From 7d02f16fff178540cb6e1d2e0bb4141ca785d0fc Mon Sep 17 00:00:00 2001 From: jwstaceyOvO <38880537+jwstaceyOvO@users.noreply.github.com> Date: Mon, 14 Feb 2022 12:30:04 +0800 Subject: [PATCH 01/23] Create status-client.service --- service/status-client.service | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 service/status-client.service diff --git a/service/status-client.service b/service/status-client.service new file mode 100644 index 0000000..65252e7 --- /dev/null +++ b/service/status-client.service @@ -0,0 +1,9 @@ +[Unit] +Description=ServerStatus-Client +After=network.target +[Service] +ExecStart=/usr/bin/python3 /root/ServerStatus/clients/client-linux.py +ExecReload=/bin/kill -HUP $MAINPID +Restart=on-failure +[Install] +WantedBy=multi-user.target From fc977367ba02e6c728015a21115eef33d6074c52 Mon Sep 17 00:00:00 2001 From: jwstaceyOvO <38880537+jwstaceyOvO@users.noreply.github.com> Date: Mon, 14 Feb 2022 12:30:17 +0800 Subject: [PATCH 02/23] Add files via upload --- service/status-server.service | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 service/status-server.service diff --git a/service/status-server.service b/service/status-server.service new file mode 100644 index 0000000..7298f58 --- /dev/null +++ b/service/status-server.service @@ -0,0 +1,10 @@ +[Unit] +Description=ServerStatus-Server +After=network.target +[Service] +EnvironmentFile=/usr/local/ServerStatus/server/config.conf +ExecStart=/root/ServerStatus/server/sergate --config=config.json --web-dir=/var/www/html +ExecReload=/bin/kill -HUP $MAINPID +Restart=on-failure +[Install] +WantedBy=multi-user.target \ No newline at end of file From 0219d21ad53fac501896b152b504e2f540dfc952 Mon Sep 17 00:00:00 2001 From: jwstaceyOvO <38880537+jwstaceyOvO@users.noreply.github.com> Date: Mon, 14 Feb 2022 12:39:10 +0800 Subject: [PATCH 03/23] Add files via upload --- status.sh | 1124 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1124 insertions(+) create mode 100644 status.sh diff --git a/status.sh b/status.sh new file mode 100644 index 0000000..045d09c --- /dev/null +++ b/status.sh @@ -0,0 +1,1124 @@ +#!/usr/bin/env bash +PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin +export PATH + +#================================================= +# System Required: CentOS/Debian/Ubuntu/ArchLinux +# Description: ServerStatus client + server +# Version: Test v0.4.1 +# Author: Toyo, Modified by APTX +#================================================= + +sh_ver="0.4.1" +filepath=$( + cd "$(dirname "$0")" || exit + pwd +) +file_1=$(echo -e "${filepath}" | awk -F "$0" '{print $1}') +file="/usr/local/ServerStatus" +web_file="/usr/local/ServerStatus/web" +server_file="/usr/local/ServerStatus/server" +server_conf="/usr/local/ServerStatus/server/config.json" +server_conf_1="/usr/local/ServerStatus/server/config.conf" +client_file="/usr/local/ServerStatus/client" + +client_log_file="/tmp/serverstatus_client.log" +server_log_file="/tmp/serverstatus_server.log" +jq_file="${file}/jq" +[[ ! -e ${jq_file} ]] && jq_file="/usr/bin/jq" + +github_prefix="https://raw.githubusercontent.com/jwstaceyOvO/ServerStatus/master" +coding_prefix="https://cokemine.coding.net/p/hotarunet/d/ServerStatus-Hotaru/git/raw/master" +link_prefix=${github_prefix} + +Green_font_prefix="\033[32m" && Red_font_prefix="\033[31m" && Red_background_prefix="\033[41;37m" && Font_color_suffix="\033[0m" +Info="${Green_font_prefix}[信息]${Font_color_suffix}" +Error="${Red_font_prefix}[错误]${Font_color_suffix}" +Tip="${Green_font_prefix}[注意]${Font_color_suffix}" + +check_installed_server_status() { + [[ ! -e "${server_file}/sergate" ]] && echo -e "${Error} ServerStatus 服务端没有安装,请检查 !" && exit 1 +} +check_installed_client_status() { + [[ ! -e "${client_file}/client-linux.py" ]] && echo -e "${Error} ServerStatus 客户端没有安装,请检查 !" && exit 1 +} +check_pid_server() { + #PID=$(ps -ef | grep "sergate" | grep -v grep | grep -v ".sh" | grep -v "init.d" | grep -v "service" | awk '{print $2}') + PID=$(pgrep -f "sergate") +} +check_pid_client() { + #PID=$(ps -ef | grep "client-linux.py" | grep -v grep | grep -v ".sh" | grep -v "init.d" | grep -v "service" | awk '{print $2}') + PID=$(pgrep -f "client-linux.py") +} + +Download_Server_Status_server() { +git clone https://github.com/cppla/ServerStatus.git +} +Download_Server_Status_client() { +git clone https://github.com/cppla/ServerStatus.git +} +Download_Server_Status_Service() { + mode=$1 + [[ -z ${mode} ]] && mode="server" + local service_note="服务端" + [[ ${mode} == "client" ]] && service_note="客户端" + if [[ ${release} == "archlinux" ]]; then + wget --no-check-certificate "${link_prefix}/service/status-${mode}.service" -O "/usr/lib/systemd/system/status-${mode}.service" || + { + echo -e "${Error} ServerStatus ${service_note}服务管理脚本下载失败 !" + exit 1 + } + systemctl enable "status-${mode}.service" + else + wget --no-check-certificate "${link_prefix}/service/server_status_${mode}_${release}" -O "/etc/init.d/status-${mode}" || + { + echo -e "${Error} ServerStatus ${service_note}服务管理脚本下载失败 !" + exit 1 + } + chmod +x "/etc/init.d/status-${mode}" + [[ ${release} == "centos" ]] && + { + chkconfig --add "status-${mode}" + chkconfig "status-${mode}" on + } + + [[ ${release} == "debian" ]] && update-rc.d -f "status-${mode}" defaults + fi + echo -e "${Info} ServerStatus ${service_note}服务管理脚本下载完成 !" +} +Service_Server_Status_server() { + Download_Server_Status_Service "server" +} +Service_Server_Status_client() { + Download_Server_Status_Service "client" +} +Write_server_config() { + cat >${server_conf} <<-EOF +{"servers": + [ + { + "username": "username01", + "password": "password", + "name": "Server 01", + "type": "KVM", + "host": "", + "location": "Hong Kong", + "disabled": false, + "region": "HK" + } + ] +} +EOF +} +Write_server_config_conf() { + cat >${server_conf_1} <<-EOF +PORT = ${server_port_s} +EOF +} +Read_config_client() { + client_text="$(sed 's/\"//g;s/,//g;s/ //g' "${client_file}/client-linux.py") " + client_server="$(echo -e "${client_text}" | grep "SERVER=" | awk -F "=" '{print $2}')" + client_port="$(echo -e "${client_text}" | grep "PORT=" | awk -F "=" '{print $2}')" + client_user="$(echo -e "${client_text}" | grep "USER=" | awk -F "=" '{print $2}')" + client_password="$(echo -e "${client_text}" | grep "PASSWORD=" | awk -F "=" '{print $2}')" + grep -q "NET_IN, NET_OUT = get_traffic_vnstat()" "${client_file}/client-linux.py" && client_vnstat="true" || client_vnstat="false" +} +Read_config_server() { + if [[ ! -e "${server_conf_1}" ]]; then + server_port_s="35601" + Write_server_config_conf + server_port="35601" + else + server_port="$(grep "PORT = " ${server_conf_1} | awk '{print $3}')" + fi +} +Set_server() { + mode=$1 + [[ -z ${mode} ]] && mode="server" + if [[ ${mode} == "server" ]]; then + echo -e "请输入 ServerStatus 服务端中网站要设置的 域名[server] +默认为本机IP为域名,例如输入: toyoo.pw ,如果要使用本机IP,请留空直接回车" + read -erp "(默认: 本机IP):" server_s + [[ -z "$server_s" ]] && server_s="" + else + echo -e "请输入 ServerStatus 服务端的 IP/域名[server],请注意,如果你的域名使用了CDN,请直接填写IP" + read -erp "(默认: 127.0.0.1):" server_s + [[ -z "$server_s" ]] && server_s="127.0.0.1" + fi + + echo && echo " ================================================" + echo -e " IP/域名[server]: ${Red_background_prefix} ${server_s} ${Font_color_suffix}" + echo " ================================================" && echo +} +Set_server_http_port() { + while true; do + echo -e "请输入 ServerStatus 服务端中网站要设置的 域名/IP的端口[1-65535](如果是域名的话,一般用 80 端口)" + read -erp "(默认: 8888):" server_http_port_s + [[ -z "$server_http_port_s" ]] && server_http_port_s="8888" + if [[ "$server_http_port_s" =~ ^[0-9]*$ ]]; then + if [[ ${server_http_port_s} -ge 1 ]] && [[ ${server_http_port_s} -le 65535 ]]; then + echo && echo " ================================================" + echo -e " 端口: ${Red_background_prefix} ${server_http_port_s} ${Font_color_suffix}" + echo " ================================================" && echo + break + else + echo "输入错误, 请输入正确的端口。" + fi + else + echo "输入错误, 请输入正确的端口。" + fi + done +} +Set_server_port() { + while true; do + echo -e "请输入 ServerStatus 服务端监听的端口[1-65535](用于服务端接收客户端消息的端口,客户端要填写这个端口)" + read -erp "(默认: 35601):" server_port_s + [[ -z "$server_port_s" ]] && server_port_s="35601" + if [[ "$server_port_s" =~ ^[0-9]*$ ]]; then + if [[ ${server_port_s} -ge 1 ]] && [[ ${server_port_s} -le 65535 ]]; then + echo && echo " ================================================" + echo -e " 端口: ${Red_background_prefix} ${server_port_s} ${Font_color_suffix}" + echo " ================================================" && echo + break + else + echo "输入错误, 请输入正确的端口。" + fi + else + echo "输入错误, 请输入正确的端口。" + fi + done +} +Set_username() { + mode=$1 + [[ -z ${mode} ]] && mode="server" + if [[ ${mode} == "server" ]]; then + echo -e "请输入 ServerStatus 服务端要设置的用户名[username](字母/数字,不可与其他账号重复)" + else + echo -e "请输入 ServerStatus 服务端中对应配置的用户名[username](字母/数字,不可与其他账号重复)" + fi + read -erp "(默认: 取消):" username_s + [[ -z "$username_s" ]] && echo "已取消..." && exit 0 + echo && echo " ================================================" + echo -e " 账号[username]: ${Red_background_prefix} ${username_s} ${Font_color_suffix}" + echo " ================================================" && echo +} +Set_password() { + mode=$1 + [[ -z ${mode} ]] && mode="server" + if [[ ${mode} == "server" ]]; then + echo -e "请输入 ServerStatus 服务端要设置的密码[password](字母/数字,可重复)" + else + echo -e "请输入 ServerStatus 服务端中对应配置的密码[password](字母/数字)" + fi + read -erp "(默认: doub.io):" password_s + [[ -z "$password_s" ]] && password_s="doub.io" + echo && echo " ================================================" + echo -e " 密码[password]: ${Red_background_prefix} ${password_s} ${Font_color_suffix}" + echo " ================================================" && echo +} +Set_vnstat() { + echo -e "对于流量计算是否使用Vnstat每月自动清零? [y/N]" + read -erp "(默认: N):" isVnstat + [[ -z "$isVnstat" ]] && isVnstat="n" +} +Set_name() { + echo -e "请输入 ServerStatus 服务端要设置的节点名称[name](支持中文,前提是你的系统和SSH工具支持中文输入,仅仅是个名字)" + read -erp "(默认: Server 01):" name_s + [[ -z "$name_s" ]] && name_s="Server 01" + echo && echo " ================================================" + echo -e " 节点名称[name]: ${Red_background_prefix} ${name_s} ${Font_color_suffix}" + echo " ================================================" && echo +} +Set_type() { + echo -e "请输入 ServerStatus 服务端要设置的节点虚拟化类型[type](例如 OpenVZ / KVM)" + read -erp "(默认: KVM):" type_s + [[ -z "$type_s" ]] && type_s="KVM" + echo && echo " ================================================" + echo -e " 虚拟化类型[type]: ${Red_background_prefix} ${type_s} ${Font_color_suffix}" + echo " ================================================" && echo +} +Set_location() { + echo -e "请输入 ServerStatus 服务端要设置的节点位置[location](支持中文,前提是你的系统和SSH工具支持中文输入)" + read -erp "(默认: Hong Kong):" location_s + [[ -z "$location_s" ]] && location_s="Hong Kong" + echo && echo " ================================================" + echo -e " 节点位置[location]: ${Red_background_prefix} ${location_s} ${Font_color_suffix}" + echo " ================================================" && echo +} +Set_region() { + echo -e "请输入 ServerStatus 服务端要设置的节点地区[region](用于国家/地区的旗帜图标显示)" + read -erp "(默认: HK):" region_s + [[ -z "$region_s" ]] && region_s="HK" + while ! check_region; do + read -erp "你输入的节点地区不合法,请重新输入:" region_s + done + echo && echo " ================================================" + echo -e " 节点地区[region]: ${Red_background_prefix} ${region_s} ${Font_color_suffix}" + echo " ================================================" && echo +} +Set_config_server() { + Set_username "server" + Set_password "server" + Set_name + Set_type + Set_location + Set_region +} +Set_config_client() { + Set_server "client" + Set_server_port + Set_username "client" + Set_password "client" + Set_vnstat +} +Set_ServerStatus_server() { + check_installed_server_status + echo && echo -e " 你要做什么? + + ${Green_font_prefix} 1.${Font_color_suffix} 添加 节点配置 + ${Green_font_prefix} 2.${Font_color_suffix} 删除 节点配置 +———————— + ${Green_font_prefix} 3.${Font_color_suffix} 修改 节点配置 - 节点用户名 + ${Green_font_prefix} 4.${Font_color_suffix} 修改 节点配置 - 节点密码 + ${Green_font_prefix} 5.${Font_color_suffix} 修改 节点配置 - 节点名称 + ${Green_font_prefix} 6.${Font_color_suffix} 修改 节点配置 - 节点虚拟化 + ${Green_font_prefix} 7.${Font_color_suffix} 修改 节点配置 - 节点位置 + ${Green_font_prefix} 8.${Font_color_suffix} 修改 节点配置 - 节点区域 + ${Green_font_prefix} 9.${Font_color_suffix} 修改 节点配置 - 全部参数 +———————— + ${Green_font_prefix} 10.${Font_color_suffix} 启用/禁用 节点配置 +———————— + ${Green_font_prefix}11.${Font_color_suffix} 修改 服务端监听端口" && echo + read -erp "(默认: 取消):" server_num + [[ -z "${server_num}" ]] && echo "已取消..." && exit 1 + if [[ ${server_num} == "1" ]]; then + Add_ServerStatus_server + elif [[ ${server_num} == "2" ]]; then + Del_ServerStatus_server + elif [[ ${server_num} == "3" ]]; then + Modify_ServerStatus_server_username + elif [[ ${server_num} == "4" ]]; then + Modify_ServerStatus_server_password + elif [[ ${server_num} == "5" ]]; then + Modify_ServerStatus_server_name + elif [[ ${server_num} == "6" ]]; then + Modify_ServerStatus_server_type + elif [[ ${server_num} == "7" ]]; then + Modify_ServerStatus_server_location + elif [[ ${server_num} == "8" ]]; then + Modify_ServerStatus_server_region + elif [[ ${server_num} == "9" ]]; then + Modify_ServerStatus_server_all + elif [[ ${server_num} == "10" ]]; then + Modify_ServerStatus_server_disabled + elif [[ ${server_num} == "11" ]]; then + Read_config_server + Set_server_port + Write_server_config_conf + else + echo -e "${Error} 请输入正确的数字[1-11]" && exit 1 + fi + Restart_ServerStatus_server +} +List_ServerStatus_server() { + conf_text=$(${jq_file} '.servers' ${server_conf} | ${jq_file} ".[]|.username" | sed 's/\"//g') + conf_text_total=$(echo -e "${conf_text}" | wc -l) + [[ ${conf_text_total} == "0" ]] && echo -e "${Error} 没有发现 一个节点配置,请检查 !" && exit 1 + conf_text_total_a=$((conf_text_total - 1)) + conf_list_all="" + for ((integer = 0; integer <= conf_text_total_a; integer++)); do + now_text=$(${jq_file} '.servers' ${server_conf} | ${jq_file} ".[${integer}]" | sed 's/\"//g;s/,$//g' | sed '$d;1d') + now_text_username=$(echo -e "${now_text}" | grep "username" | awk -F ": " '{print $2}') + now_text_password=$(echo -e "${now_text}" | grep "password" | awk -F ": " '{print $2}') + now_text_name=$(echo -e "${now_text}" | grep "name" | grep -v "username" | awk -F ": " '{print $2}') + now_text_type=$(echo -e "${now_text}" | grep "type" | awk -F ": " '{print $2}') + now_text_location=$(echo -e "${now_text}" | grep "location" | awk -F ": " '{print $2}') + now_text_region=$(echo -e "${now_text}" | grep "region" | awk -F ": " '{print $2}') + now_text_disabled=$(echo -e "${now_text}" | grep "disabled" | awk -F ": " '{print $2}') + if [[ ${now_text_disabled} == "false" ]]; then + now_text_disabled_status="${Green_font_prefix}启用${Font_color_suffix}" + else + now_text_disabled_status="${Red_font_prefix}禁用${Font_color_suffix}" + fi + conf_list_all=${conf_list_all}"用户名: ${Green_font_prefix}${now_text_username}${Font_color_suffix} 密码: ${Green_font_prefix}${now_text_password}${Font_color_suffix} 节点名: ${Green_font_prefix}${now_text_name}${Font_color_suffix} 类型: ${Green_font_prefix}${now_text_type}${Font_color_suffix} 位置: ${Green_font_prefix}${now_text_location}${Font_color_suffix} 区域: ${Green_font_prefix}${now_text_region}${Font_color_suffix} 状态: ${Green_font_prefix}${now_text_disabled_status}${Font_color_suffix}\n" + done + echo && echo -e "节点总数 ${Green_font_prefix}${conf_text_total}${Font_color_suffix}" + echo -e "${conf_list_all}" +} +Add_ServerStatus_server() { + Set_config_server + Set_username_ch=$(grep '"username": "'"${username_s}"'"' ${server_conf}) + [[ -n "${Set_username_ch}" ]] && echo -e "${Error} 用户名已被使用 !" && exit 1 + sed -i '3i\ },' ${server_conf} + sed -i '3i\ "region": "'"${region_s}"'"' ${server_conf} + sed -i '3i\ "disabled": false ,' ${server_conf} + sed -i '3i\ "location": "'"${location_s}"'",' ${server_conf} + sed -i '3i\ "host": "'"None"'",' ${server_conf} + sed -i '3i\ "type": "'"${type_s}"'",' ${server_conf} + sed -i '3i\ "name": "'"${name_s}"'",' ${server_conf} + sed -i '3i\ "password": "'"${password_s}"'",' ${server_conf} + sed -i '3i\ "username": "'"${username_s}"'",' ${server_conf} + sed -i '3i\ {' ${server_conf} + echo -e "${Info} 添加节点成功 ${Green_font_prefix}[ 节点名称: ${name_s}, 节点用户名: ${username_s}, 节点密码: ${password_s} ]${Font_color_suffix} !" +} +Del_ServerStatus_server() { + List_ServerStatus_server + [[ "${conf_text_total}" == "1" ]] && echo -e "${Error} 节点配置仅剩 1个,不能删除 !" && exit 1 + echo -e "请输入要删除的节点用户名" + read -erp "(默认: 取消):" del_server_username + [[ -z "${del_server_username}" ]] && echo -e "已取消..." && exit 1 + del_username=$(cat -n ${server_conf} | grep '"username": "'"${del_server_username}"'"' | awk '{print $1}') + if [[ -n ${del_username} ]]; then + del_username_min=$((del_username - 1)) + del_username_max=$((del_username + 8)) + del_username_max_text=$(sed -n "${del_username_max}p" ${server_conf}) + del_username_max_text_last=${del_username_max_text:((${#del_username_max_text} - 1))} + if [[ ${del_username_max_text_last} != "," ]]; then + del_list_num=$((del_username_min - 1)) + sed -i "${del_list_num}s/,$//g" ${server_conf} + fi + sed -i "${del_username_min},${del_username_max}d" ${server_conf} + echo -e "${Info} 节点删除成功 ${Green_font_prefix}[ 节点用户名: ${del_server_username} ]${Font_color_suffix} " + else + echo -e "${Error} 请输入正确的节点用户名 !" && exit 1 + fi +} +Modify_ServerStatus_server_username() { + List_ServerStatus_server + echo -e "请输入要修改的节点用户名" + read -erp "(默认: 取消):" manually_username + [[ -z "${manually_username}" ]] && echo -e "已取消..." && exit 1 + Set_username_num=$(cat -n ${server_conf} | grep '"username": "'"${manually_username}"'"' | awk '{print $1}') + if [[ -n ${Set_username_num} ]]; then + Set_username + Set_username_ch=$(grep '"username": "'"${username_s}"'"' ${server_conf}) + [[ -n "${Set_username_ch}" ]] && echo -e "${Error} 用户名已被使用 !" && exit 1 + sed -i "${Set_username_num}"'s/"username": "'"${manually_username}"'"/"username": "'"${username_s}"'"/g' ${server_conf} + echo -e "${Info} 修改成功 [ 原节点用户名: ${manually_username}, 新节点用户名: ${username_s} ]" + else + echo -e "${Error} 请输入正确的节点用户名 !" && exit 1 + fi +} +Modify_ServerStatus_server_password() { + List_ServerStatus_server + echo -e "请输入要修改的节点用户名" + read -erp "(默认: 取消):" manually_username + [[ -z "${manually_username}" ]] && echo -e "已取消..." && exit 1 + Set_username_num=$(cat -n ${server_conf} | grep '"username": "'"${manually_username}"'"' | awk '{print $1}') + if [[ -n ${Set_username_num} ]]; then + Set_password + Set_password_num_a=$((Set_username_num + 1)) + Set_password_num_text=$(sed -n "${Set_password_num_a}p" ${server_conf} | sed 's/\"//g;s/,$//g' | awk -F ": " '{print $2}') + sed -i "${Set_password_num_a}"'s/"password": "'"${Set_password_num_text}"'"/"password": "'"${password_s}"'"/g' ${server_conf} + echo -e "${Info} 修改成功 [ 原节点密码: ${Set_password_num_text}, 新节点密码: ${password_s} ]" + else + echo -e "${Error} 请输入正确的节点用户名 !" && exit 1 + fi +} +Modify_ServerStatus_server_name() { + List_ServerStatus_server + echo -e "请输入要修改的节点用户名" + read -erp "(默认: 取消):" manually_username + [[ -z "${manually_username}" ]] && echo -e "已取消..." && exit 1 + Set_username_num=$(cat -n ${server_conf} | grep '"username": "'"${manually_username}"'"' | awk '{print $1}') + if [[ -n ${Set_username_num} ]]; then + Set_name + Set_name_num_a=$((Set_username_num + 2)) + Set_name_num_a_text=$(sed -n "${Set_name_num_a}p" ${server_conf} | sed 's/\"//g;s/,$//g' | awk -F ": " '{print $2}') + sed -i "${Set_name_num_a}"'s/"name": "'"${Set_name_num_a_text}"'"/"name": "'"${name_s}"'"/g' ${server_conf} + echo -e "${Info} 修改成功 [ 原节点名称: ${Set_name_num_a_text}, 新节点名称: ${name_s} ]" + else + echo -e "${Error} 请输入正确的节点用户名 !" && exit 1 + fi +} +Modify_ServerStatus_server_type() { + List_ServerStatus_server + echo -e "请输入要修改的节点用户名" + read -erp "(默认: 取消):" manually_username + [[ -z "${manually_username}" ]] && echo -e "已取消..." && exit 1 + Set_username_num=$(cat -n ${server_conf} | grep '"username": "'"${manually_username}"'"' | awk '{print $1}') + if [[ -n ${Set_username_num} ]]; then + Set_type + Set_type_num_a=$((Set_username_num + 3)) + Set_type_num_a_text=$(sed -n "${Set_type_num_a}p" ${server_conf} | sed 's/\"//g;s/,$//g' | awk -F ": " '{print $2}') + sed -i "${Set_type_num_a}"'s/"type": "'"${Set_type_num_a_text}"'"/"type": "'"${type_s}"'"/g' ${server_conf} + echo -e "${Info} 修改成功 [ 原节点虚拟化: ${Set_type_num_a_text}, 新节点虚拟化: ${type_s} ]" + else + echo -e "${Error} 请输入正确的节点用户名 !" && exit 1 + fi +} +Modify_ServerStatus_server_location() { + List_ServerStatus_server + echo -e "请输入要修改的节点用户名" + read -erp "(默认: 取消):" manually_username + [[ -z "${manually_username}" ]] && echo -e "已取消..." && exit 1 + Set_username_num=$(cat -n ${server_conf} | grep '"username": "'"${manually_username}"'"' | awk '{print $1}') + if [[ -n ${Set_username_num} ]]; then + Set_location + Set_location_num_a=$((Set_username_num + 5)) + Set_location_num_a_text=$(sed -n "${Set_location_num_a}p" ${server_conf} | sed 's/\"//g;s/,$//g' | awk -F ": " '{print $2}') + sed -i "${Set_location_num_a}"'s/"location": "'"${Set_location_num_a_text}"'"/"location": "'"${location_s}"'"/g' ${server_conf} + echo -e "${Info} 修改成功 [ 原节点位置: ${Set_location_num_a_text}, 新节点位置: ${location_s} ]" + else + echo -e "${Error} 请输入正确的节点用户名 !" && exit 1 + fi +} +Modify_ServerStatus_server_region() { + List_ServerStatus_server + echo -e "请输入要修改的节点用户名" + read -erp "(默认: 取消):" manually_username + [[ -z "${manually_username}" ]] && echo -e "已取消..." && exit 1 + Set_username_num=$(cat -n ${server_conf} | grep '"username": "'"${manually_username}"'"' | awk '{print $1}') + if [[ -n ${Set_username_num} ]]; then + Set_region + Set_region_num_a=$((Set_username_num + 7)) + Set_region_num_a_text=$(sed -n "${Set_region_num_a}p" ${server_conf} | sed 's/\"//g;s/,$//g' | awk -F ": " '{print $2}') + sed -i "${Set_region_num_a}"'s/"region": "'"${Set_region_num_a_text}"'"/"region": "'"${region_s}"'"/g' ${server_conf} + echo -e "${Info} 修改成功 [ 原节点地区: ${Set_region_num_a_text}, 新节点地区: ${region_s} ]" + else + echo -e "${Error} 请输入正确的节点用户名 !" && exit 1 + fi +} +Modify_ServerStatus_server_all() { + List_ServerStatus_server + echo -e "请输入要修改的节点用户名" + read -erp "(默认: 取消):" manually_username + [[ -z "${manually_username}" ]] && echo -e "已取消..." && exit 1 + Set_username_num=$(cat -n ${server_conf} | grep '"username": "'"${manually_username}"'"' | awk '{print $1}') + if [[ -n ${Set_username_num} ]]; then + Set_username + Set_password + Set_name + Set_type + Set_location + Set_region + sed -i "${Set_username_num}"'s/"username": "'"${manually_username}"'"/"username": "'"${username_s}"'"/g' ${server_conf} + Set_password_num_a=$((Set_username_num + 1)) + Set_password_num_text=$(sed -n "${Set_password_num_a}p" ${server_conf} | sed 's/\"//g;s/,$//g' | awk -F ": " '{print $2}') + sed -i "${Set_password_num_a}"'s/"password": "'"${Set_password_num_text}"'"/"password": "'"${password_s}"'"/g' ${server_conf} + Set_name_num_a=$((Set_username_num + 2)) + Set_name_num_a_text=$(sed -n "${Set_name_num_a}p" ${server_conf} | sed 's/\"//g;s/,$//g' | awk -F ": " '{print $2}') + sed -i "${Set_name_num_a}"'s/"name": "'"${Set_name_num_a_text}"'"/"name": "'"${name_s}"'"/g' ${server_conf} + Set_type_num_a=$((Set_username_num + 3)) + Set_type_num_a_text=$(sed -n "${Set_type_num_a}p" ${server_conf} | sed 's/\"//g;s/,$//g' | awk -F ": " '{print $2}') + sed -i "${Set_type_num_a}"'s/"type": "'"${Set_type_num_a_text}"'"/"type": "'"${type_s}"'"/g' ${server_conf} + Set_location_num_a=$((Set_username_num + 5)) + Set_location_num_a_text=$(sed -n "${Set_location_num_a}p" ${server_conf} | sed 's/\"//g;s/,$//g' | awk -F ": " '{print $2}') + sed -i "${Set_location_num_a}"'s/"location": "'"${Set_location_num_a_text}"'"/"location": "'"${location_s}"'"/g' ${server_conf} + Set_region_num_a=$((Set_username_num + 7)) + Set_region_num_a_text=$(sed -n "${Set_region_num_a}p" ${server_conf} | sed 's/\"//g;s/,$//g' | awk -F ": " '{print $2}') + sed -i "${Set_region_num_a}"'s/"region": "'"${Set_region_num_a_text}"'"/"region": "'"${region_s}"'"/g' ${server_conf} + echo -e "${Info} 修改成功。" + else + echo -e "${Error} 请输入正确的节点用户名 !" && exit 1 + fi +} +Modify_ServerStatus_server_disabled() { + List_ServerStatus_server + echo -e "请输入要修改的节点用户名" + read -erp "(默认: 取消):" manually_username + [[ -z "${manually_username}" ]] && echo -e "已取消..." && exit 1 + Set_username_num=$(cat -n ${server_conf} | grep '"username": "'"${manually_username}"'"' | awk '{print $1}') + if [[ -n ${Set_username_num} ]]; then + Set_disabled_num_a=$((Set_username_num + 6)) + Set_disabled_num_a_text=$(sed -n "${Set_disabled_num_a}p" ${server_conf} | sed 's/\"//g;s/,$//g' | awk -F ": " '{print $2}') + if [[ ${Set_disabled_num_a_text} == "false" ]]; then + disabled_s="true" + else + disabled_s="false" + fi + sed -i "${Set_disabled_num_a}"'s/"disabled": '"${Set_disabled_num_a_text}"'/"disabled": '"${disabled_s}"'/g' ${server_conf} + echo -e "${Info} 修改成功 [ 原禁用状态: ${Set_disabled_num_a_text}, 新禁用状态: ${disabled_s} ]" + else + echo -e "${Error} 请输入正确的节点用户名 !" && exit 1 + fi +} +Set_ServerStatus_client() { + check_installed_client_status + Set_config_client + Read_config_client + Modify_config_client + Restart_ServerStatus_client +} +Install_vnStat() { + if [[ ${release} == "archlinux" ]]; then + pacman -Sy vnstat --noconfirm + systemctl enable vnstat + systemctl start vnstat + return 0 + elif [[ ${release} == "centos" ]]; then + yum -y update + yum -y install sqlite sqlite-devel + yum -y groupinstall "Development Tools" + elif [[ ${release} == "debian" ]]; then + apt -y update + apt -y install sqlite3 libsqlite3-dev build-essential + fi + cd "/tmp" || return 1 + wget --no-check-certificate https://humdi.net/vnstat/vnstat-latest.tar.gz + tar zxvf vnstat-latest.tar.gz + cd vnstat-*/ || return 1 + ./configure --prefix=/usr --sysconfdir=/etc && make && make install + if ! vnstat -v >/dev/null 2>&1; then + echo "编译安装vnStat失败,请手动安装vnStat" + exit 1 + fi + vnstatd -d + if [[ ${release} == "centos" ]]; then + if grep "6\..*" /etc/redhat-release | grep -i "centos" | grep -v "{^6}\.6" >/dev/null; then + [[ ! -e /etc/init.d/vnstat ]] && cp examples/init.d/redhat/vnstat /etc/init.d/ + chkconfig vnstat on + service vnstat restart + fi + else + if grep -i "debian" /etc/issue | grep -q "7" || grep -i "ubuntu" /etc/issue | grep -q "14"; then + [[ ! -e /etc/init.d/vnstat ]] && cp examples/init.d/debian/vnstat /etc/init.d/ + update-rc.d vnstat defaults + service vnstat restart + fi + fi + if [[ ! -e /etc/init.d/vnstat ]]; then + cp -v examples/systemd/simple/vnstat.service /etc/systemd/system/ + systemctl enable vnstat + systemctl start vnstat + fi + rm -rf vnstat* + cd ~ || exit +} +Modify_config_client_traffic() { + [ -z ${isVnstat} ] && [[ ${client_vnstat_s} == "false" ]] && return + if [[ ${isVnstat="y"} == [Yy] ]]; then + vnstat -v >/dev/null 2>&1 || Install_vnStat + netName=$(awk '{i++; if( i>2 && ($2 != 0 && $10 != 0) ){print $1}}' /proc/net/dev | sed 's/^lo:$//g' | sed 's/^tun:$//g' | sed '/^$/d' | sed 's/^[\t]*//g' | sed 's/[:]*$//g') + if [ -z "$netName" ]; then + echo -e "获取网卡名称失败,请在Github反馈" + exit 1 + fi + if [[ $netName =~ [[:space:]] ]]; then + read -erp "检测到多个网卡: ${netName},请手动输入网卡名称" netName + fi + read -erp "请输入每月流量归零的日期(1~28),默认为1(即每月1日): " time_N + [[ -z "$time_N" ]] && time_N="1" + while ! [[ $time_N =~ ^[0-9]*$ ]] || ((time_N < 1 || time_N > 28)); do + read -erp "你输入的日期不合法,请重新输入: " time_N + done + sed -i "s/$(grep -w "MonthRotate" /etc/vnstat.conf)/MonthRotate $time_N/" /etc/vnstat.conf + sed -i "s/$(grep -w "Interface" /etc/vnstat.conf)/Interface \"$netName\"/" /etc/vnstat.conf + chmod -R 777 /var/lib/vnstat/ + systemctl restart vnstat + if ! grep -q "NET_IN, NET_OUT = get_traffic_vnstat()" ${client_file}/client-linux.py; then + sed -i 's/\t/ /g' ${client_file}/client-linux.py + sed -i 's/NET_IN, NET_OUT = traffic.get_traffic()/NET_IN, NET_OUT = get_traffic_vnstat()/' ${client_file}/client-linux.py + fi + elif grep -q "NET_IN, NET_OUT = get_traffic_vnstat()" ${client_file}/client-linux.py; then + sed -i 's/\t/ /g' ${client_file}/client-linux.py + sed -i 's/NET_IN, NET_OUT = get_traffic_vnstat()/NET_IN, NET_OUT = traffic.get_traffic()/' ${client_file}/client-linux.py + fi +} +Modify_config_client() { + sed -i 's/SERVER = "'"${client_server}"'"/SERVER = "'"${server_s}"'"/g' "${client_file}/client-linux.py" + sed -i "s/PORT = ${client_port}/PORT = ${server_port_s}/g" "${client_file}/client-linux.py" + sed -i 's/USER = "'"${client_user}"'"/USER = "'"${username_s}"'"/g' "${client_file}/client-linux.py" + sed -i 's/PASSWORD = "'"${client_password}"'"/PASSWORD = "'"${password_s}"'"/g' "${client_file}/client-linux.py" + Modify_config_client_traffic +} +Install_jq() { + [[ ${mirror_num} == 2 ]] && { + github_link="https://hub.fastgit.org" + raw_link="https://raw.fastgit.org" + } || { + github_link="https://github.com" + raw_link="https://raw.githubusercontent.com" + } + if [[ ! -e ${jq_file} ]]; then + if [[ ${bit} == "x86_64" ]]; then + jq_file="${file}/jq" + wget --no-check-certificate "${github_link}/stedolan/jq/releases/download/jq-1.5/jq-linux64" -O ${jq_file} + elif [[ ${bit} == "i386" ]]; then + jq_file="${file}/jq" + wget --no-check-certificate "${github_link}/stedolan/jq/releases/download/jq-1.5/jq-linux32" -O ${jq_file} + else + # ARM fallback to package manager + [[ ${release} == "archlinux" ]] && pacman -Sy jq --noconfirm + [[ ${release} == "centos" ]] && yum -y install jq + [[ ${release} == "debian" ]] && apt -y install jq + jq_file="/usr/bin/jq" + fi + [[ ! -e ${jq_file} ]] && echo -e "${Error} JQ解析器 下载失败,请检查 !" && exit 1 + chmod +x ${jq_file} + echo -e "${Info} JQ解析器 安装完成,继续..." + else + echo -e "${Info} JQ解析器 已安装,继续..." + fi + if [[ ! -e ${region_json} ]]; then + wget --no-check-certificate "${raw_link}/michaelwittig/node-i18n-iso-countries/master/langs/zh.json" -O ${region_json} + [[ ! -e ${region_json} ]] && echo -e "${Error} ISO 3166-1 json文件下载失败,请检查!" && exit 1 + fi +} +Install_caddy() { + echo + echo -e "${Info} 是否由脚本自动配置HTTP服务(服务端的在线监控网站),如果选择 N,则请在其他HTTP服务中配置网站根目录为:${Green_font_prefix}${web_file}${Font_color_suffix} [Y/n]" + read -erp "(默认: Y 自动部署):" caddy_yn + [[ -z "$caddy_yn" ]] && caddy_yn="y" + if [[ "${caddy_yn}" == [Yy] ]]; then + caddy_file="/etc/caddy/Caddyfile" # Where is the default Caddyfile specified in Archlinux? + [[ ! -e /usr/bin/caddy ]] && { + if [[ ${release} == "debian" ]]; then + apt install -y debian-keyring debian-archive-keyring apt-transport-https curl + curl -1sLf "https://dl.cloudsmith.io/public/caddy/stable/gpg.key" | tee /etc/apt/trusted.gpg.d/caddy-stable.asc + curl -1sLf "https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt" | tee /etc/apt/sources.list.d/caddy-stable.list + apt update && apt install caddy + elif [[ ${release} == "centos" ]]; then + yum install yum-plugin-copr -y + yum copr enable @caddy/caddy -y + yum install caddy -y + elif [[ ${release} == "archlinux" ]]; then + pacman -Sy caddy --noconfirm + fi + [[ ! -e "/usr/bin/caddy" ]] && echo -e "${Error} Caddy安装失败,请手动部署,Web网页文件位置:${web_file}" && exit 1 + systemctl enable caddy + echo "" >${caddy_file} + } + Set_server "server" + Set_server_http_port + cat >>${caddy_file} <<-EOF +http://${server_s}:${server_http_port_s} { + root * ${web_file} + encode gzip + file_server +} +EOF + systemctl restart caddy + else + echo -e "${Info} 跳过 HTTP服务部署,请手动部署,Web网页文件位置:${web_file} ,如果位置改变,请注意修改服务脚本文件 /etc/init.d/status-server 中的 WEB_BIN 变量 !" + fi +} +Install_ServerStatus_server() { + Set_Mirror + [[ -e "${server_file}/sergate" ]] && echo -e "${Error} 检测到 ServerStatus 服务端已安装 !" && exit 1 + Set_server_port + echo -e "${Info} 开始安装/配置 依赖..." + Installation_dependency "server" + Install_caddy + echo -e "${Info} 开始下载/安装..." + Download_Server_Status_server + Install_jq + echo -e "${Info} 开始下载/安装 服务脚本(init)..." + Service_Server_Status_server + echo -e "${Info} 开始写入 配置文件..." + Write_server_config + Write_server_config_conf + echo -e "${Info} 所有步骤 安装完毕,开始启动..." + Start_ServerStatus_server +} +Install_ServerStatus_client() { + Set_Mirror + [[ -e "${client_file}/client-linux.py" ]] && echo -e "${Error} 检测到 ServerStatus 客户端已安装 !" && exit 1 + check_sys + echo -e "${Info} 开始设置 用户配置..." + Set_config_client + echo -e "${Info} 开始安装/配置 依赖..." + Installation_dependency "client" + echo -e "${Info} 开始下载/安装..." + Download_Server_Status_client + echo -e "${Info} 开始下载/安装 服务脚本(init)..." + Service_Server_Status_client + echo -e "${Info} 开始写入 配置..." + Read_config_client + Modify_config_client + echo -e "${Info} 所有步骤 安装完毕,开始启动..." + Start_ServerStatus_client +} +Update_ServerStatus_server() { + Set_Mirror + check_installed_server_status + check_pid_server + if [[ -n ${PID} ]]; then + if [[ ${release} == "archlinux" ]]; then + systemctl stop status-server + else + /etc/init.d/status-server stop + fi + fi + Download_Server_Status_server + rm -rf /etc/init.d/status-server + Service_Server_Status_server + Start_ServerStatus_server +} +Update_ServerStatus_client() { + Set_Mirror + check_installed_client_status + check_pid_client + if [[ -n ${PID} ]]; then + if [[ ${release} == "archlinux" ]]; then + systemctl stop status-client + else + /etc/init.d/status-client stop + fi + fi + if [[ ! -e "${client_file}/client-linux.py" ]]; then + if [[ ! -e "${file}/client-linux.py" ]]; then + echo -e "${Error} ServerStatus 客户端文件不存在 !" && exit 1 + else + client_text="$(sed 's/\"//g;s/,//g;s/ //g' "${file}/client-linux.py")" + rm -rf "${file}/client-linux.py" + fi + else + client_text="$(sed 's/\"//g;s/,//g;s/ //g' "${client_file}/client-linux.py")" + fi + server_s="$(echo -e "${client_text}" | grep "SERVER=" | awk -F "=" '{print $2}')" + server_port_s="$(echo -e "${client_text}" | grep "PORT=" | awk -F "=" '{print $2}')" + username_s="$(echo -e "${client_text}" | grep "USER=" | awk -F "=" '{print $2}')" + password_s="$(echo -e "${client_text}" | grep "PASSWORD=" | awk -F "=" '{print $2}')" + grep -q "NET_IN, NET_OUT = get_traffic_vnstat()" "${client_file}/client-linux.py" && client_vnstat_s="true" || client_vnstat_s="false" + Download_Server_Status_client + Read_config_client + Modify_config_client + rm -rf /etc/init.d/status-client + Service_Server_Status_client + Start_ServerStatus_client +} +Start_ServerStatus_server() { + check_installed_server_status + check_pid_server + [[ -n ${PID} ]] && echo -e "${Error} ServerStatus 正在运行,请检查 !" && exit 1 + if [[ ${release} == "archlinux" ]]; then + systemctl start status-server.service + else + /etc/init.d/status-server start + fi +} +Stop_ServerStatus_server() { + check_installed_server_status + check_pid_server + [[ -z ${PID} ]] && echo -e "${Error} ServerStatus 没有运行,请检查 !" && exit 1 + if [[ ${release} == "archlinux" ]]; then + systemctl stop status-server.service + else + /etc/init.d/status-server stop + fi +} +Restart_ServerStatus_server() { + check_installed_server_status + check_pid_server + if [[ -n ${PID} ]]; then + if [[ ${release} == "archlinux" ]]; then + systemctl stop status-server.service + else + /etc/init.d/status-server stop + fi + fi + if [[ ${release} == "archlinux" ]]; then + systemctl start status-server.service + else + /etc/init.d/status-server start + fi +} +Uninstall_ServerStatus_server() { + check_installed_server_status + echo "确定要卸载 ServerStatus 服务端(如果同时安装了客户端,则只会删除服务端) ? [y/N]" + echo + read -erp "(默认: n):" unyn + [[ -z ${unyn} ]] && unyn="n" + if [[ ${unyn} == [Yy] ]]; then + check_pid_server + [[ -n $PID ]] && kill -9 "${PID}" + Read_config_server + if [[ -e "${client_file}/client-linux.py" ]]; then + rm -rf "${server_file}" + rm -rf "${web_file}" + else + rm -rf "${file}" + fi + rm -rf "/etc/init.d/status-server" + if [[ -e "/usr/bin/caddy" ]]; then + systemctl stop caddy + systemctl disable caddy + [[ ${release} == "debian" ]] && apt purge -y caddy + [[ ${release} == "centos" ]] && yum -y remove caddy + [[ ${release} == "archlinux" ]] && pacman -R caddy --noconfirm + fi + if [[ ${release} == "centos" ]]; then + chkconfig --del status-server + elif [[ ${release} == "debian" ]]; then + update-rc.d -f status-server remove + elif [[ ${release} == "archlinux" ]]; then + systemctl stop status-server + systemctl disable status-server + rm /usr/lib/systemd/system/status-server.service + fi + echo && echo "ServerStatus 卸载完成 !" && echo + else + echo && echo "卸载已取消..." && echo + fi +} +Start_ServerStatus_client() { + check_installed_client_status + check_pid_client + [[ -n ${PID} ]] && echo -e "${Error} ServerStatus 正在运行,请检查 !" && exit 1 + if [[ ${release} == "archlinux" ]]; then + systemctl start status-client.service + else + /etc/init.d/status-client start + fi +} +Stop_ServerStatus_client() { + check_installed_client_status + check_pid_client + [[ -z ${PID} ]] && echo -e "${Error} ServerStatus 没有运行,请检查 !" && exit 1 + if [[ ${release} == "archlinux" ]]; then + systemctl stop status-client.service + else + /etc/init.d/status-client stop + fi +} +Restart_ServerStatus_client() { + check_installed_client_status + check_pid_client + if [[ -n ${PID} ]]; then + if [[ ${release} == "archlinux" ]]; then + systemctl restart status-client.service + else + /etc/init.d/status-client restart + fi + fi +} +Uninstall_ServerStatus_client() { + check_installed_client_status + echo "确定要卸载 ServerStatus 客户端(如果同时安装了服务端,则只会删除客户端) ? [y/N]" + echo + read -erp "(默认: n):" unyn + [[ -z ${unyn} ]] && unyn="n" + if [[ ${unyn} == [Yy] ]]; then + check_pid_client + [[ -n $PID ]] && kill -9 "${PID}" + Read_config_client + if [[ -e "${server_file}/sergate" ]]; then + rm -rf "${client_file}" + else + rm -rf "${file}" + fi + rm -rf /etc/init.d/status-client + if [[ ${release} == "centos" ]]; then + chkconfig --del status-client + elif [[ ${release} == "debian" ]]; then + update-rc.d -f status-client remove + elif [[ ${release} == "archlinux" ]]; then + systemctl stop status-client + systemctl disable status-client + rm /usr/lib/systemd/system/status-client.service + fi + echo && echo "ServerStatus 卸载完成 !" && echo + else + echo && echo "卸载已取消..." && echo + fi +} +View_ServerStatus_client() { + check_installed_client_status + Read_config_client + clear && echo "————————————————————" && echo + echo -e " ServerStatus 客户端配置信息: + + IP \t: ${Green_font_prefix}${client_server}${Font_color_suffix} + 端口 \t: ${Green_font_prefix}${client_port}${Font_color_suffix} + 账号 \t: ${Green_font_prefix}${client_user}${Font_color_suffix} + 密码 \t: ${Green_font_prefix}${client_password}${Font_color_suffix} + vnStat : ${Green_font_prefix}${client_vnstat}${Font_color_suffix} + +————————————————————" +} +View_client_Log() { + [[ ! -e ${client_log_file} ]] && echo -e "${Error} 没有找到日志文件 !" && exit 1 + echo && echo -e "${Tip} 按 ${Red_font_prefix}Ctrl+C${Font_color_suffix} 终止查看日志" && echo -e "如果需要查看完整日志内容,请用 ${Red_font_prefix}cat ${client_log_file}${Font_color_suffix} 命令。" && echo + tail -f ${client_log_file} +} +View_server_Log() { + [[ ! -e ${server_log_file} ]] && echo -e "${Error} 没有找到日志文件 !" && exit 1 + echo && echo -e "${Tip} 按 ${Red_font_prefix}Ctrl+C${Font_color_suffix} 终止查看日志" && echo -e "如果需要查看完整日志内容,请用 ${Red_font_prefix}cat ${server_log_file}${Font_color_suffix} 命令。" && echo + tail -f ${server_log_file} +} +Update_Shell() { + Set_Mirror + sh_new_ver=$(wget --no-check-certificate -qO- -t1 -T3 "${link_prefix}/status.sh" | grep 'sh_ver="' | awk -F "=" '{print $NF}' | sed 's/\"//g' | head -1) + [[ -z ${sh_new_ver} ]] && echo -e "${Error} 无法链接到 Github !" && exit 0 + if [[ -e "/etc/init.d/status-client" ]] || [[ -e "/usr/lib/systemd/system/status-client.service" ]]; then + rm -rf /etc/init.d/status-client + rm -rf /usr/lib/systemd/system/status-client.service + Service_Server_Status_client + fi + if [[ -e "/etc/init.d/status-server" ]] || [[ -e "/usr/lib/systemd/system/status-server.service" ]]; then + rm -rf /etc/init.d/status-server + rm -rf /usr/lib/systemd/system/status-server.service + Service_Server_Status_server + fi + wget -N --no-check-certificate "${link_prefix}/status.sh" && chmod +x status.sh + echo -e "脚本已更新为最新版本[ ${sh_new_ver} ] !(注意:因为更新方式为直接覆盖当前运行的脚本,所以可能下面会提示一些报错,无视即可)" && exit 0 +} +menu_client() { + echo && echo -e " ServerStatus 一键安装管理脚本 ${Red_font_prefix}[v${sh_ver}]${Font_color_suffix} + -- Toyo | doub.io/shell-jc3 -- + -- Modified by APTX -- + ${Green_font_prefix} 0.${Font_color_suffix} 升级脚本 + ———————————— + ${Green_font_prefix} 1.${Font_color_suffix} 安装 客户端 + ${Green_font_prefix} 2.${Font_color_suffix} 更新 客户端 + ${Green_font_prefix} 3.${Font_color_suffix} 卸载 客户端 +———————————— + ${Green_font_prefix} 4.${Font_color_suffix} 启动 客户端 + ${Green_font_prefix} 5.${Font_color_suffix} 停止 客户端 + ${Green_font_prefix} 6.${Font_color_suffix} 重启 客户端 +———————————— + ${Green_font_prefix} 7.${Font_color_suffix} 设置 客户端配置 + ${Green_font_prefix} 8.${Font_color_suffix} 查看 客户端信息 + ${Green_font_prefix} 9.${Font_color_suffix} 查看 客户端日志 +———————————— + ${Green_font_prefix}10.${Font_color_suffix} 切换为 服务端菜单" && echo + if [[ -e "${client_file}/client-linux.py" ]]; then + check_pid_client + if [[ -n "${PID}" ]]; then + echo -e " 当前状态: 客户端 ${Green_font_prefix}已安装${Font_color_suffix} 并 ${Green_font_prefix}已启动${Font_color_suffix}" + else + echo -e " 当前状态: 客户端 ${Green_font_prefix}已安装${Font_color_suffix} 但 ${Red_font_prefix}未启动${Font_color_suffix}" + fi + else + if [[ -e "${file}/client-linux.py" ]]; then + check_pid_client + if [[ -n "${PID}" ]]; then + echo -e " 当前状态: 客户端 ${Green_font_prefix}已安装${Font_color_suffix} 并 ${Green_font_prefix}已启动${Font_color_suffix}" + else + echo -e " 当前状态: 客户端 ${Green_font_prefix}已安装${Font_color_suffix} 但 ${Red_font_prefix}未启动${Font_color_suffix}" + fi + else + echo -e " 当前状态: 客户端 ${Red_font_prefix}未安装${Font_color_suffix}" + fi + fi + echo + read -erp " 请输入数字 [0-10]:" num + case "$num" in + 0) + Update_Shell + ;; + 1) + Install_ServerStatus_client + ;; + 2) + Update_ServerStatus_client + ;; + 3) + Uninstall_ServerStatus_client + ;; + 4) + Start_ServerStatus_client + ;; + 5) + Stop_ServerStatus_client + ;; + 6) + Restart_ServerStatus_client + ;; + 7) + Set_ServerStatus_client + ;; + 8) + View_ServerStatus_client + ;; + 9) + View_client_Log + ;; + 10) + menu_server + ;; + *) + echo "请输入正确数字 [0-10]" + ;; + esac +} +menu_server() { + echo && echo -e " ServerStatus 一键安装管理脚本 ${Red_font_prefix}[v${sh_ver}]${Font_color_suffix} + -- Toyo | doub.io/shell-jc3 -- + -- Modified by APTX -- + ${Green_font_prefix} 0.${Font_color_suffix} 升级脚本 + ———————————— + ${Green_font_prefix} 1.${Font_color_suffix} 安装 服务端 + ${Green_font_prefix} 2.${Font_color_suffix} 更新 服务端 + ${Green_font_prefix} 3.${Font_color_suffix} 卸载 服务端 +———————————— + ${Green_font_prefix} 4.${Font_color_suffix} 启动 服务端 + ${Green_font_prefix} 5.${Font_color_suffix} 停止 服务端 + ${Green_font_prefix} 6.${Font_color_suffix} 重启 服务端 +———————————— + ${Green_font_prefix} 7.${Font_color_suffix} 设置 服务端配置 + ${Green_font_prefix} 8.${Font_color_suffix} 查看 服务端信息 + ${Green_font_prefix} 9.${Font_color_suffix} 查看 服务端日志 +———————————— + ${Green_font_prefix}10.${Font_color_suffix} 切换为 客户端菜单" && echo + if [[ -e "${server_file}/sergate" ]]; then + check_pid_server + if [[ -n "${PID}" ]]; then + echo -e " 当前状态: 服务端 ${Green_font_prefix}已安装${Font_color_suffix} 并 ${Green_font_prefix}已启动${Font_color_suffix}" + else + echo -e " 当前状态: 服务端 ${Green_font_prefix}已安装${Font_color_suffix} 但 ${Red_font_prefix}未启动${Font_color_suffix}" + fi + else + echo -e " 当前状态: 服务端 ${Red_font_prefix}未安装${Font_color_suffix}" + fi + echo + read -erp " 请输入数字 [0-10]:" num + case "$num" in + 0) + Update_Shell + ;; + 1) + Install_ServerStatus_server + ;; + 2) + Update_ServerStatus_server + ;; + 3) + Uninstall_ServerStatus_server + ;; + 4) + Start_ServerStatus_server + ;; + 5) + Stop_ServerStatus_server + ;; + 6) + Restart_ServerStatus_server + ;; + 7) + Set_ServerStatus_server + ;; + 8) + List_ServerStatus_server + ;; + 9) + View_server_Log + ;; + 10) + menu_client + ;; + *) + echo "请输入正确数字 [0-10]" + ;; + esac +} +Set_Mirror() { + echo -e "${Info} 请输入要选择的下载源,默认使用GitHub,中国大陆建议选择Coding.net,但是不建议将服务端部署在中国大陆主机上 + ${Green_font_prefix} 1.${Font_color_suffix} GitHub + ${Green_font_prefix} 2.${Font_color_suffix} Coding.net (部分资源通过 FastGit 提供服务下载, Thanks to FastGit.org for the service)" + read -erp "请输入数字 [1-2], 默认为 1:" mirror_num + [[ -z "${mirror_num}" ]] && mirror_num=1 + [[ ${mirror_num} == 2 ]] && link_prefix=${coding_prefix} || link_prefix=${github_prefix} +} +check_sys +action=$1 +if [[ -n $action ]]; then + if [[ $action == "s" ]]; then + menu_server + elif [[ $action == "c" ]]; then + menu_client + fi +else + menu_client +fi \ No newline at end of file From 050a6f78dccc60867abd5f69bfebb784fc1a0ce5 Mon Sep 17 00:00:00 2001 From: jwstaceyOvO <38880537+jwstaceyOvO@users.noreply.github.com> Date: Mon, 14 Feb 2022 13:23:25 +0800 Subject: [PATCH 04/23] Update status-server.service --- service/status-server.service | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/service/status-server.service b/service/status-server.service index 7298f58..0a31890 100644 --- a/service/status-server.service +++ b/service/status-server.service @@ -3,8 +3,8 @@ Description=ServerStatus-Server After=network.target [Service] EnvironmentFile=/usr/local/ServerStatus/server/config.conf -ExecStart=/root/ServerStatus/server/sergate --config=config.json --web-dir=/var/www/html +ExecStart=/root/ServerStatus/server/sergate --config=config.json --web-dir=/usr/local/ServerStatus/web ExecReload=/bin/kill -HUP $MAINPID Restart=on-failure [Install] -WantedBy=multi-user.target \ No newline at end of file +WantedBy=multi-user.target From a3dab0dc0fbb3761b6bae5610267d1bec483c91f Mon Sep 17 00:00:00 2001 From: jwstaceyOvO <38880537+jwstaceyOvO@users.noreply.github.com> Date: Mon, 14 Feb 2022 15:30:08 +0800 Subject: [PATCH 05/23] Update status-client.service --- service/status-client.service | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/status-client.service b/service/status-client.service index 65252e7..bdddad9 100644 --- a/service/status-client.service +++ b/service/status-client.service @@ -2,7 +2,7 @@ Description=ServerStatus-Client After=network.target [Service] -ExecStart=/usr/bin/python3 /root/ServerStatus/clients/client-linux.py +ExecStart=/usr/bin/python3 /usr/local/ServerStatus/client/status-client.py ExecReload=/bin/kill -HUP $MAINPID Restart=on-failure [Install] From d0f3507adde012a132835d4ce02bf19be924079a Mon Sep 17 00:00:00 2001 From: jwstaceyOvO <38880537+jwstaceyOvO@users.noreply.github.com> Date: Mon, 14 Feb 2022 15:31:31 +0800 Subject: [PATCH 06/23] Update status-client.service --- service/status-client.service | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/status-client.service b/service/status-client.service index bdddad9..49e1748 100644 --- a/service/status-client.service +++ b/service/status-client.service @@ -2,7 +2,7 @@ Description=ServerStatus-Client After=network.target [Service] -ExecStart=/usr/bin/python3 /usr/local/ServerStatus/client/status-client.py +ExecStart=/usr/bin/python3 /usr/local/ServerStatus/clients/status-client.py ExecReload=/bin/kill -HUP $MAINPID Restart=on-failure [Install] From d1bdec5e308e582425a2dca5f80f5d25cb9f6f9e Mon Sep 17 00:00:00 2001 From: jwstaceyOvO <38880537+jwstaceyOvO@users.noreply.github.com> Date: Mon, 14 Feb 2022 15:33:39 +0800 Subject: [PATCH 07/23] Update status-client.service --- service/status-client.service | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/status-client.service b/service/status-client.service index 49e1748..bdddad9 100644 --- a/service/status-client.service +++ b/service/status-client.service @@ -2,7 +2,7 @@ Description=ServerStatus-Client After=network.target [Service] -ExecStart=/usr/bin/python3 /usr/local/ServerStatus/clients/status-client.py +ExecStart=/usr/bin/python3 /usr/local/ServerStatus/client/status-client.py ExecReload=/bin/kill -HUP $MAINPID Restart=on-failure [Install] From e4fdacb2b58115eca1e519fb9644c92a77e87b65 Mon Sep 17 00:00:00 2001 From: jwstaceyOvO <38880537+jwstaceyOvO@users.noreply.github.com> Date: Mon, 14 Feb 2022 15:34:54 +0800 Subject: [PATCH 08/23] Update status-client.service --- service/status-client.service | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/status-client.service b/service/status-client.service index bdddad9..49e1748 100644 --- a/service/status-client.service +++ b/service/status-client.service @@ -2,7 +2,7 @@ Description=ServerStatus-Client After=network.target [Service] -ExecStart=/usr/bin/python3 /usr/local/ServerStatus/client/status-client.py +ExecStart=/usr/bin/python3 /usr/local/ServerStatus/clients/status-client.py ExecReload=/bin/kill -HUP $MAINPID Restart=on-failure [Install] From 4a0b15b61d807d22b0e8c48b56bb92700f296b27 Mon Sep 17 00:00:00 2001 From: jwstaceyOvO <38880537+jwstaceyOvO@users.noreply.github.com> Date: Mon, 14 Feb 2022 15:37:58 +0800 Subject: [PATCH 09/23] Update status-client.service --- service/status-client.service | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/status-client.service b/service/status-client.service index 49e1748..350a96e 100644 --- a/service/status-client.service +++ b/service/status-client.service @@ -2,7 +2,7 @@ Description=ServerStatus-Client After=network.target [Service] -ExecStart=/usr/bin/python3 /usr/local/ServerStatus/clients/status-client.py +ExecStart=/usr/bin/python3 /usr/local/ServerStatus/clients/client-linux.py ExecReload=/bin/kill -HUP $MAINPID Restart=on-failure [Install] From 3871c2c3d9113b7c31de932e5a93a00ae9179519 Mon Sep 17 00:00:00 2001 From: jwstaceyOvO <38880537+jwstaceyOvO@users.noreply.github.com> Date: Mon, 14 Feb 2022 16:29:32 +0800 Subject: [PATCH 10/23] Update status.sh --- status.sh | 230 +++++++++++------------------------------------------- 1 file changed, 44 insertions(+), 186 deletions(-) diff --git a/status.sh b/status.sh index 045d09c..448b76b 100644 --- a/status.sh +++ b/status.sh @@ -20,7 +20,7 @@ web_file="/usr/local/ServerStatus/web" server_file="/usr/local/ServerStatus/server" server_conf="/usr/local/ServerStatus/server/config.json" server_conf_1="/usr/local/ServerStatus/server/config.conf" -client_file="/usr/local/ServerStatus/client" +client_file="/usr/local/ServerStatus/clients" client_log_file="/tmp/serverstatus_client.log" server_log_file="/tmp/serverstatus_server.log" @@ -52,38 +52,21 @@ check_pid_client() { } Download_Server_Status_server() { -git clone https://github.com/cppla/ServerStatus.git +git clone https://github.com/cppla/ServerStatus.git "${file}" } Download_Server_Status_client() { -git clone https://github.com/cppla/ServerStatus.git +git clone https://github.com/cppla/ServerStatus.git "${file}" } Download_Server_Status_Service() { mode=$1 [[ -z ${mode} ]] && mode="server" local service_note="服务端" [[ ${mode} == "client" ]] && service_note="客户端" - if [[ ${release} == "archlinux" ]]; then wget --no-check-certificate "${link_prefix}/service/status-${mode}.service" -O "/usr/lib/systemd/system/status-${mode}.service" || { echo -e "${Error} ServerStatus ${service_note}服务管理脚本下载失败 !" exit 1 } - systemctl enable "status-${mode}.service" - else - wget --no-check-certificate "${link_prefix}/service/server_status_${mode}_${release}" -O "/etc/init.d/status-${mode}" || - { - echo -e "${Error} ServerStatus ${service_note}服务管理脚本下载失败 !" - exit 1 - } - chmod +x "/etc/init.d/status-${mode}" - [[ ${release} == "centos" ]] && - { - chkconfig --add "status-${mode}" - chkconfig "status-${mode}" on - } - - [[ ${release} == "debian" ]] && update-rc.d -f "status-${mode}" defaults - fi echo -e "${Info} ServerStatus ${service_note}服务管理脚本下载完成 !" } Service_Server_Status_server() { @@ -117,11 +100,10 @@ EOF } Read_config_client() { client_text="$(sed 's/\"//g;s/,//g;s/ //g' "${client_file}/client-linux.py") " - client_server="$(echo -e "${client_text}" | grep "SERVER=" | awk -F "=" '{print $2}')" - client_port="$(echo -e "${client_text}" | grep "PORT=" | awk -F "=" '{print $2}')" - client_user="$(echo -e "${client_text}" | grep "USER=" | awk -F "=" '{print $2}')" - client_password="$(echo -e "${client_text}" | grep "PASSWORD=" | awk -F "=" '{print $2}')" - grep -q "NET_IN, NET_OUT = get_traffic_vnstat()" "${client_file}/client-linux.py" && client_vnstat="true" || client_vnstat="false" + client_server="$(echo -e "${client_text}" | grep "SERVER =" | awk -F "=" '{print $2}')" + client_port="$(echo -e "${client_text}" | grep "PORT =" | awk -F "=" '{print $2}')" + client_user="$(echo -e "${client_text}" | grep "USER =" | awk -F "=" '{print $2}')" + client_password="$(echo -e "${client_text}" | grep "PASSWORD =" | awk -F "=" '{print $2}')" } Read_config_server() { if [[ ! -e "${server_conf_1}" ]]; then @@ -216,11 +198,6 @@ Set_password() { echo -e " 密码[password]: ${Red_background_prefix} ${password_s} ${Font_color_suffix}" echo " ================================================" && echo } -Set_vnstat() { - echo -e "对于流量计算是否使用Vnstat每月自动清零? [y/N]" - read -erp "(默认: N):" isVnstat - [[ -z "$isVnstat" ]] && isVnstat="n" -} Set_name() { echo -e "请输入 ServerStatus 服务端要设置的节点名称[name](支持中文,前提是你的系统和SSH工具支持中文输入,仅仅是个名字)" read -erp "(默认: Server 01):" name_s @@ -269,7 +246,6 @@ Set_config_client() { Set_server_port Set_username "client" Set_password "client" - Set_vnstat } Set_ServerStatus_server() { check_installed_server_status @@ -283,12 +259,11 @@ Set_ServerStatus_server() { ${Green_font_prefix} 5.${Font_color_suffix} 修改 节点配置 - 节点名称 ${Green_font_prefix} 6.${Font_color_suffix} 修改 节点配置 - 节点虚拟化 ${Green_font_prefix} 7.${Font_color_suffix} 修改 节点配置 - 节点位置 - ${Green_font_prefix} 8.${Font_color_suffix} 修改 节点配置 - 节点区域 - ${Green_font_prefix} 9.${Font_color_suffix} 修改 节点配置 - 全部参数 + ${Green_font_prefix} 8.${Font_color_suffix} 修改 节点配置 - 全部参数 ———————— - ${Green_font_prefix} 10.${Font_color_suffix} 启用/禁用 节点配置 + ${Green_font_prefix} 9.${Font_color_suffix} 启用/禁用 节点配置 ———————— - ${Green_font_prefix}11.${Font_color_suffix} 修改 服务端监听端口" && echo + ${Green_font_prefix}10.${Font_color_suffix} 修改 服务端监听端口" && echo read -erp "(默认: 取消):" server_num [[ -z "${server_num}" ]] && echo "已取消..." && exit 1 if [[ ${server_num} == "1" ]]; then @@ -306,20 +281,19 @@ Set_ServerStatus_server() { elif [[ ${server_num} == "7" ]]; then Modify_ServerStatus_server_location elif [[ ${server_num} == "8" ]]; then - Modify_ServerStatus_server_region - elif [[ ${server_num} == "9" ]]; then Modify_ServerStatus_server_all - elif [[ ${server_num} == "10" ]]; then + elif [[ ${server_num} == "9" ]]; then Modify_ServerStatus_server_disabled - elif [[ ${server_num} == "11" ]]; then + elif [[ ${server_num} == "10" ]]; then Read_config_server Set_server_port Write_server_config_conf else - echo -e "${Error} 请输入正确的数字[1-11]" && exit 1 + echo -e "${Error} 请输入正确的数字[1-10]" && exit 1 fi Restart_ServerStatus_server } + List_ServerStatus_server() { conf_text=$(${jq_file} '.servers' ${server_conf} | ${jq_file} ".[]|.username" | sed 's/\"//g') conf_text_total=$(echo -e "${conf_text}" | wc -l) @@ -345,6 +319,7 @@ List_ServerStatus_server() { echo && echo -e "节点总数 ${Green_font_prefix}${conf_text_total}${Font_color_suffix}" echo -e "${conf_list_all}" } + Add_ServerStatus_server() { Set_config_server Set_username_ch=$(grep '"username": "'"${username_s}"'"' ${server_conf}) @@ -383,6 +358,7 @@ Del_ServerStatus_server() { echo -e "${Error} 请输入正确的节点用户名 !" && exit 1 fi } + Modify_ServerStatus_server_username() { List_ServerStatus_server echo -e "请输入要修改的节点用户名" @@ -399,6 +375,7 @@ Modify_ServerStatus_server_username() { echo -e "${Error} 请输入正确的节点用户名 !" && exit 1 fi } + Modify_ServerStatus_server_password() { List_ServerStatus_server echo -e "请输入要修改的节点用户名" @@ -415,6 +392,7 @@ Modify_ServerStatus_server_password() { echo -e "${Error} 请输入正确的节点用户名 !" && exit 1 fi } + Modify_ServerStatus_server_name() { List_ServerStatus_server echo -e "请输入要修改的节点用户名" @@ -431,6 +409,7 @@ Modify_ServerStatus_server_name() { echo -e "${Error} 请输入正确的节点用户名 !" && exit 1 fi } + Modify_ServerStatus_server_type() { List_ServerStatus_server echo -e "请输入要修改的节点用户名" @@ -463,22 +442,7 @@ Modify_ServerStatus_server_location() { echo -e "${Error} 请输入正确的节点用户名 !" && exit 1 fi } -Modify_ServerStatus_server_region() { - List_ServerStatus_server - echo -e "请输入要修改的节点用户名" - read -erp "(默认: 取消):" manually_username - [[ -z "${manually_username}" ]] && echo -e "已取消..." && exit 1 - Set_username_num=$(cat -n ${server_conf} | grep '"username": "'"${manually_username}"'"' | awk '{print $1}') - if [[ -n ${Set_username_num} ]]; then - Set_region - Set_region_num_a=$((Set_username_num + 7)) - Set_region_num_a_text=$(sed -n "${Set_region_num_a}p" ${server_conf} | sed 's/\"//g;s/,$//g' | awk -F ": " '{print $2}') - sed -i "${Set_region_num_a}"'s/"region": "'"${Set_region_num_a_text}"'"/"region": "'"${region_s}"'"/g' ${server_conf} - echo -e "${Info} 修改成功 [ 原节点地区: ${Set_region_num_a_text}, 新节点地区: ${region_s} ]" - else - echo -e "${Error} 请输入正确的节点用户名 !" && exit 1 - fi -} + Modify_ServerStatus_server_all() { List_ServerStatus_server echo -e "请输入要修改的节点用户名" @@ -513,6 +477,7 @@ Modify_ServerStatus_server_all() { echo -e "${Error} 请输入正确的节点用户名 !" && exit 1 fi } + Modify_ServerStatus_server_disabled() { List_ServerStatus_server echo -e "请输入要修改的节点用户名" @@ -533,6 +498,7 @@ Modify_ServerStatus_server_disabled() { echo -e "${Error} 请输入正确的节点用户名 !" && exit 1 fi } + Set_ServerStatus_client() { check_installed_client_status Set_config_client @@ -540,121 +506,14 @@ Set_ServerStatus_client() { Modify_config_client Restart_ServerStatus_client } -Install_vnStat() { - if [[ ${release} == "archlinux" ]]; then - pacman -Sy vnstat --noconfirm - systemctl enable vnstat - systemctl start vnstat - return 0 - elif [[ ${release} == "centos" ]]; then - yum -y update - yum -y install sqlite sqlite-devel - yum -y groupinstall "Development Tools" - elif [[ ${release} == "debian" ]]; then - apt -y update - apt -y install sqlite3 libsqlite3-dev build-essential - fi - cd "/tmp" || return 1 - wget --no-check-certificate https://humdi.net/vnstat/vnstat-latest.tar.gz - tar zxvf vnstat-latest.tar.gz - cd vnstat-*/ || return 1 - ./configure --prefix=/usr --sysconfdir=/etc && make && make install - if ! vnstat -v >/dev/null 2>&1; then - echo "编译安装vnStat失败,请手动安装vnStat" - exit 1 - fi - vnstatd -d - if [[ ${release} == "centos" ]]; then - if grep "6\..*" /etc/redhat-release | grep -i "centos" | grep -v "{^6}\.6" >/dev/null; then - [[ ! -e /etc/init.d/vnstat ]] && cp examples/init.d/redhat/vnstat /etc/init.d/ - chkconfig vnstat on - service vnstat restart - fi - else - if grep -i "debian" /etc/issue | grep -q "7" || grep -i "ubuntu" /etc/issue | grep -q "14"; then - [[ ! -e /etc/init.d/vnstat ]] && cp examples/init.d/debian/vnstat /etc/init.d/ - update-rc.d vnstat defaults - service vnstat restart - fi - fi - if [[ ! -e /etc/init.d/vnstat ]]; then - cp -v examples/systemd/simple/vnstat.service /etc/systemd/system/ - systemctl enable vnstat - systemctl start vnstat - fi - rm -rf vnstat* - cd ~ || exit -} -Modify_config_client_traffic() { - [ -z ${isVnstat} ] && [[ ${client_vnstat_s} == "false" ]] && return - if [[ ${isVnstat="y"} == [Yy] ]]; then - vnstat -v >/dev/null 2>&1 || Install_vnStat - netName=$(awk '{i++; if( i>2 && ($2 != 0 && $10 != 0) ){print $1}}' /proc/net/dev | sed 's/^lo:$//g' | sed 's/^tun:$//g' | sed '/^$/d' | sed 's/^[\t]*//g' | sed 's/[:]*$//g') - if [ -z "$netName" ]; then - echo -e "获取网卡名称失败,请在Github反馈" - exit 1 - fi - if [[ $netName =~ [[:space:]] ]]; then - read -erp "检测到多个网卡: ${netName},请手动输入网卡名称" netName - fi - read -erp "请输入每月流量归零的日期(1~28),默认为1(即每月1日): " time_N - [[ -z "$time_N" ]] && time_N="1" - while ! [[ $time_N =~ ^[0-9]*$ ]] || ((time_N < 1 || time_N > 28)); do - read -erp "你输入的日期不合法,请重新输入: " time_N - done - sed -i "s/$(grep -w "MonthRotate" /etc/vnstat.conf)/MonthRotate $time_N/" /etc/vnstat.conf - sed -i "s/$(grep -w "Interface" /etc/vnstat.conf)/Interface \"$netName\"/" /etc/vnstat.conf - chmod -R 777 /var/lib/vnstat/ - systemctl restart vnstat - if ! grep -q "NET_IN, NET_OUT = get_traffic_vnstat()" ${client_file}/client-linux.py; then - sed -i 's/\t/ /g' ${client_file}/client-linux.py - sed -i 's/NET_IN, NET_OUT = traffic.get_traffic()/NET_IN, NET_OUT = get_traffic_vnstat()/' ${client_file}/client-linux.py - fi - elif grep -q "NET_IN, NET_OUT = get_traffic_vnstat()" ${client_file}/client-linux.py; then - sed -i 's/\t/ /g' ${client_file}/client-linux.py - sed -i 's/NET_IN, NET_OUT = get_traffic_vnstat()/NET_IN, NET_OUT = traffic.get_traffic()/' ${client_file}/client-linux.py - fi -} + Modify_config_client() { sed -i 's/SERVER = "'"${client_server}"'"/SERVER = "'"${server_s}"'"/g' "${client_file}/client-linux.py" sed -i "s/PORT = ${client_port}/PORT = ${server_port_s}/g" "${client_file}/client-linux.py" sed -i 's/USER = "'"${client_user}"'"/USER = "'"${username_s}"'"/g' "${client_file}/client-linux.py" sed -i 's/PASSWORD = "'"${client_password}"'"/PASSWORD = "'"${password_s}"'"/g' "${client_file}/client-linux.py" - Modify_config_client_traffic -} -Install_jq() { - [[ ${mirror_num} == 2 ]] && { - github_link="https://hub.fastgit.org" - raw_link="https://raw.fastgit.org" - } || { - github_link="https://github.com" - raw_link="https://raw.githubusercontent.com" - } - if [[ ! -e ${jq_file} ]]; then - if [[ ${bit} == "x86_64" ]]; then - jq_file="${file}/jq" - wget --no-check-certificate "${github_link}/stedolan/jq/releases/download/jq-1.5/jq-linux64" -O ${jq_file} - elif [[ ${bit} == "i386" ]]; then - jq_file="${file}/jq" - wget --no-check-certificate "${github_link}/stedolan/jq/releases/download/jq-1.5/jq-linux32" -O ${jq_file} - else - # ARM fallback to package manager - [[ ${release} == "archlinux" ]] && pacman -Sy jq --noconfirm - [[ ${release} == "centos" ]] && yum -y install jq - [[ ${release} == "debian" ]] && apt -y install jq - jq_file="/usr/bin/jq" - fi - [[ ! -e ${jq_file} ]] && echo -e "${Error} JQ解析器 下载失败,请检查 !" && exit 1 - chmod +x ${jq_file} - echo -e "${Info} JQ解析器 安装完成,继续..." - else - echo -e "${Info} JQ解析器 已安装,继续..." - fi - if [[ ! -e ${region_json} ]]; then - wget --no-check-certificate "${raw_link}/michaelwittig/node-i18n-iso-countries/master/langs/zh.json" -O ${region_json} - [[ ! -e ${region_json} ]] && echo -e "${Error} ISO 3166-1 json文件下载失败,请检查!" && exit 1 - fi } + Install_caddy() { echo echo -e "${Info} 是否由脚本自动配置HTTP服务(服务端的在线监控网站),如果选择 N,则请在其他HTTP服务中配置网站根目录为:${Green_font_prefix}${web_file}${Font_color_suffix} [Y/n]" @@ -693,6 +552,7 @@ EOF echo -e "${Info} 跳过 HTTP服务部署,请手动部署,Web网页文件位置:${web_file} ,如果位置改变,请注意修改服务脚本文件 /etc/init.d/status-server 中的 WEB_BIN 变量 !" fi } + Install_ServerStatus_server() { Set_Mirror [[ -e "${server_file}/sergate" ]] && echo -e "${Error} 检测到 ServerStatus 服务端已安装 !" && exit 1 @@ -711,14 +571,12 @@ Install_ServerStatus_server() { echo -e "${Info} 所有步骤 安装完毕,开始启动..." Start_ServerStatus_server } + Install_ServerStatus_client() { Set_Mirror [[ -e "${client_file}/client-linux.py" ]] && echo -e "${Error} 检测到 ServerStatus 客户端已安装 !" && exit 1 - check_sys echo -e "${Info} 开始设置 用户配置..." Set_config_client - echo -e "${Info} 开始安装/配置 依赖..." - Installation_dependency "client" echo -e "${Info} 开始下载/安装..." Download_Server_Status_client echo -e "${Info} 开始下载/安装 服务脚本(init)..." @@ -729,6 +587,7 @@ Install_ServerStatus_client() { echo -e "${Info} 所有步骤 安装完毕,开始启动..." Start_ServerStatus_client } + Update_ServerStatus_server() { Set_Mirror check_installed_server_status @@ -745,6 +604,7 @@ Update_ServerStatus_server() { Service_Server_Status_server Start_ServerStatus_server } + Update_ServerStatus_client() { Set_Mirror check_installed_client_status @@ -778,6 +638,7 @@ Update_ServerStatus_client() { Service_Server_Status_client Start_ServerStatus_client } + Start_ServerStatus_server() { check_installed_server_status check_pid_server @@ -788,6 +649,7 @@ Start_ServerStatus_server() { /etc/init.d/status-server start fi } + Stop_ServerStatus_server() { check_installed_server_status check_pid_server @@ -798,6 +660,7 @@ Stop_ServerStatus_server() { /etc/init.d/status-server stop fi } + Restart_ServerStatus_server() { check_installed_server_status check_pid_server @@ -814,6 +677,7 @@ Restart_ServerStatus_server() { /etc/init.d/status-server start fi } + Uninstall_ServerStatus_server() { check_installed_server_status echo "确定要卸载 ServerStatus 服务端(如果同时安装了客户端,则只会删除服务端) ? [y/N]" @@ -852,37 +716,31 @@ Uninstall_ServerStatus_server() { echo && echo "卸载已取消..." && echo fi } + Start_ServerStatus_client() { check_installed_client_status check_pid_client [[ -n ${PID} ]] && echo -e "${Error} ServerStatus 正在运行,请检查 !" && exit 1 - if [[ ${release} == "archlinux" ]]; then - systemctl start status-client.service - else - /etc/init.d/status-client start - fi + systemctl enable status-client + service status-client start + } + Stop_ServerStatus_client() { check_installed_client_status check_pid_client [[ -z ${PID} ]] && echo -e "${Error} ServerStatus 没有运行,请检查 !" && exit 1 - if [[ ${release} == "archlinux" ]]; then - systemctl stop status-client.service - else - /etc/init.d/status-client stop - fi + service status-client stop } + Restart_ServerStatus_client() { check_installed_client_status check_pid_client if [[ -n ${PID} ]]; then - if [[ ${release} == "archlinux" ]]; then - systemctl restart status-client.service - else - /etc/init.d/status-client restart - fi + service status-client restart fi } + Uninstall_ServerStatus_client() { check_installed_client_status echo "确定要卸载 ServerStatus 客户端(如果同时安装了服务端,则只会删除客户端) ? [y/N]" @@ -913,6 +771,7 @@ Uninstall_ServerStatus_client() { echo && echo "卸载已取消..." && echo fi } + View_ServerStatus_client() { check_installed_client_status Read_config_client @@ -923,7 +782,6 @@ View_ServerStatus_client() { 端口 \t: ${Green_font_prefix}${client_port}${Font_color_suffix} 账号 \t: ${Green_font_prefix}${client_user}${Font_color_suffix} 密码 \t: ${Green_font_prefix}${client_password}${Font_color_suffix} - vnStat : ${Green_font_prefix}${client_vnstat}${Font_color_suffix} ————————————————————" } @@ -1103,6 +961,7 @@ menu_server() { ;; esac } + Set_Mirror() { echo -e "${Info} 请输入要选择的下载源,默认使用GitHub,中国大陆建议选择Coding.net,但是不建议将服务端部署在中国大陆主机上 ${Green_font_prefix} 1.${Font_color_suffix} GitHub @@ -1111,7 +970,6 @@ Set_Mirror() { [[ -z "${mirror_num}" ]] && mirror_num=1 [[ ${mirror_num} == 2 ]] && link_prefix=${coding_prefix} || link_prefix=${github_prefix} } -check_sys action=$1 if [[ -n $action ]]; then if [[ $action == "s" ]]; then @@ -1121,4 +979,4 @@ if [[ -n $action ]]; then fi else menu_client -fi \ No newline at end of file +fi From f36b4e66d214bab84d4affbbb6465af516b4a1e3 Mon Sep 17 00:00:00 2001 From: jwstaceyOvO <38880537+jwstaceyOvO@users.noreply.github.com> Date: Mon, 14 Feb 2022 16:32:02 +0800 Subject: [PATCH 11/23] Delete status.sh --- status.sh | 982 ------------------------------------------------------ 1 file changed, 982 deletions(-) delete mode 100644 status.sh diff --git a/status.sh b/status.sh deleted file mode 100644 index 448b76b..0000000 --- a/status.sh +++ /dev/null @@ -1,982 +0,0 @@ -#!/usr/bin/env bash -PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin -export PATH - -#================================================= -# System Required: CentOS/Debian/Ubuntu/ArchLinux -# Description: ServerStatus client + server -# Version: Test v0.4.1 -# Author: Toyo, Modified by APTX -#================================================= - -sh_ver="0.4.1" -filepath=$( - cd "$(dirname "$0")" || exit - pwd -) -file_1=$(echo -e "${filepath}" | awk -F "$0" '{print $1}') -file="/usr/local/ServerStatus" -web_file="/usr/local/ServerStatus/web" -server_file="/usr/local/ServerStatus/server" -server_conf="/usr/local/ServerStatus/server/config.json" -server_conf_1="/usr/local/ServerStatus/server/config.conf" -client_file="/usr/local/ServerStatus/clients" - -client_log_file="/tmp/serverstatus_client.log" -server_log_file="/tmp/serverstatus_server.log" -jq_file="${file}/jq" -[[ ! -e ${jq_file} ]] && jq_file="/usr/bin/jq" - -github_prefix="https://raw.githubusercontent.com/jwstaceyOvO/ServerStatus/master" -coding_prefix="https://cokemine.coding.net/p/hotarunet/d/ServerStatus-Hotaru/git/raw/master" -link_prefix=${github_prefix} - -Green_font_prefix="\033[32m" && Red_font_prefix="\033[31m" && Red_background_prefix="\033[41;37m" && Font_color_suffix="\033[0m" -Info="${Green_font_prefix}[信息]${Font_color_suffix}" -Error="${Red_font_prefix}[错误]${Font_color_suffix}" -Tip="${Green_font_prefix}[注意]${Font_color_suffix}" - -check_installed_server_status() { - [[ ! -e "${server_file}/sergate" ]] && echo -e "${Error} ServerStatus 服务端没有安装,请检查 !" && exit 1 -} -check_installed_client_status() { - [[ ! -e "${client_file}/client-linux.py" ]] && echo -e "${Error} ServerStatus 客户端没有安装,请检查 !" && exit 1 -} -check_pid_server() { - #PID=$(ps -ef | grep "sergate" | grep -v grep | grep -v ".sh" | grep -v "init.d" | grep -v "service" | awk '{print $2}') - PID=$(pgrep -f "sergate") -} -check_pid_client() { - #PID=$(ps -ef | grep "client-linux.py" | grep -v grep | grep -v ".sh" | grep -v "init.d" | grep -v "service" | awk '{print $2}') - PID=$(pgrep -f "client-linux.py") -} - -Download_Server_Status_server() { -git clone https://github.com/cppla/ServerStatus.git "${file}" -} -Download_Server_Status_client() { -git clone https://github.com/cppla/ServerStatus.git "${file}" -} -Download_Server_Status_Service() { - mode=$1 - [[ -z ${mode} ]] && mode="server" - local service_note="服务端" - [[ ${mode} == "client" ]] && service_note="客户端" - wget --no-check-certificate "${link_prefix}/service/status-${mode}.service" -O "/usr/lib/systemd/system/status-${mode}.service" || - { - echo -e "${Error} ServerStatus ${service_note}服务管理脚本下载失败 !" - exit 1 - } - echo -e "${Info} ServerStatus ${service_note}服务管理脚本下载完成 !" -} -Service_Server_Status_server() { - Download_Server_Status_Service "server" -} -Service_Server_Status_client() { - Download_Server_Status_Service "client" -} -Write_server_config() { - cat >${server_conf} <<-EOF -{"servers": - [ - { - "username": "username01", - "password": "password", - "name": "Server 01", - "type": "KVM", - "host": "", - "location": "Hong Kong", - "disabled": false, - "region": "HK" - } - ] -} -EOF -} -Write_server_config_conf() { - cat >${server_conf_1} <<-EOF -PORT = ${server_port_s} -EOF -} -Read_config_client() { - client_text="$(sed 's/\"//g;s/,//g;s/ //g' "${client_file}/client-linux.py") " - client_server="$(echo -e "${client_text}" | grep "SERVER =" | awk -F "=" '{print $2}')" - client_port="$(echo -e "${client_text}" | grep "PORT =" | awk -F "=" '{print $2}')" - client_user="$(echo -e "${client_text}" | grep "USER =" | awk -F "=" '{print $2}')" - client_password="$(echo -e "${client_text}" | grep "PASSWORD =" | awk -F "=" '{print $2}')" -} -Read_config_server() { - if [[ ! -e "${server_conf_1}" ]]; then - server_port_s="35601" - Write_server_config_conf - server_port="35601" - else - server_port="$(grep "PORT = " ${server_conf_1} | awk '{print $3}')" - fi -} -Set_server() { - mode=$1 - [[ -z ${mode} ]] && mode="server" - if [[ ${mode} == "server" ]]; then - echo -e "请输入 ServerStatus 服务端中网站要设置的 域名[server] -默认为本机IP为域名,例如输入: toyoo.pw ,如果要使用本机IP,请留空直接回车" - read -erp "(默认: 本机IP):" server_s - [[ -z "$server_s" ]] && server_s="" - else - echo -e "请输入 ServerStatus 服务端的 IP/域名[server],请注意,如果你的域名使用了CDN,请直接填写IP" - read -erp "(默认: 127.0.0.1):" server_s - [[ -z "$server_s" ]] && server_s="127.0.0.1" - fi - - echo && echo " ================================================" - echo -e " IP/域名[server]: ${Red_background_prefix} ${server_s} ${Font_color_suffix}" - echo " ================================================" && echo -} -Set_server_http_port() { - while true; do - echo -e "请输入 ServerStatus 服务端中网站要设置的 域名/IP的端口[1-65535](如果是域名的话,一般用 80 端口)" - read -erp "(默认: 8888):" server_http_port_s - [[ -z "$server_http_port_s" ]] && server_http_port_s="8888" - if [[ "$server_http_port_s" =~ ^[0-9]*$ ]]; then - if [[ ${server_http_port_s} -ge 1 ]] && [[ ${server_http_port_s} -le 65535 ]]; then - echo && echo " ================================================" - echo -e " 端口: ${Red_background_prefix} ${server_http_port_s} ${Font_color_suffix}" - echo " ================================================" && echo - break - else - echo "输入错误, 请输入正确的端口。" - fi - else - echo "输入错误, 请输入正确的端口。" - fi - done -} -Set_server_port() { - while true; do - echo -e "请输入 ServerStatus 服务端监听的端口[1-65535](用于服务端接收客户端消息的端口,客户端要填写这个端口)" - read -erp "(默认: 35601):" server_port_s - [[ -z "$server_port_s" ]] && server_port_s="35601" - if [[ "$server_port_s" =~ ^[0-9]*$ ]]; then - if [[ ${server_port_s} -ge 1 ]] && [[ ${server_port_s} -le 65535 ]]; then - echo && echo " ================================================" - echo -e " 端口: ${Red_background_prefix} ${server_port_s} ${Font_color_suffix}" - echo " ================================================" && echo - break - else - echo "输入错误, 请输入正确的端口。" - fi - else - echo "输入错误, 请输入正确的端口。" - fi - done -} -Set_username() { - mode=$1 - [[ -z ${mode} ]] && mode="server" - if [[ ${mode} == "server" ]]; then - echo -e "请输入 ServerStatus 服务端要设置的用户名[username](字母/数字,不可与其他账号重复)" - else - echo -e "请输入 ServerStatus 服务端中对应配置的用户名[username](字母/数字,不可与其他账号重复)" - fi - read -erp "(默认: 取消):" username_s - [[ -z "$username_s" ]] && echo "已取消..." && exit 0 - echo && echo " ================================================" - echo -e " 账号[username]: ${Red_background_prefix} ${username_s} ${Font_color_suffix}" - echo " ================================================" && echo -} -Set_password() { - mode=$1 - [[ -z ${mode} ]] && mode="server" - if [[ ${mode} == "server" ]]; then - echo -e "请输入 ServerStatus 服务端要设置的密码[password](字母/数字,可重复)" - else - echo -e "请输入 ServerStatus 服务端中对应配置的密码[password](字母/数字)" - fi - read -erp "(默认: doub.io):" password_s - [[ -z "$password_s" ]] && password_s="doub.io" - echo && echo " ================================================" - echo -e " 密码[password]: ${Red_background_prefix} ${password_s} ${Font_color_suffix}" - echo " ================================================" && echo -} -Set_name() { - echo -e "请输入 ServerStatus 服务端要设置的节点名称[name](支持中文,前提是你的系统和SSH工具支持中文输入,仅仅是个名字)" - read -erp "(默认: Server 01):" name_s - [[ -z "$name_s" ]] && name_s="Server 01" - echo && echo " ================================================" - echo -e " 节点名称[name]: ${Red_background_prefix} ${name_s} ${Font_color_suffix}" - echo " ================================================" && echo -} -Set_type() { - echo -e "请输入 ServerStatus 服务端要设置的节点虚拟化类型[type](例如 OpenVZ / KVM)" - read -erp "(默认: KVM):" type_s - [[ -z "$type_s" ]] && type_s="KVM" - echo && echo " ================================================" - echo -e " 虚拟化类型[type]: ${Red_background_prefix} ${type_s} ${Font_color_suffix}" - echo " ================================================" && echo -} -Set_location() { - echo -e "请输入 ServerStatus 服务端要设置的节点位置[location](支持中文,前提是你的系统和SSH工具支持中文输入)" - read -erp "(默认: Hong Kong):" location_s - [[ -z "$location_s" ]] && location_s="Hong Kong" - echo && echo " ================================================" - echo -e " 节点位置[location]: ${Red_background_prefix} ${location_s} ${Font_color_suffix}" - echo " ================================================" && echo -} -Set_region() { - echo -e "请输入 ServerStatus 服务端要设置的节点地区[region](用于国家/地区的旗帜图标显示)" - read -erp "(默认: HK):" region_s - [[ -z "$region_s" ]] && region_s="HK" - while ! check_region; do - read -erp "你输入的节点地区不合法,请重新输入:" region_s - done - echo && echo " ================================================" - echo -e " 节点地区[region]: ${Red_background_prefix} ${region_s} ${Font_color_suffix}" - echo " ================================================" && echo -} -Set_config_server() { - Set_username "server" - Set_password "server" - Set_name - Set_type - Set_location - Set_region -} -Set_config_client() { - Set_server "client" - Set_server_port - Set_username "client" - Set_password "client" -} -Set_ServerStatus_server() { - check_installed_server_status - echo && echo -e " 你要做什么? - - ${Green_font_prefix} 1.${Font_color_suffix} 添加 节点配置 - ${Green_font_prefix} 2.${Font_color_suffix} 删除 节点配置 -———————— - ${Green_font_prefix} 3.${Font_color_suffix} 修改 节点配置 - 节点用户名 - ${Green_font_prefix} 4.${Font_color_suffix} 修改 节点配置 - 节点密码 - ${Green_font_prefix} 5.${Font_color_suffix} 修改 节点配置 - 节点名称 - ${Green_font_prefix} 6.${Font_color_suffix} 修改 节点配置 - 节点虚拟化 - ${Green_font_prefix} 7.${Font_color_suffix} 修改 节点配置 - 节点位置 - ${Green_font_prefix} 8.${Font_color_suffix} 修改 节点配置 - 全部参数 -———————— - ${Green_font_prefix} 9.${Font_color_suffix} 启用/禁用 节点配置 -———————— - ${Green_font_prefix}10.${Font_color_suffix} 修改 服务端监听端口" && echo - read -erp "(默认: 取消):" server_num - [[ -z "${server_num}" ]] && echo "已取消..." && exit 1 - if [[ ${server_num} == "1" ]]; then - Add_ServerStatus_server - elif [[ ${server_num} == "2" ]]; then - Del_ServerStatus_server - elif [[ ${server_num} == "3" ]]; then - Modify_ServerStatus_server_username - elif [[ ${server_num} == "4" ]]; then - Modify_ServerStatus_server_password - elif [[ ${server_num} == "5" ]]; then - Modify_ServerStatus_server_name - elif [[ ${server_num} == "6" ]]; then - Modify_ServerStatus_server_type - elif [[ ${server_num} == "7" ]]; then - Modify_ServerStatus_server_location - elif [[ ${server_num} == "8" ]]; then - Modify_ServerStatus_server_all - elif [[ ${server_num} == "9" ]]; then - Modify_ServerStatus_server_disabled - elif [[ ${server_num} == "10" ]]; then - Read_config_server - Set_server_port - Write_server_config_conf - else - echo -e "${Error} 请输入正确的数字[1-10]" && exit 1 - fi - Restart_ServerStatus_server -} - -List_ServerStatus_server() { - conf_text=$(${jq_file} '.servers' ${server_conf} | ${jq_file} ".[]|.username" | sed 's/\"//g') - conf_text_total=$(echo -e "${conf_text}" | wc -l) - [[ ${conf_text_total} == "0" ]] && echo -e "${Error} 没有发现 一个节点配置,请检查 !" && exit 1 - conf_text_total_a=$((conf_text_total - 1)) - conf_list_all="" - for ((integer = 0; integer <= conf_text_total_a; integer++)); do - now_text=$(${jq_file} '.servers' ${server_conf} | ${jq_file} ".[${integer}]" | sed 's/\"//g;s/,$//g' | sed '$d;1d') - now_text_username=$(echo -e "${now_text}" | grep "username" | awk -F ": " '{print $2}') - now_text_password=$(echo -e "${now_text}" | grep "password" | awk -F ": " '{print $2}') - now_text_name=$(echo -e "${now_text}" | grep "name" | grep -v "username" | awk -F ": " '{print $2}') - now_text_type=$(echo -e "${now_text}" | grep "type" | awk -F ": " '{print $2}') - now_text_location=$(echo -e "${now_text}" | grep "location" | awk -F ": " '{print $2}') - now_text_region=$(echo -e "${now_text}" | grep "region" | awk -F ": " '{print $2}') - now_text_disabled=$(echo -e "${now_text}" | grep "disabled" | awk -F ": " '{print $2}') - if [[ ${now_text_disabled} == "false" ]]; then - now_text_disabled_status="${Green_font_prefix}启用${Font_color_suffix}" - else - now_text_disabled_status="${Red_font_prefix}禁用${Font_color_suffix}" - fi - conf_list_all=${conf_list_all}"用户名: ${Green_font_prefix}${now_text_username}${Font_color_suffix} 密码: ${Green_font_prefix}${now_text_password}${Font_color_suffix} 节点名: ${Green_font_prefix}${now_text_name}${Font_color_suffix} 类型: ${Green_font_prefix}${now_text_type}${Font_color_suffix} 位置: ${Green_font_prefix}${now_text_location}${Font_color_suffix} 区域: ${Green_font_prefix}${now_text_region}${Font_color_suffix} 状态: ${Green_font_prefix}${now_text_disabled_status}${Font_color_suffix}\n" - done - echo && echo -e "节点总数 ${Green_font_prefix}${conf_text_total}${Font_color_suffix}" - echo -e "${conf_list_all}" -} - -Add_ServerStatus_server() { - Set_config_server - Set_username_ch=$(grep '"username": "'"${username_s}"'"' ${server_conf}) - [[ -n "${Set_username_ch}" ]] && echo -e "${Error} 用户名已被使用 !" && exit 1 - sed -i '3i\ },' ${server_conf} - sed -i '3i\ "region": "'"${region_s}"'"' ${server_conf} - sed -i '3i\ "disabled": false ,' ${server_conf} - sed -i '3i\ "location": "'"${location_s}"'",' ${server_conf} - sed -i '3i\ "host": "'"None"'",' ${server_conf} - sed -i '3i\ "type": "'"${type_s}"'",' ${server_conf} - sed -i '3i\ "name": "'"${name_s}"'",' ${server_conf} - sed -i '3i\ "password": "'"${password_s}"'",' ${server_conf} - sed -i '3i\ "username": "'"${username_s}"'",' ${server_conf} - sed -i '3i\ {' ${server_conf} - echo -e "${Info} 添加节点成功 ${Green_font_prefix}[ 节点名称: ${name_s}, 节点用户名: ${username_s}, 节点密码: ${password_s} ]${Font_color_suffix} !" -} -Del_ServerStatus_server() { - List_ServerStatus_server - [[ "${conf_text_total}" == "1" ]] && echo -e "${Error} 节点配置仅剩 1个,不能删除 !" && exit 1 - echo -e "请输入要删除的节点用户名" - read -erp "(默认: 取消):" del_server_username - [[ -z "${del_server_username}" ]] && echo -e "已取消..." && exit 1 - del_username=$(cat -n ${server_conf} | grep '"username": "'"${del_server_username}"'"' | awk '{print $1}') - if [[ -n ${del_username} ]]; then - del_username_min=$((del_username - 1)) - del_username_max=$((del_username + 8)) - del_username_max_text=$(sed -n "${del_username_max}p" ${server_conf}) - del_username_max_text_last=${del_username_max_text:((${#del_username_max_text} - 1))} - if [[ ${del_username_max_text_last} != "," ]]; then - del_list_num=$((del_username_min - 1)) - sed -i "${del_list_num}s/,$//g" ${server_conf} - fi - sed -i "${del_username_min},${del_username_max}d" ${server_conf} - echo -e "${Info} 节点删除成功 ${Green_font_prefix}[ 节点用户名: ${del_server_username} ]${Font_color_suffix} " - else - echo -e "${Error} 请输入正确的节点用户名 !" && exit 1 - fi -} - -Modify_ServerStatus_server_username() { - List_ServerStatus_server - echo -e "请输入要修改的节点用户名" - read -erp "(默认: 取消):" manually_username - [[ -z "${manually_username}" ]] && echo -e "已取消..." && exit 1 - Set_username_num=$(cat -n ${server_conf} | grep '"username": "'"${manually_username}"'"' | awk '{print $1}') - if [[ -n ${Set_username_num} ]]; then - Set_username - Set_username_ch=$(grep '"username": "'"${username_s}"'"' ${server_conf}) - [[ -n "${Set_username_ch}" ]] && echo -e "${Error} 用户名已被使用 !" && exit 1 - sed -i "${Set_username_num}"'s/"username": "'"${manually_username}"'"/"username": "'"${username_s}"'"/g' ${server_conf} - echo -e "${Info} 修改成功 [ 原节点用户名: ${manually_username}, 新节点用户名: ${username_s} ]" - else - echo -e "${Error} 请输入正确的节点用户名 !" && exit 1 - fi -} - -Modify_ServerStatus_server_password() { - List_ServerStatus_server - echo -e "请输入要修改的节点用户名" - read -erp "(默认: 取消):" manually_username - [[ -z "${manually_username}" ]] && echo -e "已取消..." && exit 1 - Set_username_num=$(cat -n ${server_conf} | grep '"username": "'"${manually_username}"'"' | awk '{print $1}') - if [[ -n ${Set_username_num} ]]; then - Set_password - Set_password_num_a=$((Set_username_num + 1)) - Set_password_num_text=$(sed -n "${Set_password_num_a}p" ${server_conf} | sed 's/\"//g;s/,$//g' | awk -F ": " '{print $2}') - sed -i "${Set_password_num_a}"'s/"password": "'"${Set_password_num_text}"'"/"password": "'"${password_s}"'"/g' ${server_conf} - echo -e "${Info} 修改成功 [ 原节点密码: ${Set_password_num_text}, 新节点密码: ${password_s} ]" - else - echo -e "${Error} 请输入正确的节点用户名 !" && exit 1 - fi -} - -Modify_ServerStatus_server_name() { - List_ServerStatus_server - echo -e "请输入要修改的节点用户名" - read -erp "(默认: 取消):" manually_username - [[ -z "${manually_username}" ]] && echo -e "已取消..." && exit 1 - Set_username_num=$(cat -n ${server_conf} | grep '"username": "'"${manually_username}"'"' | awk '{print $1}') - if [[ -n ${Set_username_num} ]]; then - Set_name - Set_name_num_a=$((Set_username_num + 2)) - Set_name_num_a_text=$(sed -n "${Set_name_num_a}p" ${server_conf} | sed 's/\"//g;s/,$//g' | awk -F ": " '{print $2}') - sed -i "${Set_name_num_a}"'s/"name": "'"${Set_name_num_a_text}"'"/"name": "'"${name_s}"'"/g' ${server_conf} - echo -e "${Info} 修改成功 [ 原节点名称: ${Set_name_num_a_text}, 新节点名称: ${name_s} ]" - else - echo -e "${Error} 请输入正确的节点用户名 !" && exit 1 - fi -} - -Modify_ServerStatus_server_type() { - List_ServerStatus_server - echo -e "请输入要修改的节点用户名" - read -erp "(默认: 取消):" manually_username - [[ -z "${manually_username}" ]] && echo -e "已取消..." && exit 1 - Set_username_num=$(cat -n ${server_conf} | grep '"username": "'"${manually_username}"'"' | awk '{print $1}') - if [[ -n ${Set_username_num} ]]; then - Set_type - Set_type_num_a=$((Set_username_num + 3)) - Set_type_num_a_text=$(sed -n "${Set_type_num_a}p" ${server_conf} | sed 's/\"//g;s/,$//g' | awk -F ": " '{print $2}') - sed -i "${Set_type_num_a}"'s/"type": "'"${Set_type_num_a_text}"'"/"type": "'"${type_s}"'"/g' ${server_conf} - echo -e "${Info} 修改成功 [ 原节点虚拟化: ${Set_type_num_a_text}, 新节点虚拟化: ${type_s} ]" - else - echo -e "${Error} 请输入正确的节点用户名 !" && exit 1 - fi -} -Modify_ServerStatus_server_location() { - List_ServerStatus_server - echo -e "请输入要修改的节点用户名" - read -erp "(默认: 取消):" manually_username - [[ -z "${manually_username}" ]] && echo -e "已取消..." && exit 1 - Set_username_num=$(cat -n ${server_conf} | grep '"username": "'"${manually_username}"'"' | awk '{print $1}') - if [[ -n ${Set_username_num} ]]; then - Set_location - Set_location_num_a=$((Set_username_num + 5)) - Set_location_num_a_text=$(sed -n "${Set_location_num_a}p" ${server_conf} | sed 's/\"//g;s/,$//g' | awk -F ": " '{print $2}') - sed -i "${Set_location_num_a}"'s/"location": "'"${Set_location_num_a_text}"'"/"location": "'"${location_s}"'"/g' ${server_conf} - echo -e "${Info} 修改成功 [ 原节点位置: ${Set_location_num_a_text}, 新节点位置: ${location_s} ]" - else - echo -e "${Error} 请输入正确的节点用户名 !" && exit 1 - fi -} - -Modify_ServerStatus_server_all() { - List_ServerStatus_server - echo -e "请输入要修改的节点用户名" - read -erp "(默认: 取消):" manually_username - [[ -z "${manually_username}" ]] && echo -e "已取消..." && exit 1 - Set_username_num=$(cat -n ${server_conf} | grep '"username": "'"${manually_username}"'"' | awk '{print $1}') - if [[ -n ${Set_username_num} ]]; then - Set_username - Set_password - Set_name - Set_type - Set_location - Set_region - sed -i "${Set_username_num}"'s/"username": "'"${manually_username}"'"/"username": "'"${username_s}"'"/g' ${server_conf} - Set_password_num_a=$((Set_username_num + 1)) - Set_password_num_text=$(sed -n "${Set_password_num_a}p" ${server_conf} | sed 's/\"//g;s/,$//g' | awk -F ": " '{print $2}') - sed -i "${Set_password_num_a}"'s/"password": "'"${Set_password_num_text}"'"/"password": "'"${password_s}"'"/g' ${server_conf} - Set_name_num_a=$((Set_username_num + 2)) - Set_name_num_a_text=$(sed -n "${Set_name_num_a}p" ${server_conf} | sed 's/\"//g;s/,$//g' | awk -F ": " '{print $2}') - sed -i "${Set_name_num_a}"'s/"name": "'"${Set_name_num_a_text}"'"/"name": "'"${name_s}"'"/g' ${server_conf} - Set_type_num_a=$((Set_username_num + 3)) - Set_type_num_a_text=$(sed -n "${Set_type_num_a}p" ${server_conf} | sed 's/\"//g;s/,$//g' | awk -F ": " '{print $2}') - sed -i "${Set_type_num_a}"'s/"type": "'"${Set_type_num_a_text}"'"/"type": "'"${type_s}"'"/g' ${server_conf} - Set_location_num_a=$((Set_username_num + 5)) - Set_location_num_a_text=$(sed -n "${Set_location_num_a}p" ${server_conf} | sed 's/\"//g;s/,$//g' | awk -F ": " '{print $2}') - sed -i "${Set_location_num_a}"'s/"location": "'"${Set_location_num_a_text}"'"/"location": "'"${location_s}"'"/g' ${server_conf} - Set_region_num_a=$((Set_username_num + 7)) - Set_region_num_a_text=$(sed -n "${Set_region_num_a}p" ${server_conf} | sed 's/\"//g;s/,$//g' | awk -F ": " '{print $2}') - sed -i "${Set_region_num_a}"'s/"region": "'"${Set_region_num_a_text}"'"/"region": "'"${region_s}"'"/g' ${server_conf} - echo -e "${Info} 修改成功。" - else - echo -e "${Error} 请输入正确的节点用户名 !" && exit 1 - fi -} - -Modify_ServerStatus_server_disabled() { - List_ServerStatus_server - echo -e "请输入要修改的节点用户名" - read -erp "(默认: 取消):" manually_username - [[ -z "${manually_username}" ]] && echo -e "已取消..." && exit 1 - Set_username_num=$(cat -n ${server_conf} | grep '"username": "'"${manually_username}"'"' | awk '{print $1}') - if [[ -n ${Set_username_num} ]]; then - Set_disabled_num_a=$((Set_username_num + 6)) - Set_disabled_num_a_text=$(sed -n "${Set_disabled_num_a}p" ${server_conf} | sed 's/\"//g;s/,$//g' | awk -F ": " '{print $2}') - if [[ ${Set_disabled_num_a_text} == "false" ]]; then - disabled_s="true" - else - disabled_s="false" - fi - sed -i "${Set_disabled_num_a}"'s/"disabled": '"${Set_disabled_num_a_text}"'/"disabled": '"${disabled_s}"'/g' ${server_conf} - echo -e "${Info} 修改成功 [ 原禁用状态: ${Set_disabled_num_a_text}, 新禁用状态: ${disabled_s} ]" - else - echo -e "${Error} 请输入正确的节点用户名 !" && exit 1 - fi -} - -Set_ServerStatus_client() { - check_installed_client_status - Set_config_client - Read_config_client - Modify_config_client - Restart_ServerStatus_client -} - -Modify_config_client() { - sed -i 's/SERVER = "'"${client_server}"'"/SERVER = "'"${server_s}"'"/g' "${client_file}/client-linux.py" - sed -i "s/PORT = ${client_port}/PORT = ${server_port_s}/g" "${client_file}/client-linux.py" - sed -i 's/USER = "'"${client_user}"'"/USER = "'"${username_s}"'"/g' "${client_file}/client-linux.py" - sed -i 's/PASSWORD = "'"${client_password}"'"/PASSWORD = "'"${password_s}"'"/g' "${client_file}/client-linux.py" -} - -Install_caddy() { - echo - echo -e "${Info} 是否由脚本自动配置HTTP服务(服务端的在线监控网站),如果选择 N,则请在其他HTTP服务中配置网站根目录为:${Green_font_prefix}${web_file}${Font_color_suffix} [Y/n]" - read -erp "(默认: Y 自动部署):" caddy_yn - [[ -z "$caddy_yn" ]] && caddy_yn="y" - if [[ "${caddy_yn}" == [Yy] ]]; then - caddy_file="/etc/caddy/Caddyfile" # Where is the default Caddyfile specified in Archlinux? - [[ ! -e /usr/bin/caddy ]] && { - if [[ ${release} == "debian" ]]; then - apt install -y debian-keyring debian-archive-keyring apt-transport-https curl - curl -1sLf "https://dl.cloudsmith.io/public/caddy/stable/gpg.key" | tee /etc/apt/trusted.gpg.d/caddy-stable.asc - curl -1sLf "https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt" | tee /etc/apt/sources.list.d/caddy-stable.list - apt update && apt install caddy - elif [[ ${release} == "centos" ]]; then - yum install yum-plugin-copr -y - yum copr enable @caddy/caddy -y - yum install caddy -y - elif [[ ${release} == "archlinux" ]]; then - pacman -Sy caddy --noconfirm - fi - [[ ! -e "/usr/bin/caddy" ]] && echo -e "${Error} Caddy安装失败,请手动部署,Web网页文件位置:${web_file}" && exit 1 - systemctl enable caddy - echo "" >${caddy_file} - } - Set_server "server" - Set_server_http_port - cat >>${caddy_file} <<-EOF -http://${server_s}:${server_http_port_s} { - root * ${web_file} - encode gzip - file_server -} -EOF - systemctl restart caddy - else - echo -e "${Info} 跳过 HTTP服务部署,请手动部署,Web网页文件位置:${web_file} ,如果位置改变,请注意修改服务脚本文件 /etc/init.d/status-server 中的 WEB_BIN 变量 !" - fi -} - -Install_ServerStatus_server() { - Set_Mirror - [[ -e "${server_file}/sergate" ]] && echo -e "${Error} 检测到 ServerStatus 服务端已安装 !" && exit 1 - Set_server_port - echo -e "${Info} 开始安装/配置 依赖..." - Installation_dependency "server" - Install_caddy - echo -e "${Info} 开始下载/安装..." - Download_Server_Status_server - Install_jq - echo -e "${Info} 开始下载/安装 服务脚本(init)..." - Service_Server_Status_server - echo -e "${Info} 开始写入 配置文件..." - Write_server_config - Write_server_config_conf - echo -e "${Info} 所有步骤 安装完毕,开始启动..." - Start_ServerStatus_server -} - -Install_ServerStatus_client() { - Set_Mirror - [[ -e "${client_file}/client-linux.py" ]] && echo -e "${Error} 检测到 ServerStatus 客户端已安装 !" && exit 1 - echo -e "${Info} 开始设置 用户配置..." - Set_config_client - echo -e "${Info} 开始下载/安装..." - Download_Server_Status_client - echo -e "${Info} 开始下载/安装 服务脚本(init)..." - Service_Server_Status_client - echo -e "${Info} 开始写入 配置..." - Read_config_client - Modify_config_client - echo -e "${Info} 所有步骤 安装完毕,开始启动..." - Start_ServerStatus_client -} - -Update_ServerStatus_server() { - Set_Mirror - check_installed_server_status - check_pid_server - if [[ -n ${PID} ]]; then - if [[ ${release} == "archlinux" ]]; then - systemctl stop status-server - else - /etc/init.d/status-server stop - fi - fi - Download_Server_Status_server - rm -rf /etc/init.d/status-server - Service_Server_Status_server - Start_ServerStatus_server -} - -Update_ServerStatus_client() { - Set_Mirror - check_installed_client_status - check_pid_client - if [[ -n ${PID} ]]; then - if [[ ${release} == "archlinux" ]]; then - systemctl stop status-client - else - /etc/init.d/status-client stop - fi - fi - if [[ ! -e "${client_file}/client-linux.py" ]]; then - if [[ ! -e "${file}/client-linux.py" ]]; then - echo -e "${Error} ServerStatus 客户端文件不存在 !" && exit 1 - else - client_text="$(sed 's/\"//g;s/,//g;s/ //g' "${file}/client-linux.py")" - rm -rf "${file}/client-linux.py" - fi - else - client_text="$(sed 's/\"//g;s/,//g;s/ //g' "${client_file}/client-linux.py")" - fi - server_s="$(echo -e "${client_text}" | grep "SERVER=" | awk -F "=" '{print $2}')" - server_port_s="$(echo -e "${client_text}" | grep "PORT=" | awk -F "=" '{print $2}')" - username_s="$(echo -e "${client_text}" | grep "USER=" | awk -F "=" '{print $2}')" - password_s="$(echo -e "${client_text}" | grep "PASSWORD=" | awk -F "=" '{print $2}')" - grep -q "NET_IN, NET_OUT = get_traffic_vnstat()" "${client_file}/client-linux.py" && client_vnstat_s="true" || client_vnstat_s="false" - Download_Server_Status_client - Read_config_client - Modify_config_client - rm -rf /etc/init.d/status-client - Service_Server_Status_client - Start_ServerStatus_client -} - -Start_ServerStatus_server() { - check_installed_server_status - check_pid_server - [[ -n ${PID} ]] && echo -e "${Error} ServerStatus 正在运行,请检查 !" && exit 1 - if [[ ${release} == "archlinux" ]]; then - systemctl start status-server.service - else - /etc/init.d/status-server start - fi -} - -Stop_ServerStatus_server() { - check_installed_server_status - check_pid_server - [[ -z ${PID} ]] && echo -e "${Error} ServerStatus 没有运行,请检查 !" && exit 1 - if [[ ${release} == "archlinux" ]]; then - systemctl stop status-server.service - else - /etc/init.d/status-server stop - fi -} - -Restart_ServerStatus_server() { - check_installed_server_status - check_pid_server - if [[ -n ${PID} ]]; then - if [[ ${release} == "archlinux" ]]; then - systemctl stop status-server.service - else - /etc/init.d/status-server stop - fi - fi - if [[ ${release} == "archlinux" ]]; then - systemctl start status-server.service - else - /etc/init.d/status-server start - fi -} - -Uninstall_ServerStatus_server() { - check_installed_server_status - echo "确定要卸载 ServerStatus 服务端(如果同时安装了客户端,则只会删除服务端) ? [y/N]" - echo - read -erp "(默认: n):" unyn - [[ -z ${unyn} ]] && unyn="n" - if [[ ${unyn} == [Yy] ]]; then - check_pid_server - [[ -n $PID ]] && kill -9 "${PID}" - Read_config_server - if [[ -e "${client_file}/client-linux.py" ]]; then - rm -rf "${server_file}" - rm -rf "${web_file}" - else - rm -rf "${file}" - fi - rm -rf "/etc/init.d/status-server" - if [[ -e "/usr/bin/caddy" ]]; then - systemctl stop caddy - systemctl disable caddy - [[ ${release} == "debian" ]] && apt purge -y caddy - [[ ${release} == "centos" ]] && yum -y remove caddy - [[ ${release} == "archlinux" ]] && pacman -R caddy --noconfirm - fi - if [[ ${release} == "centos" ]]; then - chkconfig --del status-server - elif [[ ${release} == "debian" ]]; then - update-rc.d -f status-server remove - elif [[ ${release} == "archlinux" ]]; then - systemctl stop status-server - systemctl disable status-server - rm /usr/lib/systemd/system/status-server.service - fi - echo && echo "ServerStatus 卸载完成 !" && echo - else - echo && echo "卸载已取消..." && echo - fi -} - -Start_ServerStatus_client() { - check_installed_client_status - check_pid_client - [[ -n ${PID} ]] && echo -e "${Error} ServerStatus 正在运行,请检查 !" && exit 1 - systemctl enable status-client - service status-client start - -} - -Stop_ServerStatus_client() { - check_installed_client_status - check_pid_client - [[ -z ${PID} ]] && echo -e "${Error} ServerStatus 没有运行,请检查 !" && exit 1 - service status-client stop -} - -Restart_ServerStatus_client() { - check_installed_client_status - check_pid_client - if [[ -n ${PID} ]]; then - service status-client restart - fi -} - -Uninstall_ServerStatus_client() { - check_installed_client_status - echo "确定要卸载 ServerStatus 客户端(如果同时安装了服务端,则只会删除客户端) ? [y/N]" - echo - read -erp "(默认: n):" unyn - [[ -z ${unyn} ]] && unyn="n" - if [[ ${unyn} == [Yy] ]]; then - check_pid_client - [[ -n $PID ]] && kill -9 "${PID}" - Read_config_client - if [[ -e "${server_file}/sergate" ]]; then - rm -rf "${client_file}" - else - rm -rf "${file}" - fi - rm -rf /etc/init.d/status-client - if [[ ${release} == "centos" ]]; then - chkconfig --del status-client - elif [[ ${release} == "debian" ]]; then - update-rc.d -f status-client remove - elif [[ ${release} == "archlinux" ]]; then - systemctl stop status-client - systemctl disable status-client - rm /usr/lib/systemd/system/status-client.service - fi - echo && echo "ServerStatus 卸载完成 !" && echo - else - echo && echo "卸载已取消..." && echo - fi -} - -View_ServerStatus_client() { - check_installed_client_status - Read_config_client - clear && echo "————————————————————" && echo - echo -e " ServerStatus 客户端配置信息: - - IP \t: ${Green_font_prefix}${client_server}${Font_color_suffix} - 端口 \t: ${Green_font_prefix}${client_port}${Font_color_suffix} - 账号 \t: ${Green_font_prefix}${client_user}${Font_color_suffix} - 密码 \t: ${Green_font_prefix}${client_password}${Font_color_suffix} - -————————————————————" -} -View_client_Log() { - [[ ! -e ${client_log_file} ]] && echo -e "${Error} 没有找到日志文件 !" && exit 1 - echo && echo -e "${Tip} 按 ${Red_font_prefix}Ctrl+C${Font_color_suffix} 终止查看日志" && echo -e "如果需要查看完整日志内容,请用 ${Red_font_prefix}cat ${client_log_file}${Font_color_suffix} 命令。" && echo - tail -f ${client_log_file} -} -View_server_Log() { - [[ ! -e ${server_log_file} ]] && echo -e "${Error} 没有找到日志文件 !" && exit 1 - echo && echo -e "${Tip} 按 ${Red_font_prefix}Ctrl+C${Font_color_suffix} 终止查看日志" && echo -e "如果需要查看完整日志内容,请用 ${Red_font_prefix}cat ${server_log_file}${Font_color_suffix} 命令。" && echo - tail -f ${server_log_file} -} -Update_Shell() { - Set_Mirror - sh_new_ver=$(wget --no-check-certificate -qO- -t1 -T3 "${link_prefix}/status.sh" | grep 'sh_ver="' | awk -F "=" '{print $NF}' | sed 's/\"//g' | head -1) - [[ -z ${sh_new_ver} ]] && echo -e "${Error} 无法链接到 Github !" && exit 0 - if [[ -e "/etc/init.d/status-client" ]] || [[ -e "/usr/lib/systemd/system/status-client.service" ]]; then - rm -rf /etc/init.d/status-client - rm -rf /usr/lib/systemd/system/status-client.service - Service_Server_Status_client - fi - if [[ -e "/etc/init.d/status-server" ]] || [[ -e "/usr/lib/systemd/system/status-server.service" ]]; then - rm -rf /etc/init.d/status-server - rm -rf /usr/lib/systemd/system/status-server.service - Service_Server_Status_server - fi - wget -N --no-check-certificate "${link_prefix}/status.sh" && chmod +x status.sh - echo -e "脚本已更新为最新版本[ ${sh_new_ver} ] !(注意:因为更新方式为直接覆盖当前运行的脚本,所以可能下面会提示一些报错,无视即可)" && exit 0 -} -menu_client() { - echo && echo -e " ServerStatus 一键安装管理脚本 ${Red_font_prefix}[v${sh_ver}]${Font_color_suffix} - -- Toyo | doub.io/shell-jc3 -- - -- Modified by APTX -- - ${Green_font_prefix} 0.${Font_color_suffix} 升级脚本 - ———————————— - ${Green_font_prefix} 1.${Font_color_suffix} 安装 客户端 - ${Green_font_prefix} 2.${Font_color_suffix} 更新 客户端 - ${Green_font_prefix} 3.${Font_color_suffix} 卸载 客户端 -———————————— - ${Green_font_prefix} 4.${Font_color_suffix} 启动 客户端 - ${Green_font_prefix} 5.${Font_color_suffix} 停止 客户端 - ${Green_font_prefix} 6.${Font_color_suffix} 重启 客户端 -———————————— - ${Green_font_prefix} 7.${Font_color_suffix} 设置 客户端配置 - ${Green_font_prefix} 8.${Font_color_suffix} 查看 客户端信息 - ${Green_font_prefix} 9.${Font_color_suffix} 查看 客户端日志 -———————————— - ${Green_font_prefix}10.${Font_color_suffix} 切换为 服务端菜单" && echo - if [[ -e "${client_file}/client-linux.py" ]]; then - check_pid_client - if [[ -n "${PID}" ]]; then - echo -e " 当前状态: 客户端 ${Green_font_prefix}已安装${Font_color_suffix} 并 ${Green_font_prefix}已启动${Font_color_suffix}" - else - echo -e " 当前状态: 客户端 ${Green_font_prefix}已安装${Font_color_suffix} 但 ${Red_font_prefix}未启动${Font_color_suffix}" - fi - else - if [[ -e "${file}/client-linux.py" ]]; then - check_pid_client - if [[ -n "${PID}" ]]; then - echo -e " 当前状态: 客户端 ${Green_font_prefix}已安装${Font_color_suffix} 并 ${Green_font_prefix}已启动${Font_color_suffix}" - else - echo -e " 当前状态: 客户端 ${Green_font_prefix}已安装${Font_color_suffix} 但 ${Red_font_prefix}未启动${Font_color_suffix}" - fi - else - echo -e " 当前状态: 客户端 ${Red_font_prefix}未安装${Font_color_suffix}" - fi - fi - echo - read -erp " 请输入数字 [0-10]:" num - case "$num" in - 0) - Update_Shell - ;; - 1) - Install_ServerStatus_client - ;; - 2) - Update_ServerStatus_client - ;; - 3) - Uninstall_ServerStatus_client - ;; - 4) - Start_ServerStatus_client - ;; - 5) - Stop_ServerStatus_client - ;; - 6) - Restart_ServerStatus_client - ;; - 7) - Set_ServerStatus_client - ;; - 8) - View_ServerStatus_client - ;; - 9) - View_client_Log - ;; - 10) - menu_server - ;; - *) - echo "请输入正确数字 [0-10]" - ;; - esac -} -menu_server() { - echo && echo -e " ServerStatus 一键安装管理脚本 ${Red_font_prefix}[v${sh_ver}]${Font_color_suffix} - -- Toyo | doub.io/shell-jc3 -- - -- Modified by APTX -- - ${Green_font_prefix} 0.${Font_color_suffix} 升级脚本 - ———————————— - ${Green_font_prefix} 1.${Font_color_suffix} 安装 服务端 - ${Green_font_prefix} 2.${Font_color_suffix} 更新 服务端 - ${Green_font_prefix} 3.${Font_color_suffix} 卸载 服务端 -———————————— - ${Green_font_prefix} 4.${Font_color_suffix} 启动 服务端 - ${Green_font_prefix} 5.${Font_color_suffix} 停止 服务端 - ${Green_font_prefix} 6.${Font_color_suffix} 重启 服务端 -———————————— - ${Green_font_prefix} 7.${Font_color_suffix} 设置 服务端配置 - ${Green_font_prefix} 8.${Font_color_suffix} 查看 服务端信息 - ${Green_font_prefix} 9.${Font_color_suffix} 查看 服务端日志 -———————————— - ${Green_font_prefix}10.${Font_color_suffix} 切换为 客户端菜单" && echo - if [[ -e "${server_file}/sergate" ]]; then - check_pid_server - if [[ -n "${PID}" ]]; then - echo -e " 当前状态: 服务端 ${Green_font_prefix}已安装${Font_color_suffix} 并 ${Green_font_prefix}已启动${Font_color_suffix}" - else - echo -e " 当前状态: 服务端 ${Green_font_prefix}已安装${Font_color_suffix} 但 ${Red_font_prefix}未启动${Font_color_suffix}" - fi - else - echo -e " 当前状态: 服务端 ${Red_font_prefix}未安装${Font_color_suffix}" - fi - echo - read -erp " 请输入数字 [0-10]:" num - case "$num" in - 0) - Update_Shell - ;; - 1) - Install_ServerStatus_server - ;; - 2) - Update_ServerStatus_server - ;; - 3) - Uninstall_ServerStatus_server - ;; - 4) - Start_ServerStatus_server - ;; - 5) - Stop_ServerStatus_server - ;; - 6) - Restart_ServerStatus_server - ;; - 7) - Set_ServerStatus_server - ;; - 8) - List_ServerStatus_server - ;; - 9) - View_server_Log - ;; - 10) - menu_client - ;; - *) - echo "请输入正确数字 [0-10]" - ;; - esac -} - -Set_Mirror() { - echo -e "${Info} 请输入要选择的下载源,默认使用GitHub,中国大陆建议选择Coding.net,但是不建议将服务端部署在中国大陆主机上 - ${Green_font_prefix} 1.${Font_color_suffix} GitHub - ${Green_font_prefix} 2.${Font_color_suffix} Coding.net (部分资源通过 FastGit 提供服务下载, Thanks to FastGit.org for the service)" - read -erp "请输入数字 [1-2], 默认为 1:" mirror_num - [[ -z "${mirror_num}" ]] && mirror_num=1 - [[ ${mirror_num} == 2 ]] && link_prefix=${coding_prefix} || link_prefix=${github_prefix} -} -action=$1 -if [[ -n $action ]]; then - if [[ $action == "s" ]]; then - menu_server - elif [[ $action == "c" ]]; then - menu_client - fi -else - menu_client -fi From 00bc87c2c275860590d3c02afd1c6ec4099dd5eb Mon Sep 17 00:00:00 2001 From: jwstaceyOvO <38880537+jwstaceyOvO@users.noreply.github.com> Date: Mon, 14 Feb 2022 16:37:05 +0800 Subject: [PATCH 12/23] Add files via upload --- status.sh | 982 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 982 insertions(+) create mode 100644 status.sh diff --git a/status.sh b/status.sh new file mode 100644 index 0000000..666a801 --- /dev/null +++ b/status.sh @@ -0,0 +1,982 @@ +#!/usr/bin/env bash +PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin +export PATH + +#================================================= +# System Required: CentOS/Debian/Ubuntu/ArchLinux +# Description: ServerStatus client + server +# Version: Test v0.4.1 +# Author: Toyo, Modified by APTX +#================================================= + +sh_ver="0.4.1" +filepath=$( + cd "$(dirname "$0")" || exit + pwd +) +file_1=$(echo -e "${filepath}" | awk -F "$0" '{print $1}') +file="/usr/local/ServerStatus" +web_file="/usr/local/ServerStatus/web" +server_file="/usr/local/ServerStatus/server" +server_conf="/usr/local/ServerStatus/server/config.json" +server_conf_1="/usr/local/ServerStatus/server/config.conf" +client_file="/usr/local/ServerStatus/clients" + +client_log_file="/tmp/serverstatus_client.log" +server_log_file="/tmp/serverstatus_server.log" +jq_file="${file}/jq" +[[ ! -e ${jq_file} ]] && jq_file="/usr/bin/jq" + +github_prefix="https://raw.githubusercontent.com/jwstaceyOvO/ServerStatus/master" +coding_prefix="https://cokemine.coding.net/p/hotarunet/d/ServerStatus-Hotaru/git/raw/master" +link_prefix=${github_prefix} + +Green_font_prefix="\033[32m" && Red_font_prefix="\033[31m" && Red_background_prefix="\033[41;37m" && Font_color_suffix="\033[0m" +Info="${Green_font_prefix}[信息]${Font_color_suffix}" +Error="${Red_font_prefix}[错误]${Font_color_suffix}" +Tip="${Green_font_prefix}[注意]${Font_color_suffix}" + +check_installed_server_status() { + [[ ! -e "${server_file}/sergate" ]] && echo -e "${Error} ServerStatus 服务端没有安装,请检查 !" && exit 1 +} +check_installed_client_status() { + [[ ! -e "${client_file}/client-linux.py" ]] && echo -e "${Error} ServerStatus 客户端没有安装,请检查 !" && exit 1 +} +check_pid_server() { + #PID=$(ps -ef | grep "sergate" | grep -v grep | grep -v ".sh" | grep -v "init.d" | grep -v "service" | awk '{print $2}') + PID=$(pgrep -f "sergate") +} +check_pid_client() { + #PID=$(ps -ef | grep "client-linux.py" | grep -v grep | grep -v ".sh" | grep -v "init.d" | grep -v "service" | awk '{print $2}') + PID=$(pgrep -f "client-linux.py") +} + +Download_Server_Status_server() { +git clone https://github.com/cppla/ServerStatus.git "${file}" +} +Download_Server_Status_client() { +git clone https://github.com/cppla/ServerStatus.git "${file}" +} +Download_Server_Status_Service() { + mode=$1 + [[ -z ${mode} ]] && mode="server" + local service_note="服务端" + [[ ${mode} == "client" ]] && service_note="客户端" + wget --no-check-certificate "${link_prefix}/service/status-${mode}.service" -O "/usr/lib/systemd/system/status-${mode}.service" || + { + echo -e "${Error} ServerStatus ${service_note}服务管理脚本下载失败 !" + exit 1 + } + echo -e "${Info} ServerStatus ${service_note}服务管理脚本下载完成 !" +} +Service_Server_Status_server() { + Download_Server_Status_Service "server" +} +Service_Server_Status_client() { + Download_Server_Status_Service "client" +} +Write_server_config() { + cat >${server_conf} <<-EOF +{"servers": + [ + { + "username": "username01", + "password": "password", + "name": "Server 01", + "type": "KVM", + "host": "", + "location": "Hong Kong", + "disabled": false, + "region": "HK" + } + ] +} +EOF +} +Write_server_config_conf() { + cat >${server_conf_1} <<-EOF +PORT = ${server_port_s} +EOF +} +Read_config_client() { + client_text="$(sed 's/\"//g;s/,//g;s/ //g' "${client_file}/client-linux.py") " + client_server="$(echo -e "${client_text}" | grep "SERVER =" | awk -F "=" '{print $2}')" + client_port="$(echo -e "${client_text}" | grep "PORT =" | awk -F "=" '{print $2}')" + client_user="$(echo -e "${client_text}" | grep "USER =" | awk -F "=" '{print $2}')" + client_password="$(echo -e "${client_text}" | grep "PASSWORD =" | awk -F "=" '{print $2}')" +} +Read_config_server() { + if [[ ! -e "${server_conf_1}" ]]; then + server_port_s="35601" + Write_server_config_conf + server_port="35601" + else + server_port="$(grep "PORT = " ${server_conf_1} | awk '{print $3}')" + fi +} +Set_server() { + mode=$1 + [[ -z ${mode} ]] && mode="server" + if [[ ${mode} == "server" ]]; then + echo -e "请输入 ServerStatus 服务端中网站要设置的 域名[server] +默认为本机IP为域名,例如输入: toyoo.pw ,如果要使用本机IP,请留空直接回车" + read -erp "(默认: 本机IP):" server_s + [[ -z "$server_s" ]] && server_s="" + else + echo -e "请输入 ServerStatus 服务端的 IP/域名[server],请注意,如果你的域名使用了CDN,请直接填写IP" + read -erp "(默认: 127.0.0.1):" server_s + [[ -z "$server_s" ]] && server_s="127.0.0.1" + fi + + echo && echo " ================================================" + echo -e " IP/域名[server]: ${Red_background_prefix} ${server_s} ${Font_color_suffix}" + echo " ================================================" && echo +} +Set_server_http_port() { + while true; do + echo -e "请输入 ServerStatus 服务端中网站要设置的 域名/IP的端口[1-65535](如果是域名的话,一般用 80 端口)" + read -erp "(默认: 8888):" server_http_port_s + [[ -z "$server_http_port_s" ]] && server_http_port_s="8888" + if [[ "$server_http_port_s" =~ ^[0-9]*$ ]]; then + if [[ ${server_http_port_s} -ge 1 ]] && [[ ${server_http_port_s} -le 65535 ]]; then + echo && echo " ================================================" + echo -e " 端口: ${Red_background_prefix} ${server_http_port_s} ${Font_color_suffix}" + echo " ================================================" && echo + break + else + echo "输入错误, 请输入正确的端口。" + fi + else + echo "输入错误, 请输入正确的端口。" + fi + done +} +Set_server_port() { + while true; do + echo -e "请输入 ServerStatus 服务端监听的端口[1-65535](用于服务端接收客户端消息的端口,客户端要填写这个端口)" + read -erp "(默认: 35601):" server_port_s + [[ -z "$server_port_s" ]] && server_port_s="35601" + if [[ "$server_port_s" =~ ^[0-9]*$ ]]; then + if [[ ${server_port_s} -ge 1 ]] && [[ ${server_port_s} -le 65535 ]]; then + echo && echo " ================================================" + echo -e " 端口: ${Red_background_prefix} ${server_port_s} ${Font_color_suffix}" + echo " ================================================" && echo + break + else + echo "输入错误, 请输入正确的端口。" + fi + else + echo "输入错误, 请输入正确的端口。" + fi + done +} +Set_username() { + mode=$1 + [[ -z ${mode} ]] && mode="server" + if [[ ${mode} == "server" ]]; then + echo -e "请输入 ServerStatus 服务端要设置的用户名[username](字母/数字,不可与其他账号重复)" + else + echo -e "请输入 ServerStatus 服务端中对应配置的用户名[username](字母/数字,不可与其他账号重复)" + fi + read -erp "(默认: 取消):" username_s + [[ -z "$username_s" ]] && echo "已取消..." && exit 0 + echo && echo " ================================================" + echo -e " 账号[username]: ${Red_background_prefix} ${username_s} ${Font_color_suffix}" + echo " ================================================" && echo +} +Set_password() { + mode=$1 + [[ -z ${mode} ]] && mode="server" + if [[ ${mode} == "server" ]]; then + echo -e "请输入 ServerStatus 服务端要设置的密码[password](字母/数字,可重复)" + else + echo -e "请输入 ServerStatus 服务端中对应配置的密码[password](字母/数字)" + fi + read -erp "(默认: doub.io):" password_s + [[ -z "$password_s" ]] && password_s="doub.io" + echo && echo " ================================================" + echo -e " 密码[password]: ${Red_background_prefix} ${password_s} ${Font_color_suffix}" + echo " ================================================" && echo +} +Set_name() { + echo -e "请输入 ServerStatus 服务端要设置的节点名称[name](支持中文,前提是你的系统和SSH工具支持中文输入,仅仅是个名字)" + read -erp "(默认: Server 01):" name_s + [[ -z "$name_s" ]] && name_s="Server 01" + echo && echo " ================================================" + echo -e " 节点名称[name]: ${Red_background_prefix} ${name_s} ${Font_color_suffix}" + echo " ================================================" && echo +} +Set_type() { + echo -e "请输入 ServerStatus 服务端要设置的节点虚拟化类型[type](例如 OpenVZ / KVM)" + read -erp "(默认: KVM):" type_s + [[ -z "$type_s" ]] && type_s="KVM" + echo && echo " ================================================" + echo -e " 虚拟化类型[type]: ${Red_background_prefix} ${type_s} ${Font_color_suffix}" + echo " ================================================" && echo +} +Set_location() { + echo -e "请输入 ServerStatus 服务端要设置的节点位置[location](支持中文,前提是你的系统和SSH工具支持中文输入)" + read -erp "(默认: Hong Kong):" location_s + [[ -z "$location_s" ]] && location_s="Hong Kong" + echo && echo " ================================================" + echo -e " 节点位置[location]: ${Red_background_prefix} ${location_s} ${Font_color_suffix}" + echo " ================================================" && echo +} +Set_region() { + echo -e "请输入 ServerStatus 服务端要设置的节点地区[region](用于国家/地区的旗帜图标显示)" + read -erp "(默认: HK):" region_s + [[ -z "$region_s" ]] && region_s="HK" + while ! check_region; do + read -erp "你输入的节点地区不合法,请重新输入:" region_s + done + echo && echo " ================================================" + echo -e " 节点地区[region]: ${Red_background_prefix} ${region_s} ${Font_color_suffix}" + echo " ================================================" && echo +} +Set_config_server() { + Set_username "server" + Set_password "server" + Set_name + Set_type + Set_location + Set_region +} +Set_config_client() { + Set_server "client" + Set_server_port + Set_username "client" + Set_password "client" +} +Set_ServerStatus_server() { + check_installed_server_status + echo && echo -e " 你要做什么? + + ${Green_font_prefix} 1.${Font_color_suffix} 添加 节点配置 + ${Green_font_prefix} 2.${Font_color_suffix} 删除 节点配置 +———————— + ${Green_font_prefix} 3.${Font_color_suffix} 修改 节点配置 - 节点用户名 + ${Green_font_prefix} 4.${Font_color_suffix} 修改 节点配置 - 节点密码 + ${Green_font_prefix} 5.${Font_color_suffix} 修改 节点配置 - 节点名称 + ${Green_font_prefix} 6.${Font_color_suffix} 修改 节点配置 - 节点虚拟化 + ${Green_font_prefix} 7.${Font_color_suffix} 修改 节点配置 - 节点位置 + ${Green_font_prefix} 8.${Font_color_suffix} 修改 节点配置 - 全部参数 +———————— + ${Green_font_prefix} 9.${Font_color_suffix} 启用/禁用 节点配置 +———————— + ${Green_font_prefix}10.${Font_color_suffix} 修改 服务端监听端口" && echo + read -erp "(默认: 取消):" server_num + [[ -z "${server_num}" ]] && echo "已取消..." && exit 1 + if [[ ${server_num} == "1" ]]; then + Add_ServerStatus_server + elif [[ ${server_num} == "2" ]]; then + Del_ServerStatus_server + elif [[ ${server_num} == "3" ]]; then + Modify_ServerStatus_server_username + elif [[ ${server_num} == "4" ]]; then + Modify_ServerStatus_server_password + elif [[ ${server_num} == "5" ]]; then + Modify_ServerStatus_server_name + elif [[ ${server_num} == "6" ]]; then + Modify_ServerStatus_server_type + elif [[ ${server_num} == "7" ]]; then + Modify_ServerStatus_server_location + elif [[ ${server_num} == "8" ]]; then + Modify_ServerStatus_server_all + elif [[ ${server_num} == "9" ]]; then + Modify_ServerStatus_server_disabled + elif [[ ${server_num} == "10" ]]; then + Read_config_server + Set_server_port + Write_server_config_conf + else + echo -e "${Error} 请输入正确的数字[1-10]" && exit 1 + fi + Restart_ServerStatus_server +} + +List_ServerStatus_server() { + conf_text=$(${jq_file} '.servers' ${server_conf} | ${jq_file} ".[]|.username" | sed 's/\"//g') + conf_text_total=$(echo -e "${conf_text}" | wc -l) + [[ ${conf_text_total} == "0" ]] && echo -e "${Error} 没有发现 一个节点配置,请检查 !" && exit 1 + conf_text_total_a=$((conf_text_total - 1)) + conf_list_all="" + for ((integer = 0; integer <= conf_text_total_a; integer++)); do + now_text=$(${jq_file} '.servers' ${server_conf} | ${jq_file} ".[${integer}]" | sed 's/\"//g;s/,$//g' | sed '$d;1d') + now_text_username=$(echo -e "${now_text}" | grep "username" | awk -F ": " '{print $2}') + now_text_password=$(echo -e "${now_text}" | grep "password" | awk -F ": " '{print $2}') + now_text_name=$(echo -e "${now_text}" | grep "name" | grep -v "username" | awk -F ": " '{print $2}') + now_text_type=$(echo -e "${now_text}" | grep "type" | awk -F ": " '{print $2}') + now_text_location=$(echo -e "${now_text}" | grep "location" | awk -F ": " '{print $2}') + now_text_region=$(echo -e "${now_text}" | grep "region" | awk -F ": " '{print $2}') + now_text_disabled=$(echo -e "${now_text}" | grep "disabled" | awk -F ": " '{print $2}') + if [[ ${now_text_disabled} == "false" ]]; then + now_text_disabled_status="${Green_font_prefix}启用${Font_color_suffix}" + else + now_text_disabled_status="${Red_font_prefix}禁用${Font_color_suffix}" + fi + conf_list_all=${conf_list_all}"用户名: ${Green_font_prefix}${now_text_username}${Font_color_suffix} 密码: ${Green_font_prefix}${now_text_password}${Font_color_suffix} 节点名: ${Green_font_prefix}${now_text_name}${Font_color_suffix} 类型: ${Green_font_prefix}${now_text_type}${Font_color_suffix} 位置: ${Green_font_prefix}${now_text_location}${Font_color_suffix} 区域: ${Green_font_prefix}${now_text_region}${Font_color_suffix} 状态: ${Green_font_prefix}${now_text_disabled_status}${Font_color_suffix}\n" + done + echo && echo -e "节点总数 ${Green_font_prefix}${conf_text_total}${Font_color_suffix}" + echo -e "${conf_list_all}" +} + +Add_ServerStatus_server() { + Set_config_server + Set_username_ch=$(grep '"username": "'"${username_s}"'"' ${server_conf}) + [[ -n "${Set_username_ch}" ]] && echo -e "${Error} 用户名已被使用 !" && exit 1 + sed -i '3i\ },' ${server_conf} + sed -i '3i\ "region": "'"${region_s}"'"' ${server_conf} + sed -i '3i\ "disabled": false ,' ${server_conf} + sed -i '3i\ "location": "'"${location_s}"'",' ${server_conf} + sed -i '3i\ "host": "'"None"'",' ${server_conf} + sed -i '3i\ "type": "'"${type_s}"'",' ${server_conf} + sed -i '3i\ "name": "'"${name_s}"'",' ${server_conf} + sed -i '3i\ "password": "'"${password_s}"'",' ${server_conf} + sed -i '3i\ "username": "'"${username_s}"'",' ${server_conf} + sed -i '3i\ {' ${server_conf} + echo -e "${Info} 添加节点成功 ${Green_font_prefix}[ 节点名称: ${name_s}, 节点用户名: ${username_s}, 节点密码: ${password_s} ]${Font_color_suffix} !" +} +Del_ServerStatus_server() { + List_ServerStatus_server + [[ "${conf_text_total}" == "1" ]] && echo -e "${Error} 节点配置仅剩 1个,不能删除 !" && exit 1 + echo -e "请输入要删除的节点用户名" + read -erp "(默认: 取消):" del_server_username + [[ -z "${del_server_username}" ]] && echo -e "已取消..." && exit 1 + del_username=$(cat -n ${server_conf} | grep '"username": "'"${del_server_username}"'"' | awk '{print $1}') + if [[ -n ${del_username} ]]; then + del_username_min=$((del_username - 1)) + del_username_max=$((del_username + 8)) + del_username_max_text=$(sed -n "${del_username_max}p" ${server_conf}) + del_username_max_text_last=${del_username_max_text:((${#del_username_max_text} - 1))} + if [[ ${del_username_max_text_last} != "," ]]; then + del_list_num=$((del_username_min - 1)) + sed -i "${del_list_num}s/,$//g" ${server_conf} + fi + sed -i "${del_username_min},${del_username_max}d" ${server_conf} + echo -e "${Info} 节点删除成功 ${Green_font_prefix}[ 节点用户名: ${del_server_username} ]${Font_color_suffix} " + else + echo -e "${Error} 请输入正确的节点用户名 !" && exit 1 + fi +} + +Modify_ServerStatus_server_username() { + List_ServerStatus_server + echo -e "请输入要修改的节点用户名" + read -erp "(默认: 取消):" manually_username + [[ -z "${manually_username}" ]] && echo -e "已取消..." && exit 1 + Set_username_num=$(cat -n ${server_conf} | grep '"username": "'"${manually_username}"'"' | awk '{print $1}') + if [[ -n ${Set_username_num} ]]; then + Set_username + Set_username_ch=$(grep '"username": "'"${username_s}"'"' ${server_conf}) + [[ -n "${Set_username_ch}" ]] && echo -e "${Error} 用户名已被使用 !" && exit 1 + sed -i "${Set_username_num}"'s/"username": "'"${manually_username}"'"/"username": "'"${username_s}"'"/g' ${server_conf} + echo -e "${Info} 修改成功 [ 原节点用户名: ${manually_username}, 新节点用户名: ${username_s} ]" + else + echo -e "${Error} 请输入正确的节点用户名 !" && exit 1 + fi +} + +Modify_ServerStatus_server_password() { + List_ServerStatus_server + echo -e "请输入要修改的节点用户名" + read -erp "(默认: 取消):" manually_username + [[ -z "${manually_username}" ]] && echo -e "已取消..." && exit 1 + Set_username_num=$(cat -n ${server_conf} | grep '"username": "'"${manually_username}"'"' | awk '{print $1}') + if [[ -n ${Set_username_num} ]]; then + Set_password + Set_password_num_a=$((Set_username_num + 1)) + Set_password_num_text=$(sed -n "${Set_password_num_a}p" ${server_conf} | sed 's/\"//g;s/,$//g' | awk -F ": " '{print $2}') + sed -i "${Set_password_num_a}"'s/"password": "'"${Set_password_num_text}"'"/"password": "'"${password_s}"'"/g' ${server_conf} + echo -e "${Info} 修改成功 [ 原节点密码: ${Set_password_num_text}, 新节点密码: ${password_s} ]" + else + echo -e "${Error} 请输入正确的节点用户名 !" && exit 1 + fi +} + +Modify_ServerStatus_server_name() { + List_ServerStatus_server + echo -e "请输入要修改的节点用户名" + read -erp "(默认: 取消):" manually_username + [[ -z "${manually_username}" ]] && echo -e "已取消..." && exit 1 + Set_username_num=$(cat -n ${server_conf} | grep '"username": "'"${manually_username}"'"' | awk '{print $1}') + if [[ -n ${Set_username_num} ]]; then + Set_name + Set_name_num_a=$((Set_username_num + 2)) + Set_name_num_a_text=$(sed -n "${Set_name_num_a}p" ${server_conf} | sed 's/\"//g;s/,$//g' | awk -F ": " '{print $2}') + sed -i "${Set_name_num_a}"'s/"name": "'"${Set_name_num_a_text}"'"/"name": "'"${name_s}"'"/g' ${server_conf} + echo -e "${Info} 修改成功 [ 原节点名称: ${Set_name_num_a_text}, 新节点名称: ${name_s} ]" + else + echo -e "${Error} 请输入正确的节点用户名 !" && exit 1 + fi +} + +Modify_ServerStatus_server_type() { + List_ServerStatus_server + echo -e "请输入要修改的节点用户名" + read -erp "(默认: 取消):" manually_username + [[ -z "${manually_username}" ]] && echo -e "已取消..." && exit 1 + Set_username_num=$(cat -n ${server_conf} | grep '"username": "'"${manually_username}"'"' | awk '{print $1}') + if [[ -n ${Set_username_num} ]]; then + Set_type + Set_type_num_a=$((Set_username_num + 3)) + Set_type_num_a_text=$(sed -n "${Set_type_num_a}p" ${server_conf} | sed 's/\"//g;s/,$//g' | awk -F ": " '{print $2}') + sed -i "${Set_type_num_a}"'s/"type": "'"${Set_type_num_a_text}"'"/"type": "'"${type_s}"'"/g' ${server_conf} + echo -e "${Info} 修改成功 [ 原节点虚拟化: ${Set_type_num_a_text}, 新节点虚拟化: ${type_s} ]" + else + echo -e "${Error} 请输入正确的节点用户名 !" && exit 1 + fi +} +Modify_ServerStatus_server_location() { + List_ServerStatus_server + echo -e "请输入要修改的节点用户名" + read -erp "(默认: 取消):" manually_username + [[ -z "${manually_username}" ]] && echo -e "已取消..." && exit 1 + Set_username_num=$(cat -n ${server_conf} | grep '"username": "'"${manually_username}"'"' | awk '{print $1}') + if [[ -n ${Set_username_num} ]]; then + Set_location + Set_location_num_a=$((Set_username_num + 5)) + Set_location_num_a_text=$(sed -n "${Set_location_num_a}p" ${server_conf} | sed 's/\"//g;s/,$//g' | awk -F ": " '{print $2}') + sed -i "${Set_location_num_a}"'s/"location": "'"${Set_location_num_a_text}"'"/"location": "'"${location_s}"'"/g' ${server_conf} + echo -e "${Info} 修改成功 [ 原节点位置: ${Set_location_num_a_text}, 新节点位置: ${location_s} ]" + else + echo -e "${Error} 请输入正确的节点用户名 !" && exit 1 + fi +} + +Modify_ServerStatus_server_all() { + List_ServerStatus_server + echo -e "请输入要修改的节点用户名" + read -erp "(默认: 取消):" manually_username + [[ -z "${manually_username}" ]] && echo -e "已取消..." && exit 1 + Set_username_num=$(cat -n ${server_conf} | grep '"username": "'"${manually_username}"'"' | awk '{print $1}') + if [[ -n ${Set_username_num} ]]; then + Set_username + Set_password + Set_name + Set_type + Set_location + Set_region + sed -i "${Set_username_num}"'s/"username": "'"${manually_username}"'"/"username": "'"${username_s}"'"/g' ${server_conf} + Set_password_num_a=$((Set_username_num + 1)) + Set_password_num_text=$(sed -n "${Set_password_num_a}p" ${server_conf} | sed 's/\"//g;s/,$//g' | awk -F ": " '{print $2}') + sed -i "${Set_password_num_a}"'s/"password": "'"${Set_password_num_text}"'"/"password": "'"${password_s}"'"/g' ${server_conf} + Set_name_num_a=$((Set_username_num + 2)) + Set_name_num_a_text=$(sed -n "${Set_name_num_a}p" ${server_conf} | sed 's/\"//g;s/,$//g' | awk -F ": " '{print $2}') + sed -i "${Set_name_num_a}"'s/"name": "'"${Set_name_num_a_text}"'"/"name": "'"${name_s}"'"/g' ${server_conf} + Set_type_num_a=$((Set_username_num + 3)) + Set_type_num_a_text=$(sed -n "${Set_type_num_a}p" ${server_conf} | sed 's/\"//g;s/,$//g' | awk -F ": " '{print $2}') + sed -i "${Set_type_num_a}"'s/"type": "'"${Set_type_num_a_text}"'"/"type": "'"${type_s}"'"/g' ${server_conf} + Set_location_num_a=$((Set_username_num + 5)) + Set_location_num_a_text=$(sed -n "${Set_location_num_a}p" ${server_conf} | sed 's/\"//g;s/,$//g' | awk -F ": " '{print $2}') + sed -i "${Set_location_num_a}"'s/"location": "'"${Set_location_num_a_text}"'"/"location": "'"${location_s}"'"/g' ${server_conf} + Set_region_num_a=$((Set_username_num + 7)) + Set_region_num_a_text=$(sed -n "${Set_region_num_a}p" ${server_conf} | sed 's/\"//g;s/,$//g' | awk -F ": " '{print $2}') + sed -i "${Set_region_num_a}"'s/"region": "'"${Set_region_num_a_text}"'"/"region": "'"${region_s}"'"/g' ${server_conf} + echo -e "${Info} 修改成功。" + else + echo -e "${Error} 请输入正确的节点用户名 !" && exit 1 + fi +} + +Modify_ServerStatus_server_disabled() { + List_ServerStatus_server + echo -e "请输入要修改的节点用户名" + read -erp "(默认: 取消):" manually_username + [[ -z "${manually_username}" ]] && echo -e "已取消..." && exit 1 + Set_username_num=$(cat -n ${server_conf} | grep '"username": "'"${manually_username}"'"' | awk '{print $1}') + if [[ -n ${Set_username_num} ]]; then + Set_disabled_num_a=$((Set_username_num + 6)) + Set_disabled_num_a_text=$(sed -n "${Set_disabled_num_a}p" ${server_conf} | sed 's/\"//g;s/,$//g' | awk -F ": " '{print $2}') + if [[ ${Set_disabled_num_a_text} == "false" ]]; then + disabled_s="true" + else + disabled_s="false" + fi + sed -i "${Set_disabled_num_a}"'s/"disabled": '"${Set_disabled_num_a_text}"'/"disabled": '"${disabled_s}"'/g' ${server_conf} + echo -e "${Info} 修改成功 [ 原禁用状态: ${Set_disabled_num_a_text}, 新禁用状态: ${disabled_s} ]" + else + echo -e "${Error} 请输入正确的节点用户名 !" && exit 1 + fi +} + +Set_ServerStatus_client() { + check_installed_client_status + Set_config_client + Read_config_client + Modify_config_client + Restart_ServerStatus_client +} + +Modify_config_client() { + sed -i 's/SERVER = "'"${client_server}"'"/SERVER = "'"${server_s}"'"/g' "${client_file}/client-linux.py" + sed -i "s/PORT = ${client_port}/PORT = ${server_port_s}/g" "${client_file}/client-linux.py" + sed -i 's/USER = "'"${client_user}"'"/USER = "'"${username_s}"'"/g' "${client_file}/client-linux.py" + sed -i 's/PASSWORD = "'"${client_password}"'"/PASSWORD = "'"${password_s}"'"/g' "${client_file}/client-linux.py" +} + +Install_caddy() { + echo + echo -e "${Info} 是否由脚本自动配置HTTP服务(服务端的在线监控网站),如果选择 N,则请在其他HTTP服务中配置网站根目录为:${Green_font_prefix}${web_file}${Font_color_suffix} [Y/n]" + read -erp "(默认: Y 自动部署):" caddy_yn + [[ -z "$caddy_yn" ]] && caddy_yn="y" + if [[ "${caddy_yn}" == [Yy] ]]; then + caddy_file="/etc/caddy/Caddyfile" # Where is the default Caddyfile specified in Archlinux? + [[ ! -e /usr/bin/caddy ]] && { + if [[ ${release} == "debian" ]]; then + apt install -y debian-keyring debian-archive-keyring apt-transport-https curl + curl -1sLf "https://dl.cloudsmith.io/public/caddy/stable/gpg.key" | tee /etc/apt/trusted.gpg.d/caddy-stable.asc + curl -1sLf "https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt" | tee /etc/apt/sources.list.d/caddy-stable.list + apt update && apt install caddy + elif [[ ${release} == "centos" ]]; then + yum install yum-plugin-copr -y + yum copr enable @caddy/caddy -y + yum install caddy -y + elif [[ ${release} == "archlinux" ]]; then + pacman -Sy caddy --noconfirm + fi + [[ ! -e "/usr/bin/caddy" ]] && echo -e "${Error} Caddy安装失败,请手动部署,Web网页文件位置:${web_file}" && exit 1 + systemctl enable caddy + echo "" >${caddy_file} + } + Set_server "server" + Set_server_http_port + cat >>${caddy_file} <<-EOF +http://${server_s}:${server_http_port_s} { + root * ${web_file} + encode gzip + file_server +} +EOF + systemctl restart caddy + else + echo -e "${Info} 跳过 HTTP服务部署,请手动部署,Web网页文件位置:${web_file} ,如果位置改变,请注意修改服务脚本文件 /etc/init.d/status-server 中的 WEB_BIN 变量 !" + fi +} + +Install_ServerStatus_server() { + Set_Mirror + [[ -e "${server_file}/sergate" ]] && echo -e "${Error} 检测到 ServerStatus 服务端已安装 !" && exit 1 + Set_server_port + echo -e "${Info} 开始安装/配置 依赖..." + Installation_dependency "server" + Install_caddy + echo -e "${Info} 开始下载/安装..." + Download_Server_Status_server + Install_jq + echo -e "${Info} 开始下载/安装 服务脚本(init)..." + Service_Server_Status_server + echo -e "${Info} 开始写入 配置文件..." + Write_server_config + Write_server_config_conf + echo -e "${Info} 所有步骤 安装完毕,开始启动..." + Start_ServerStatus_server +} + +Install_ServerStatus_client() { + Set_Mirror + [[ -e "${client_file}/client-linux.py" ]] && echo -e "${Error} 检测到 ServerStatus 客户端已安装 !" && exit 1 + echo -e "${Info} 开始设置 用户配置..." + Set_config_client + echo -e "${Info} 开始下载/安装..." + Download_Server_Status_client + echo -e "${Info} 开始下载/安装 服务脚本(init)..." + Service_Server_Status_client + echo -e "${Info} 开始写入 配置..." + Read_config_client + Modify_config_client + echo -e "${Info} 所有步骤 安装完毕,开始启动..." + Start_ServerStatus_client +} + +Update_ServerStatus_server() { + Set_Mirror + check_installed_server_status + check_pid_server + if [[ -n ${PID} ]]; then + if [[ ${release} == "archlinux" ]]; then + systemctl stop status-server + else + /etc/init.d/status-server stop + fi + fi + Download_Server_Status_server + rm -rf /etc/init.d/status-server + Service_Server_Status_server + Start_ServerStatus_server +} + +Update_ServerStatus_client() { + Set_Mirror + check_installed_client_status + check_pid_client + if [[ -n ${PID} ]]; then + if [[ ${release} == "archlinux" ]]; then + systemctl stop status-client + else + /etc/init.d/status-client stop + fi + fi + if [[ ! -e "${client_file}/client-linux.py" ]]; then + if [[ ! -e "${file}/client-linux.py" ]]; then + echo -e "${Error} ServerStatus 客户端文件不存在 !" && exit 1 + else + client_text="$(sed 's/\"//g;s/,//g;s/ //g' "${file}/client-linux.py")" + rm -rf "${file}/client-linux.py" + fi + else + client_text="$(sed 's/\"//g;s/,//g;s/ //g' "${client_file}/client-linux.py")" + fi + server_s="$(echo -e "${client_text}" | grep "SERVER=" | awk -F "=" '{print $2}')" + server_port_s="$(echo -e "${client_text}" | grep "PORT=" | awk -F "=" '{print $2}')" + username_s="$(echo -e "${client_text}" | grep "USER=" | awk -F "=" '{print $2}')" + password_s="$(echo -e "${client_text}" | grep "PASSWORD=" | awk -F "=" '{print $2}')" + grep -q "NET_IN, NET_OUT = get_traffic_vnstat()" "${client_file}/client-linux.py" && client_vnstat_s="true" || client_vnstat_s="false" + Download_Server_Status_client + Read_config_client + Modify_config_client + rm -rf /etc/init.d/status-client + Service_Server_Status_client + Start_ServerStatus_client +} + +Start_ServerStatus_server() { + check_installed_server_status + check_pid_server + [[ -n ${PID} ]] && echo -e "${Error} ServerStatus 正在运行,请检查 !" && exit 1 + if [[ ${release} == "archlinux" ]]; then + systemctl start status-server.service + else + /etc/init.d/status-server start + fi +} + +Stop_ServerStatus_server() { + check_installed_server_status + check_pid_server + [[ -z ${PID} ]] && echo -e "${Error} ServerStatus 没有运行,请检查 !" && exit 1 + if [[ ${release} == "archlinux" ]]; then + systemctl stop status-server.service + else + /etc/init.d/status-server stop + fi +} + +Restart_ServerStatus_server() { + check_installed_server_status + check_pid_server + if [[ -n ${PID} ]]; then + if [[ ${release} == "archlinux" ]]; then + systemctl stop status-server.service + else + /etc/init.d/status-server stop + fi + fi + if [[ ${release} == "archlinux" ]]; then + systemctl start status-server.service + else + /etc/init.d/status-server start + fi +} + +Uninstall_ServerStatus_server() { + check_installed_server_status + echo "确定要卸载 ServerStatus 服务端(如果同时安装了客户端,则只会删除服务端) ? [y/N]" + echo + read -erp "(默认: n):" unyn + [[ -z ${unyn} ]] && unyn="n" + if [[ ${unyn} == [Yy] ]]; then + check_pid_server + [[ -n $PID ]] && kill -9 "${PID}" + Read_config_server + if [[ -e "${client_file}/client-linux.py" ]]; then + rm -rf "${server_file}" + rm -rf "${web_file}" + else + rm -rf "${file}" + fi + rm -rf "/etc/init.d/status-server" + if [[ -e "/usr/bin/caddy" ]]; then + systemctl stop caddy + systemctl disable caddy + [[ ${release} == "debian" ]] && apt purge -y caddy + [[ ${release} == "centos" ]] && yum -y remove caddy + [[ ${release} == "archlinux" ]] && pacman -R caddy --noconfirm + fi + if [[ ${release} == "centos" ]]; then + chkconfig --del status-server + elif [[ ${release} == "debian" ]]; then + update-rc.d -f status-server remove + elif [[ ${release} == "archlinux" ]]; then + systemctl stop status-server + systemctl disable status-server + rm /usr/lib/systemd/system/status-server.service + fi + echo && echo "ServerStatus 卸载完成 !" && echo + else + echo && echo "卸载已取消..." && echo + fi +} + +Start_ServerStatus_client() { + check_installed_client_status + check_pid_client + [[ -n ${PID} ]] && echo -e "${Error} ServerStatus 正在运行,请检查 !" && exit 1 + systemctl enable status-client + service status-client start + +} + +Stop_ServerStatus_client() { + check_installed_client_status + check_pid_client + [[ -z ${PID} ]] && echo -e "${Error} ServerStatus 没有运行,请检查 !" && exit 1 + service status-client stop +} + +Restart_ServerStatus_client() { + check_installed_client_status + check_pid_client + if [[ -n ${PID} ]]; then + service status-client restart + fi +} + +Uninstall_ServerStatus_client() { + check_installed_client_status + echo "确定要卸载 ServerStatus 客户端(如果同时安装了服务端,则只会删除客户端) ? [y/N]" + echo + read -erp "(默认: n):" unyn + [[ -z ${unyn} ]] && unyn="n" + if [[ ${unyn} == [Yy] ]]; then + check_pid_client + [[ -n $PID ]] && kill -9 "${PID}" + Read_config_client + if [[ -e "${server_file}/sergate" ]]; then + rm -rf "${client_file}" + else + rm -rf "${file}" + fi + rm -rf /etc/init.d/status-client + if [[ ${release} == "centos" ]]; then + chkconfig --del status-client + elif [[ ${release} == "debian" ]]; then + update-rc.d -f status-client remove + elif [[ ${release} == "archlinux" ]]; then + systemctl stop status-client + systemctl disable status-client + rm /usr/lib/systemd/system/status-client.service + fi + echo && echo "ServerStatus 卸载完成 !" && echo + else + echo && echo "卸载已取消..." && echo + fi +} + +View_ServerStatus_client() { + check_installed_client_status + Read_config_client + clear && echo "————————————————————" && echo + echo -e " ServerStatus 客户端配置信息: + + IP \t: ${Green_font_prefix}${client_server}${Font_color_suffix} + 端口 \t: ${Green_font_prefix}${client_port}${Font_color_suffix} + 账号 \t: ${Green_font_prefix}${client_user}${Font_color_suffix} + 密码 \t: ${Green_font_prefix}${client_password}${Font_color_suffix} + +————————————————————" +} +View_client_Log() { + [[ ! -e ${client_log_file} ]] && echo -e "${Error} 没有找到日志文件 !" && exit 1 + echo && echo -e "${Tip} 按 ${Red_font_prefix}Ctrl+C${Font_color_suffix} 终止查看日志" && echo -e "如果需要查看完整日志内容,请用 ${Red_font_prefix}cat ${client_log_file}${Font_color_suffix} 命令。" && echo + tail -f ${client_log_file} +} +View_server_Log() { + [[ ! -e ${server_log_file} ]] && echo -e "${Error} 没有找到日志文件 !" && exit 1 + echo && echo -e "${Tip} 按 ${Red_font_prefix}Ctrl+C${Font_color_suffix} 终止查看日志" && echo -e "如果需要查看完整日志内容,请用 ${Red_font_prefix}cat ${server_log_file}${Font_color_suffix} 命令。" && echo + tail -f ${server_log_file} +} +Update_Shell() { + Set_Mirror + sh_new_ver=$(wget --no-check-certificate -qO- -t1 -T3 "${link_prefix}/status.sh" | grep 'sh_ver="' | awk -F "=" '{print $NF}' | sed 's/\"//g' | head -1) + [[ -z ${sh_new_ver} ]] && echo -e "${Error} 无法链接到 Github !" && exit 0 + if [[ -e "/etc/init.d/status-client" ]] || [[ -e "/usr/lib/systemd/system/status-client.service" ]]; then + rm -rf /etc/init.d/status-client + rm -rf /usr/lib/systemd/system/status-client.service + Service_Server_Status_client + fi + if [[ -e "/etc/init.d/status-server" ]] || [[ -e "/usr/lib/systemd/system/status-server.service" ]]; then + rm -rf /etc/init.d/status-server + rm -rf /usr/lib/systemd/system/status-server.service + Service_Server_Status_server + fi + wget -N --no-check-certificate "${link_prefix}/status.sh" && chmod +x status.sh + echo -e "脚本已更新为最新版本[ ${sh_new_ver} ] !(注意:因为更新方式为直接覆盖当前运行的脚本,所以可能下面会提示一些报错,无视即可)" && exit 0 +} +menu_client() { + echo && echo -e " ServerStatus 一键安装管理脚本 ${Red_font_prefix}[v${sh_ver}]${Font_color_suffix} + -- Toyo | doub.io/shell-jc3 -- + -- Modified by APTX -- + ${Green_font_prefix} 0.${Font_color_suffix} 升级脚本 + ———————————— + ${Green_font_prefix} 1.${Font_color_suffix} 安装 客户端 + ${Green_font_prefix} 2.${Font_color_suffix} 更新 客户端 + ${Green_font_prefix} 3.${Font_color_suffix} 卸载 客户端 +———————————— + ${Green_font_prefix} 4.${Font_color_suffix} 启动 客户端 + ${Green_font_prefix} 5.${Font_color_suffix} 停止 客户端 + ${Green_font_prefix} 6.${Font_color_suffix} 重启 客户端 +———————————— + ${Green_font_prefix} 7.${Font_color_suffix} 设置 客户端配置 + ${Green_font_prefix} 8.${Font_color_suffix} 查看 客户端信息 + ${Green_font_prefix} 9.${Font_color_suffix} 查看 客户端日志 +———————————— + ${Green_font_prefix}10.${Font_color_suffix} 切换为 服务端菜单" && echo + if [[ -e "${client_file}/client-linux.py" ]]; then + check_pid_client + if [[ -n "${PID}" ]]; then + echo -e " 当前状态: 客户端 ${Green_font_prefix}已安装${Font_color_suffix} 并 ${Green_font_prefix}已启动${Font_color_suffix}" + else + echo -e " 当前状态: 客户端 ${Green_font_prefix}已安装${Font_color_suffix} 但 ${Red_font_prefix}未启动${Font_color_suffix}" + fi + else + if [[ -e "${file}/client-linux.py" ]]; then + check_pid_client + if [[ -n "${PID}" ]]; then + echo -e " 当前状态: 客户端 ${Green_font_prefix}已安装${Font_color_suffix} 并 ${Green_font_prefix}已启动${Font_color_suffix}" + else + echo -e " 当前状态: 客户端 ${Green_font_prefix}已安装${Font_color_suffix} 但 ${Red_font_prefix}未启动${Font_color_suffix}" + fi + else + echo -e " 当前状态: 客户端 ${Red_font_prefix}未安装${Font_color_suffix}" + fi + fi + echo + read -erp " 请输入数字 [0-10]:" num + case "$num" in + 0) + Update_Shell + ;; + 1) + Install_ServerStatus_client + ;; + 2) + Update_ServerStatus_client + ;; + 3) + Uninstall_ServerStatus_client + ;; + 4) + Start_ServerStatus_client + ;; + 5) + Stop_ServerStatus_client + ;; + 6) + Restart_ServerStatus_client + ;; + 7) + Set_ServerStatus_client + ;; + 8) + View_ServerStatus_client + ;; + 9) + View_client_Log + ;; + 10) + menu_server + ;; + *) + echo "请输入正确数字 [0-10]" + ;; + esac +} +menu_server() { + echo && echo -e " ServerStatus 一键安装管理脚本 ${Red_font_prefix}[v${sh_ver}]${Font_color_suffix} + -- Toyo | doub.io/shell-jc3 -- + -- Modified by APTX -- + ${Green_font_prefix} 0.${Font_color_suffix} 升级脚本 + ———————————— + ${Green_font_prefix} 1.${Font_color_suffix} 安装 服务端 + ${Green_font_prefix} 2.${Font_color_suffix} 更新 服务端 + ${Green_font_prefix} 3.${Font_color_suffix} 卸载 服务端 +———————————— + ${Green_font_prefix} 4.${Font_color_suffix} 启动 服务端 + ${Green_font_prefix} 5.${Font_color_suffix} 停止 服务端 + ${Green_font_prefix} 6.${Font_color_suffix} 重启 服务端 +———————————— + ${Green_font_prefix} 7.${Font_color_suffix} 设置 服务端配置 + ${Green_font_prefix} 8.${Font_color_suffix} 查看 服务端信息 + ${Green_font_prefix} 9.${Font_color_suffix} 查看 服务端日志 +———————————— + ${Green_font_prefix}10.${Font_color_suffix} 切换为 客户端菜单" && echo + if [[ -e "${server_file}/sergate" ]]; then + check_pid_server + if [[ -n "${PID}" ]]; then + echo -e " 当前状态: 服务端 ${Green_font_prefix}已安装${Font_color_suffix} 并 ${Green_font_prefix}已启动${Font_color_suffix}" + else + echo -e " 当前状态: 服务端 ${Green_font_prefix}已安装${Font_color_suffix} 但 ${Red_font_prefix}未启动${Font_color_suffix}" + fi + else + echo -e " 当前状态: 服务端 ${Red_font_prefix}未安装${Font_color_suffix}" + fi + echo + read -erp " 请输入数字 [0-10]:" num + case "$num" in + 0) + Update_Shell + ;; + 1) + Install_ServerStatus_server + ;; + 2) + Update_ServerStatus_server + ;; + 3) + Uninstall_ServerStatus_server + ;; + 4) + Start_ServerStatus_server + ;; + 5) + Stop_ServerStatus_server + ;; + 6) + Restart_ServerStatus_server + ;; + 7) + Set_ServerStatus_server + ;; + 8) + List_ServerStatus_server + ;; + 9) + View_server_Log + ;; + 10) + menu_client + ;; + *) + echo "请输入正确数字 [0-10]" + ;; + esac +} + +Set_Mirror() { + echo -e "${Info} 请输入要选择的下载源,默认使用GitHub,中国大陆建议选择Coding.net,但是不建议将服务端部署在中国大陆主机上 + ${Green_font_prefix} 1.${Font_color_suffix} GitHub + ${Green_font_prefix} 2.${Font_color_suffix} Coding.net (部分资源通过 FastGit 提供服务下载, Thanks to FastGit.org for the service)" + read -erp "请输入数字 [1-2], 默认为 1:" mirror_num + [[ -z "${mirror_num}" ]] && mirror_num=1 + [[ ${mirror_num} == 2 ]] && link_prefix=${coding_prefix} || link_prefix=${github_prefix} +} +action=$1 +if [[ -n $action ]]; then + if [[ $action == "s" ]]; then + menu_server + elif [[ $action == "c" ]]; then + menu_client + fi +else + menu_client +fi From ec4218f1b053f83f856050fa4aa2cad84749ebaf Mon Sep 17 00:00:00 2001 From: jwstaceyOvO <38880537+jwstaceyOvO@users.noreply.github.com> Date: Mon, 14 Feb 2022 16:41:56 +0800 Subject: [PATCH 13/23] Update status.sh --- status.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/status.sh b/status.sh index 666a801..31ea304 100644 --- a/status.sh +++ b/status.sh @@ -98,6 +98,7 @@ Write_server_config_conf() { PORT = ${server_port_s} EOF } + Read_config_client() { client_text="$(sed 's/\"//g;s/,//g;s/ //g' "${client_file}/client-linux.py") " client_server="$(echo -e "${client_text}" | grep "SERVER =" | awk -F "=" '{print $2}')" @@ -105,6 +106,7 @@ Read_config_client() { client_user="$(echo -e "${client_text}" | grep "USER =" | awk -F "=" '{print $2}')" client_password="$(echo -e "${client_text}" | grep "PASSWORD =" | awk -F "=" '{print $2}')" } + Read_config_server() { if [[ ! -e "${server_conf_1}" ]]; then server_port_s="35601" @@ -114,6 +116,7 @@ Read_config_server() { server_port="$(grep "PORT = " ${server_conf_1} | awk '{print $3}')" fi } + Set_server() { mode=$1 [[ -z ${mode} ]] && mode="server" @@ -132,6 +135,7 @@ Set_server() { echo -e " IP/域名[server]: ${Red_background_prefix} ${server_s} ${Font_color_suffix}" echo " ================================================" && echo } + Set_server_http_port() { while true; do echo -e "请输入 ServerStatus 服务端中网站要设置的 域名/IP的端口[1-65535](如果是域名的话,一般用 80 端口)" @@ -151,6 +155,7 @@ Set_server_http_port() { fi done } + Set_server_port() { while true; do echo -e "请输入 ServerStatus 服务端监听的端口[1-65535](用于服务端接收客户端消息的端口,客户端要填写这个端口)" @@ -170,6 +175,7 @@ Set_server_port() { fi done } + Set_username() { mode=$1 [[ -z ${mode} ]] && mode="server" @@ -184,6 +190,7 @@ Set_username() { echo -e " 账号[username]: ${Red_background_prefix} ${username_s} ${Font_color_suffix}" echo " ================================================" && echo } + Set_password() { mode=$1 [[ -z ${mode} ]] && mode="server" @@ -198,6 +205,7 @@ Set_password() { echo -e " 密码[password]: ${Red_background_prefix} ${password_s} ${Font_color_suffix}" echo " ================================================" && echo } + Set_name() { echo -e "请输入 ServerStatus 服务端要设置的节点名称[name](支持中文,前提是你的系统和SSH工具支持中文输入,仅仅是个名字)" read -erp "(默认: Server 01):" name_s @@ -206,6 +214,7 @@ Set_name() { echo -e " 节点名称[name]: ${Red_background_prefix} ${name_s} ${Font_color_suffix}" echo " ================================================" && echo } + Set_type() { echo -e "请输入 ServerStatus 服务端要设置的节点虚拟化类型[type](例如 OpenVZ / KVM)" read -erp "(默认: KVM):" type_s @@ -214,6 +223,7 @@ Set_type() { echo -e " 虚拟化类型[type]: ${Red_background_prefix} ${type_s} ${Font_color_suffix}" echo " ================================================" && echo } + Set_location() { echo -e "请输入 ServerStatus 服务端要设置的节点位置[location](支持中文,前提是你的系统和SSH工具支持中文输入)" read -erp "(默认: Hong Kong):" location_s @@ -222,6 +232,7 @@ Set_location() { echo -e " 节点位置[location]: ${Red_background_prefix} ${location_s} ${Font_color_suffix}" echo " ================================================" && echo } + Set_region() { echo -e "请输入 ServerStatus 服务端要设置的节点地区[region](用于国家/地区的旗帜图标显示)" read -erp "(默认: HK):" region_s @@ -233,6 +244,7 @@ Set_region() { echo -e " 节点地区[region]: ${Red_background_prefix} ${region_s} ${Font_color_suffix}" echo " ================================================" && echo } + Set_config_server() { Set_username "server" Set_password "server" @@ -241,12 +253,14 @@ Set_config_server() { Set_location Set_region } + Set_config_client() { Set_server "client" Set_server_port Set_username "client" Set_password "client" } + Set_ServerStatus_server() { check_installed_server_status echo && echo -e " 你要做什么? @@ -336,6 +350,7 @@ Add_ServerStatus_server() { sed -i '3i\ {' ${server_conf} echo -e "${Info} 添加节点成功 ${Green_font_prefix}[ 节点名称: ${name_s}, 节点用户名: ${username_s}, 节点密码: ${password_s} ]${Font_color_suffix} !" } + Del_ServerStatus_server() { List_ServerStatus_server [[ "${conf_text_total}" == "1" ]] && echo -e "${Error} 节点配置仅剩 1个,不能删除 !" && exit 1 @@ -426,6 +441,7 @@ Modify_ServerStatus_server_type() { echo -e "${Error} 请输入正确的节点用户名 !" && exit 1 fi } + Modify_ServerStatus_server_location() { List_ServerStatus_server echo -e "请输入要修改的节点用户名" From 64c028f9ce854cc057d5c31dbaf0c713473261d4 Mon Sep 17 00:00:00 2001 From: jwstaceyOvO <38880537+jwstaceyOvO@users.noreply.github.com> Date: Mon, 14 Feb 2022 16:57:08 +0800 Subject: [PATCH 14/23] Update status.sh --- status.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/status.sh b/status.sh index 31ea304..1bc6767 100644 --- a/status.sh +++ b/status.sh @@ -524,10 +524,10 @@ Set_ServerStatus_client() { } Modify_config_client() { - sed -i 's/SERVER = "'"${client_server}"'"/SERVER = "'"${server_s}"'"/g' "${client_file}/client-linux.py" - sed -i "s/PORT = ${client_port}/PORT = ${server_port_s}/g" "${client_file}/client-linux.py" - sed -i 's/USER = "'"${client_user}"'"/USER = "'"${username_s}"'"/g' "${client_file}/client-linux.py" - sed -i 's/PASSWORD = "'"${client_password}"'"/PASSWORD = "'"${password_s}"'"/g' "${client_file}/client-linux.py" + sed -i 's/SERVER = "'"${client_server}"'"/SERVER = "'"${server_s}"'"/' "${client_file}/client-linux.py" + sed -i "s/PORT = ${client_port}/PORT = ${server_port_s}/" "${client_file}/client-linux.py" + sed -i 's/USER = "'"${client_user}"'"/USER = "'"${username_s}"'"/' "${client_file}/client-linux.py" + sed -i 's/PASSWORD = "'"${client_password}"'"/PASSWORD = "'"${password_s}"'"/' "${client_file}/client-linux.py" } Install_caddy() { From 260b7b3a21d643b204d82afd5cc688d0ed30046c Mon Sep 17 00:00:00 2001 From: jwstaceyOvO <38880537+jwstaceyOvO@users.noreply.github.com> Date: Tue, 15 Feb 2022 18:31:39 +0800 Subject: [PATCH 15/23] Update status-server.service --- service/status-server.service | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/service/status-server.service b/service/status-server.service index 0a31890..64d48ae 100644 --- a/service/status-server.service +++ b/service/status-server.service @@ -2,8 +2,7 @@ Description=ServerStatus-Server After=network.target [Service] -EnvironmentFile=/usr/local/ServerStatus/server/config.conf -ExecStart=/root/ServerStatus/server/sergate --config=config.json --web-dir=/usr/local/ServerStatus/web +ExecStart=/usr/local/ServerStatus/server/sergate --config=/usr/local/ServerStatus/server/config.json --web-dir=/usr/local/ServerStatus/web ExecReload=/bin/kill -HUP $MAINPID Restart=on-failure [Install] From fcb4b3cdfea11f24ec19909ee8620620b24ff3f5 Mon Sep 17 00:00:00 2001 From: jwstaceyOvO <38880537+jwstaceyOvO@users.noreply.github.com> Date: Tue, 15 Feb 2022 18:47:44 +0800 Subject: [PATCH 16/23] Update status.sh --- status.sh | 328 +++++++++++++++++++----------------------------------- 1 file changed, 114 insertions(+), 214 deletions(-) diff --git a/status.sh b/status.sh index 1bc6767..d0b4493 100644 --- a/status.sh +++ b/status.sh @@ -4,7 +4,7 @@ export PATH #================================================= # System Required: CentOS/Debian/Ubuntu/ArchLinux -# Description: ServerStatus client + server +# Description: $NAME client + server # Version: Test v0.4.1 # Author: Toyo, Modified by APTX #================================================= @@ -19,114 +19,97 @@ file="/usr/local/ServerStatus" web_file="/usr/local/ServerStatus/web" server_file="/usr/local/ServerStatus/server" server_conf="/usr/local/ServerStatus/server/config.json" -server_conf_1="/usr/local/ServerStatus/server/config.conf" client_file="/usr/local/ServerStatus/clients" client_log_file="/tmp/serverstatus_client.log" server_log_file="/tmp/serverstatus_server.log" -jq_file="${file}/jq" -[[ ! -e ${jq_file} ]] && jq_file="/usr/bin/jq" github_prefix="https://raw.githubusercontent.com/jwstaceyOvO/ServerStatus/master" -coding_prefix="https://cokemine.coding.net/p/hotarunet/d/ServerStatus-Hotaru/git/raw/master" -link_prefix=${github_prefix} +NAME="ServerStatus" Green_font_prefix="\033[32m" && Red_font_prefix="\033[31m" && Red_background_prefix="\033[41;37m" && Font_color_suffix="\033[0m" Info="${Green_font_prefix}[信息]${Font_color_suffix}" Error="${Red_font_prefix}[错误]${Font_color_suffix}" Tip="${Green_font_prefix}[注意]${Font_color_suffix}" check_installed_server_status() { - [[ ! -e "${server_file}/sergate" ]] && echo -e "${Error} ServerStatus 服务端没有安装,请检查 !" && exit 1 + [[ ! -e "${server_file}/sergate" ]] && echo -e "${Error} $NAME 服务端没有安装,请检查 !" && exit 1 } + check_installed_client_status() { - [[ ! -e "${client_file}/client-linux.py" ]] && echo -e "${Error} ServerStatus 客户端没有安装,请检查 !" && exit 1 -} -check_pid_server() { - #PID=$(ps -ef | grep "sergate" | grep -v grep | grep -v ".sh" | grep -v "init.d" | grep -v "service" | awk '{print $2}') - PID=$(pgrep -f "sergate") -} -check_pid_client() { - #PID=$(ps -ef | grep "client-linux.py" | grep -v grep | grep -v ".sh" | grep -v "init.d" | grep -v "service" | awk '{print $2}') - PID=$(pgrep -f "client-linux.py") + [[ ! -e "${client_file}/client-linux.py" ]] && echo -e "${Error} $NAME 客户端没有安装,请检查 !" && exit 1 } Download_Server_Status_server() { -git clone https://github.com/cppla/ServerStatus.git "${file}" +git clone https://github.com/cppla/ServerStatus.git "${file}" && make } + Download_Server_Status_client() { -git clone https://github.com/cppla/ServerStatus.git "${file}" +mkdir -p "${client_file}" +wget -N --no-check-certificate "${github_prefix}/clients/client-linux.py" -P "${client_file}" } + Download_Server_Status_Service() { mode=$1 [[ -z ${mode} ]] && mode="server" local service_note="服务端" [[ ${mode} == "client" ]] && service_note="客户端" - wget --no-check-certificate "${link_prefix}/service/status-${mode}.service" -O "/usr/lib/systemd/system/status-${mode}.service" || + wget --no-check-certificate "${github_prefix}/service/status-${mode}.service" -O "/usr/lib/systemd/system/status-${mode}.service" || { - echo -e "${Error} ServerStatus ${service_note}服务管理脚本下载失败 !" + echo -e "${Error} $NAME ${service_note}服务管理脚本下载失败 !" exit 1 } - echo -e "${Info} ServerStatus ${service_note}服务管理脚本下载完成 !" + echo -e "${Info} $NAME ${service_note}服务管理脚本下载完成 !" } + Service_Server_Status_server() { Download_Server_Status_Service "server" } + Service_Server_Status_client() { Download_Server_Status_Service "client" } + Write_server_config() { cat >${server_conf} <<-EOF {"servers": - [ - { - "username": "username01", - "password": "password", - "name": "Server 01", - "type": "KVM", - "host": "", - "location": "Hong Kong", - "disabled": false, - "region": "HK" - } - ] -} -EOF -} -Write_server_config_conf() { - cat >${server_conf_1} <<-EOF -PORT = ${server_port_s} + [ + { + "username": "s01", + "name": "vps-1", + "type": "kvm", + "host": "chengdu", + "location": "🇨🇳", + "password": "USER_DEFAULT_PASSWORD", + "monthstart": 1 + }, + ] +} EOF } Read_config_client() { client_text="$(sed 's/\"//g;s/,//g;s/ //g' "${client_file}/client-linux.py") " - client_server="$(echo -e "${client_text}" | grep "SERVER =" | awk -F "=" '{print $2}')" - client_port="$(echo -e "${client_text}" | grep "PORT =" | awk -F "=" '{print $2}')" - client_user="$(echo -e "${client_text}" | grep "USER =" | awk -F "=" '{print $2}')" - client_password="$(echo -e "${client_text}" | grep "PASSWORD =" | awk -F "=" '{print $2}')" + client_server="$(echo -e "${client_text}" | grep "SERVER=" | awk -F "=" '{print $2;exit}')" + client_port="$(echo -e "${client_text}" | grep "PORT=" | awk -F "=" '{print $2;exit}')" + client_user="$(echo -e "${client_text}" | grep "USER=" | awk -F "=" '{print $2;exit}')" + client_password="$(echo -e "${client_text}" | grep "PASSWORD=" | awk -F "=" '{print $2;exit}')" } Read_config_server() { - if [[ ! -e "${server_conf_1}" ]]; then - server_port_s="35601" - Write_server_config_conf server_port="35601" - else - server_port="$(grep "PORT = " ${server_conf_1} | awk '{print $3}')" - fi } Set_server() { mode=$1 [[ -z ${mode} ]] && mode="server" if [[ ${mode} == "server" ]]; then - echo -e "请输入 ServerStatus 服务端中网站要设置的 域名[server] + echo -e "请输入 $NAME 服务端中网站要设置的 域名[server] 默认为本机IP为域名,例如输入: toyoo.pw ,如果要使用本机IP,请留空直接回车" read -erp "(默认: 本机IP):" server_s [[ -z "$server_s" ]] && server_s="" else - echo -e "请输入 ServerStatus 服务端的 IP/域名[server],请注意,如果你的域名使用了CDN,请直接填写IP" + echo -e "请输入 $NAME 服务端的 IP/域名[server],请注意,如果你的域名使用了CDN,请直接填写IP" read -erp "(默认: 127.0.0.1):" server_s [[ -z "$server_s" ]] && server_s="127.0.0.1" fi @@ -138,7 +121,7 @@ Set_server() { Set_server_http_port() { while true; do - echo -e "请输入 ServerStatus 服务端中网站要设置的 域名/IP的端口[1-65535](如果是域名的话,一般用 80 端口)" + echo -e "请输入 $NAME 服务端中网站要设置的 域名/IP的端口[1-65535](如果是域名的话,一般用 80 端口)" read -erp "(默认: 8888):" server_http_port_s [[ -z "$server_http_port_s" ]] && server_http_port_s="8888" if [[ "$server_http_port_s" =~ ^[0-9]*$ ]]; then @@ -158,7 +141,7 @@ Set_server_http_port() { Set_server_port() { while true; do - echo -e "请输入 ServerStatus 服务端监听的端口[1-65535](用于服务端接收客户端消息的端口,客户端要填写这个端口)" + echo -e "请输入 $NAME 服务端监听的端口[1-65535](用于服务端接收客户端消息的端口,客户端要填写这个端口)" read -erp "(默认: 35601):" server_port_s [[ -z "$server_port_s" ]] && server_port_s="35601" if [[ "$server_port_s" =~ ^[0-9]*$ ]]; then @@ -180,9 +163,9 @@ Set_username() { mode=$1 [[ -z ${mode} ]] && mode="server" if [[ ${mode} == "server" ]]; then - echo -e "请输入 ServerStatus 服务端要设置的用户名[username](字母/数字,不可与其他账号重复)" + echo -e "请输入 $NAME 服务端要设置的用户名[username](字母/数字,不可与其他账号重复)" else - echo -e "请输入 ServerStatus 服务端中对应配置的用户名[username](字母/数字,不可与其他账号重复)" + echo -e "请输入 $NAME 服务端中对应配置的用户名[username](字母/数字,不可与其他账号重复)" fi read -erp "(默认: 取消):" username_s [[ -z "$username_s" ]] && echo "已取消..." && exit 0 @@ -195,9 +178,9 @@ Set_password() { mode=$1 [[ -z ${mode} ]] && mode="server" if [[ ${mode} == "server" ]]; then - echo -e "请输入 ServerStatus 服务端要设置的密码[password](字母/数字,可重复)" + echo -e "请输入 $NAME 服务端要设置的密码[password](字母/数字,可重复)" else - echo -e "请输入 ServerStatus 服务端中对应配置的密码[password](字母/数字)" + echo -e "请输入 $NAME 服务端中对应配置的密码[password](字母/数字)" fi read -erp "(默认: doub.io):" password_s [[ -z "$password_s" ]] && password_s="doub.io" @@ -207,7 +190,7 @@ Set_password() { } Set_name() { - echo -e "请输入 ServerStatus 服务端要设置的节点名称[name](支持中文,前提是你的系统和SSH工具支持中文输入,仅仅是个名字)" + echo -e "请输入 $NAME 服务端要设置的节点名称[name](支持中文,前提是你的系统和SSH工具支持中文输入,仅仅是个名字)" read -erp "(默认: Server 01):" name_s [[ -z "$name_s" ]] && name_s="Server 01" echo && echo " ================================================" @@ -216,7 +199,7 @@ Set_name() { } Set_type() { - echo -e "请输入 ServerStatus 服务端要设置的节点虚拟化类型[type](例如 OpenVZ / KVM)" + echo -e "请输入 $NAME 服务端要设置的节点虚拟化类型[type](例如 OpenVZ / KVM)" read -erp "(默认: KVM):" type_s [[ -z "$type_s" ]] && type_s="KVM" echo && echo " ================================================" @@ -225,7 +208,7 @@ Set_type() { } Set_location() { - echo -e "请输入 ServerStatus 服务端要设置的节点位置[location](支持中文,前提是你的系统和SSH工具支持中文输入)" + echo -e "请输入 $NAME 服务端要设置的节点位置[location](支持中文,前提是你的系统和SSH工具支持中文输入)" read -erp "(默认: Hong Kong):" location_s [[ -z "$location_s" ]] && location_s="Hong Kong" echo && echo " ================================================" @@ -233,18 +216,6 @@ Set_location() { echo " ================================================" && echo } -Set_region() { - echo -e "请输入 ServerStatus 服务端要设置的节点地区[region](用于国家/地区的旗帜图标显示)" - read -erp "(默认: HK):" region_s - [[ -z "$region_s" ]] && region_s="HK" - while ! check_region; do - read -erp "你输入的节点地区不合法,请重新输入:" region_s - done - echo && echo " ================================================" - echo -e " 节点地区[region]: ${Red_background_prefix} ${region_s} ${Font_color_suffix}" - echo " ================================================" && echo -} - Set_config_server() { Set_username "server" Set_password "server" @@ -301,7 +272,6 @@ Set_ServerStatus_server() { elif [[ ${server_num} == "10" ]]; then Read_config_server Set_server_port - Write_server_config_conf else echo -e "${Error} 请输入正确的数字[1-10]" && exit 1 fi @@ -321,7 +291,6 @@ List_ServerStatus_server() { now_text_name=$(echo -e "${now_text}" | grep "name" | grep -v "username" | awk -F ": " '{print $2}') now_text_type=$(echo -e "${now_text}" | grep "type" | awk -F ": " '{print $2}') now_text_location=$(echo -e "${now_text}" | grep "location" | awk -F ": " '{print $2}') - now_text_region=$(echo -e "${now_text}" | grep "region" | awk -F ": " '{print $2}') now_text_disabled=$(echo -e "${now_text}" | grep "disabled" | awk -F ": " '{print $2}') if [[ ${now_text_disabled} == "false" ]]; then now_text_disabled_status="${Green_font_prefix}启用${Font_color_suffix}" @@ -524,10 +493,10 @@ Set_ServerStatus_client() { } Modify_config_client() { - sed -i 's/SERVER = "'"${client_server}"'"/SERVER = "'"${server_s}"'"/' "${client_file}/client-linux.py" - sed -i "s/PORT = ${client_port}/PORT = ${server_port_s}/" "${client_file}/client-linux.py" - sed -i 's/USER = "'"${client_user}"'"/USER = "'"${username_s}"'"/' "${client_file}/client-linux.py" - sed -i 's/PASSWORD = "'"${client_password}"'"/PASSWORD = "'"${password_s}"'"/' "${client_file}/client-linux.py" + sed -i '0,/SERVER = "'"${client_server}"'"/s//SERVER = "'"${server_s}"'"/' "${client_file}/client-linux.py" + sed -i '0,/PORT = ${client_port}/s//PORT = ${server_port_s}/' "${client_file}/client-linux.py" + sed -i '0,/USER = "'"${client_user}"'"/s//USER = "'"${username_s}"'"/' "${client_file}/client-linux.py" + sed -i '0,/PASSWORD = "'"${client_password}"'"/s//PASSWORD = "'"${password_s}"'"/' "${client_file}/client-linux.py" } Install_caddy() { @@ -570,11 +539,9 @@ EOF } Install_ServerStatus_server() { - Set_Mirror - [[ -e "${server_file}/sergate" ]] && echo -e "${Error} 检测到 ServerStatus 服务端已安装 !" && exit 1 + [[ -e "${server_file}/sergate" ]] && echo -e "${Error} 检测到 $NAME 服务端已安装 !" && exit 1 Set_server_port echo -e "${Info} 开始安装/配置 依赖..." - Installation_dependency "server" Install_caddy echo -e "${Info} 开始下载/安装..." Download_Server_Status_server @@ -583,14 +550,12 @@ Install_ServerStatus_server() { Service_Server_Status_server echo -e "${Info} 开始写入 配置文件..." Write_server_config - Write_server_config_conf echo -e "${Info} 所有步骤 安装完毕,开始启动..." Start_ServerStatus_server } Install_ServerStatus_client() { - Set_Mirror - [[ -e "${client_file}/client-linux.py" ]] && echo -e "${Error} 检测到 ServerStatus 客户端已安装 !" && exit 1 + [[ -e "${client_file}/client-linux.py" ]] && echo -e "${Error} 检测到 $NAME 客户端已安装 !" && exit 1 echo -e "${Info} 开始设置 用户配置..." Set_config_client echo -e "${Info} 开始下载/安装..." @@ -605,16 +570,7 @@ Install_ServerStatus_client() { } Update_ServerStatus_server() { - Set_Mirror check_installed_server_status - check_pid_server - if [[ -n ${PID} ]]; then - if [[ ${release} == "archlinux" ]]; then - systemctl stop status-server - else - /etc/init.d/status-server stop - fi - fi Download_Server_Status_server rm -rf /etc/init.d/status-server Service_Server_Status_server @@ -622,87 +578,50 @@ Update_ServerStatus_server() { } Update_ServerStatus_client() { - Set_Mirror check_installed_client_status - check_pid_client - if [[ -n ${PID} ]]; then - if [[ ${release} == "archlinux" ]]; then - systemctl stop status-client - else - /etc/init.d/status-client stop - fi - fi - if [[ ! -e "${client_file}/client-linux.py" ]]; then - if [[ ! -e "${file}/client-linux.py" ]]; then - echo -e "${Error} ServerStatus 客户端文件不存在 !" && exit 1 - else - client_text="$(sed 's/\"//g;s/,//g;s/ //g' "${file}/client-linux.py")" - rm -rf "${file}/client-linux.py" - fi - else - client_text="$(sed 's/\"//g;s/,//g;s/ //g' "${client_file}/client-linux.py")" - fi - server_s="$(echo -e "${client_text}" | grep "SERVER=" | awk -F "=" '{print $2}')" - server_port_s="$(echo -e "${client_text}" | grep "PORT=" | awk -F "=" '{print $2}')" - username_s="$(echo -e "${client_text}" | grep "USER=" | awk -F "=" '{print $2}')" - password_s="$(echo -e "${client_text}" | grep "PASSWORD=" | awk -F "=" '{print $2}')" - grep -q "NET_IN, NET_OUT = get_traffic_vnstat()" "${client_file}/client-linux.py" && client_vnstat_s="true" || client_vnstat_s="false" + service status-client stop + client_text="$(sed 's/\"//g;s/,//g;s/ //g' "${client_file}/client-linux.py") " + server_s="$(echo -e "${client_text}" | grep "SERVER=" | awk -F "=" '{print $2;exit}')" + server_port_s="$(echo -e "${client_text}" | grep "PORT=" | awk -F "=" '{print $2;exit}')" + username_s="$(echo -e "${client_text}" | grep "USER=" | awk -F "=" '{print $2;exit}')" + password_s="$(echo -e "${client_text}" | grep "PASSWORD=" | awk -F "=" '{print $2;exit}')" Download_Server_Status_client Read_config_client Modify_config_client - rm -rf /etc/init.d/status-client + rm -rf /usr/lib/systemd/system/status-client.service Service_Server_Status_client Start_ServerStatus_client } Start_ServerStatus_server() { check_installed_server_status - check_pid_server - [[ -n ${PID} ]] && echo -e "${Error} ServerStatus 正在运行,请检查 !" && exit 1 - if [[ ${release} == "archlinux" ]]; then - systemctl start status-server.service - else - /etc/init.d/status-server start - fi + systemctl -q is-active status-server && echo -e "${Error} $NAME 正在运行,请检查 !" && exit 1 + service status-server start } Stop_ServerStatus_server() { check_installed_server_status - check_pid_server - [[ -z ${PID} ]] && echo -e "${Error} ServerStatus 没有运行,请检查 !" && exit 1 - if [[ ${release} == "archlinux" ]]; then - systemctl stop status-server.service - else - /etc/init.d/status-server stop - fi +if (systemctl -q is-active status-server) + then + service status-server stop + else + echo -e "${Error} $NAME 没有运行,请检查 !" && exit 1 +fi } Restart_ServerStatus_server() { check_installed_server_status - check_pid_server - if [[ -n ${PID} ]]; then - if [[ ${release} == "archlinux" ]]; then - systemctl stop status-server.service - else - /etc/init.d/status-server stop - fi - fi - if [[ ${release} == "archlinux" ]]; then - systemctl start status-server.service - else - /etc/init.d/status-server start - fi + systemctl -q is-active status-client && service status-server stop } Uninstall_ServerStatus_server() { check_installed_server_status - echo "确定要卸载 ServerStatus 服务端(如果同时安装了客户端,则只会删除服务端) ? [y/N]" + echo "确定要卸载 $NAME 服务端(如果同时安装了客户端,则只会删除服务端) ? [y/N]" echo read -erp "(默认: n):" unyn [[ -z ${unyn} ]] && unyn="n" if [[ ${unyn} == [Yy] ]]; then - check_pid_server - [[ -n $PID ]] && kill -9 "${PID}" + service status-server stop Read_config_server if [[ -e "${client_file}/client-linux.py" ]]; then rm -rf "${server_file}" @@ -710,7 +629,6 @@ Uninstall_ServerStatus_server() { else rm -rf "${file}" fi - rm -rf "/etc/init.d/status-server" if [[ -e "/usr/bin/caddy" ]]; then systemctl stop caddy systemctl disable caddy @@ -718,15 +636,8 @@ Uninstall_ServerStatus_server() { [[ ${release} == "centos" ]] && yum -y remove caddy [[ ${release} == "archlinux" ]] && pacman -R caddy --noconfirm fi - if [[ ${release} == "centos" ]]; then - chkconfig --del status-server - elif [[ ${release} == "debian" ]]; then - update-rc.d -f status-server remove - elif [[ ${release} == "archlinux" ]]; then - systemctl stop status-server - systemctl disable status-server rm /usr/lib/systemd/system/status-server.service - fi + systemctl daemon-reload echo && echo "ServerStatus 卸载完成 !" && echo else echo && echo "卸载已取消..." && echo @@ -734,54 +645,66 @@ Uninstall_ServerStatus_server() { } Start_ServerStatus_client() { +NAME="ServerStatus Client" check_installed_client_status - check_pid_client - [[ -n ${PID} ]] && echo -e "${Error} ServerStatus 正在运行,请检查 !" && exit 1 - systemctl enable status-client - service status-client start - +if (systemctl -q is-active status-client) + then + echo -e "${Error} $NAME 正在运行,请检查 !" && exit 1 +fi + systemctl daemon-reload + systemctl enable status-client + service status-client start + if (systemctl -q is-active status-client) + then + echo -e "${Info} $NAME 启动成功 !" + else + echo -e "${Error} $NAME 启动失败 !" + fi } Stop_ServerStatus_client() { check_installed_client_status - check_pid_client - [[ -z ${PID} ]] && echo -e "${Error} ServerStatus 没有运行,请检查 !" && exit 1 - service status-client stop +if (systemctl -q is-active status-client) + then service status-client stop + if (systemctl -q is-active status-client) + then + echo -e "${Error}} $NAME 停止失败 !" + else + echo -e "${Info} $NAME 停止成功 !" + fi + else + echo -e "${Error} $NAME 没有运行,请检查 !" && exit 1 + fi } Restart_ServerStatus_client() { check_installed_client_status - check_pid_client - if [[ -n ${PID} ]]; then - service status-client restart - fi + service status-client restart +if (systemctl -q is-active status-client) + then + echo -e "${Info} $NAME 重启成功 !" + else + echo -e "${Error} $NAME 重启失败 !" && exit 1 +fi } Uninstall_ServerStatus_client() { check_installed_client_status - echo "确定要卸载 ServerStatus 客户端(如果同时安装了服务端,则只会删除客户端) ? [y/N]" + echo "确定要卸载 $NAME 客户端(如果同时安装了服务端,则只会删除客户端) ? [y/N]" echo read -erp "(默认: n):" unyn [[ -z ${unyn} ]] && unyn="n" if [[ ${unyn} == [Yy] ]]; then - check_pid_client - [[ -n $PID ]] && kill -9 "${PID}" + service status-client stop Read_config_client if [[ -e "${server_file}/sergate" ]]; then rm -rf "${client_file}" - else - rm -rf "${file}" fi - rm -rf /etc/init.d/status-client - if [[ ${release} == "centos" ]]; then - chkconfig --del status-client - elif [[ ${release} == "debian" ]]; then - update-rc.d -f status-client remove - elif [[ ${release} == "archlinux" ]]; then systemctl stop status-client systemctl disable status-client + rm -rf "${client_file}" rm /usr/lib/systemd/system/status-client.service - fi + systemctl daemon-reload echo && echo "ServerStatus 卸载完成 !" && echo else echo && echo "卸载已取消..." && echo @@ -792,7 +715,7 @@ View_ServerStatus_client() { check_installed_client_status Read_config_client clear && echo "————————————————————" && echo - echo -e " ServerStatus 客户端配置信息: + echo -e " $NAME 客户端配置信息: IP \t: ${Green_font_prefix}${client_server}${Font_color_suffix} 端口 \t: ${Green_font_prefix}${client_port}${Font_color_suffix} @@ -812,26 +735,22 @@ View_server_Log() { tail -f ${server_log_file} } Update_Shell() { - Set_Mirror - sh_new_ver=$(wget --no-check-certificate -qO- -t1 -T3 "${link_prefix}/status.sh" | grep 'sh_ver="' | awk -F "=" '{print $NF}' | sed 's/\"//g' | head -1) + sh_new_ver=$(wget --no-check-certificate -qO- -t1 -T3 "${github_prefix}/status.sh" | grep 'sh_ver="' | awk -F "=" '{print $NF}' | sed 's/\"//g' | head -1) [[ -z ${sh_new_ver} ]] && echo -e "${Error} 无法链接到 Github !" && exit 0 - if [[ -e "/etc/init.d/status-client" ]] || [[ -e "/usr/lib/systemd/system/status-client.service" ]]; then - rm -rf /etc/init.d/status-client + if [[ -e "/usr/lib/systemd/system/status-client.service" ]]; then rm -rf /usr/lib/systemd/system/status-client.service Service_Server_Status_client fi - if [[ -e "/etc/init.d/status-server" ]] || [[ -e "/usr/lib/systemd/system/status-server.service" ]]; then - rm -rf /etc/init.d/status-server + if [[ -e "/usr/lib/systemd/system/status-server.service" ]]; then rm -rf /usr/lib/systemd/system/status-server.service Service_Server_Status_server fi - wget -N --no-check-certificate "${link_prefix}/status.sh" && chmod +x status.sh + wget -N --no-check-certificate "${github_prefix}/status.sh" echo -e "脚本已更新为最新版本[ ${sh_new_ver} ] !(注意:因为更新方式为直接覆盖当前运行的脚本,所以可能下面会提示一些报错,无视即可)" && exit 0 } menu_client() { - echo && echo -e " ServerStatus 一键安装管理脚本 ${Red_font_prefix}[v${sh_ver}]${Font_color_suffix} - -- Toyo | doub.io/shell-jc3 -- - -- Modified by APTX -- + echo && echo -e " $NAME 一键安装管理脚本 ${Red_font_prefix}[v${sh_ver}]${Font_color_suffix} + ${Green_font_prefix} 0.${Font_color_suffix} 升级脚本 ———————————— ${Green_font_prefix} 1.${Font_color_suffix} 安装 客户端 @@ -848,23 +767,13 @@ menu_client() { ———————————— ${Green_font_prefix}10.${Font_color_suffix} 切换为 服务端菜单" && echo if [[ -e "${client_file}/client-linux.py" ]]; then - check_pid_client - if [[ -n "${PID}" ]]; then + if (systemctl -q is-active status-client); then echo -e " 当前状态: 客户端 ${Green_font_prefix}已安装${Font_color_suffix} 并 ${Green_font_prefix}已启动${Font_color_suffix}" else echo -e " 当前状态: 客户端 ${Green_font_prefix}已安装${Font_color_suffix} 但 ${Red_font_prefix}未启动${Font_color_suffix}" fi - else - if [[ -e "${file}/client-linux.py" ]]; then - check_pid_client - if [[ -n "${PID}" ]]; then - echo -e " 当前状态: 客户端 ${Green_font_prefix}已安装${Font_color_suffix} 并 ${Green_font_prefix}已启动${Font_color_suffix}" - else - echo -e " 当前状态: 客户端 ${Green_font_prefix}已安装${Font_color_suffix} 但 ${Red_font_prefix}未启动${Font_color_suffix}" - fi else echo -e " 当前状态: 客户端 ${Red_font_prefix}未安装${Font_color_suffix}" - fi fi echo read -erp " 请输入数字 [0-10]:" num @@ -908,7 +817,7 @@ menu_client() { esac } menu_server() { - echo && echo -e " ServerStatus 一键安装管理脚本 ${Red_font_prefix}[v${sh_ver}]${Font_color_suffix} + echo && echo -e " $NAME 一键安装管理脚本 ${Red_font_prefix}[v${sh_ver}]${Font_color_suffix} -- Toyo | doub.io/shell-jc3 -- -- Modified by APTX -- ${Green_font_prefix} 0.${Font_color_suffix} 升级脚本 @@ -927,8 +836,7 @@ menu_server() { ———————————— ${Green_font_prefix}10.${Font_color_suffix} 切换为 客户端菜单" && echo if [[ -e "${server_file}/sergate" ]]; then - check_pid_server - if [[ -n "${PID}" ]]; then + if (systemctl -q is-active status-server) then echo -e " 当前状态: 服务端 ${Green_font_prefix}已安装${Font_color_suffix} 并 ${Green_font_prefix}已启动${Font_color_suffix}" else echo -e " 当前状态: 服务端 ${Green_font_prefix}已安装${Font_color_suffix} 但 ${Red_font_prefix}未启动${Font_color_suffix}" @@ -978,14 +886,6 @@ menu_server() { esac } -Set_Mirror() { - echo -e "${Info} 请输入要选择的下载源,默认使用GitHub,中国大陆建议选择Coding.net,但是不建议将服务端部署在中国大陆主机上 - ${Green_font_prefix} 1.${Font_color_suffix} GitHub - ${Green_font_prefix} 2.${Font_color_suffix} Coding.net (部分资源通过 FastGit 提供服务下载, Thanks to FastGit.org for the service)" - read -erp "请输入数字 [1-2], 默认为 1:" mirror_num - [[ -z "${mirror_num}" ]] && mirror_num=1 - [[ ${mirror_num} == 2 ]] && link_prefix=${coding_prefix} || link_prefix=${github_prefix} -} action=$1 if [[ -n $action ]]; then if [[ $action == "s" ]]; then From 4e1e92e406c6ca36aab03d43a6278dcd8a9a5d9f Mon Sep 17 00:00:00 2001 From: jwstaceyOvO <38880537+jwstaceyOvO@users.noreply.github.com> Date: Wed, 16 Feb 2022 15:47:27 +0800 Subject: [PATCH 17/23] Update status.sh --- status.sh | 153 +++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 110 insertions(+), 43 deletions(-) diff --git a/status.sh b/status.sh index d0b4493..e16090f 100644 --- a/status.sh +++ b/status.sh @@ -2,14 +2,8 @@ PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH -#================================================= -# System Required: CentOS/Debian/Ubuntu/ArchLinux -# Description: $NAME client + server -# Version: Test v0.4.1 -# Author: Toyo, Modified by APTX -#================================================= +sh_ver="1.0.0" -sh_ver="0.4.1" filepath=$( cd "$(dirname "$0")" || exit pwd @@ -19,8 +13,8 @@ file="/usr/local/ServerStatus" web_file="/usr/local/ServerStatus/web" server_file="/usr/local/ServerStatus/server" server_conf="/usr/local/ServerStatus/server/config.json" +plugin_file="/usr/local/ServerStatus/plugin" client_file="/usr/local/ServerStatus/clients" - client_log_file="/tmp/serverstatus_client.log" server_log_file="/tmp/serverstatus_server.log" @@ -41,7 +35,33 @@ check_installed_client_status() { } Download_Server_Status_server() { -git clone https://github.com/cppla/ServerStatus.git "${file}" && make + cd "/tmp" || exit 1 + wget -N --no-check-certificate https://github.com/cppla/ServerStatus/archive/refs/heads/master.zip + [[ ! -e "master.zip" ]] && echo -e "${Error} ServerStatus 服务端下载失败 !" && exit 1 + unzip master.zip + rm -rf master.zip + [[ ! -d "/tmp/ServerStatus-master" ]] && echo -e "${Error} ServerStatus 服务端解压失败 !" && exit 1 + cd "/tmp/ServerStatus-master/server" || exit 1 + make + [[ ! -e "sergate" ]] && echo -e "${Error} ServerStatus 服务端编译失败 !" && cd "${file_1}" && rm -rf "/tmp//ServerStatus-master" && exit 1 + cd "${file_1}" || exit 1 + mkdir -p "${server_file}" + if [[ -e "${server_file}/sergate" ]]; then + mv "${server_file}/sergate" "${server_file}/sergate1" + mv "/tmp/ServerStatus-master/server/sergate" "${server_file}/sergate" + else + mv "/tmp/ServerStatus-master/server/sergate" "${server_file}/sergate" + mv "/tmp/ServerStatus-master/web" "${web_file}" + mv "/tmp/ServerStatus-master/plugin" "${plugin_file}" + fi + rm -rf "/tmp/ServerStatus-master" + if [[ ! -e "${server_file}/sergate" ]]; then + echo -e "${Error} ServerStatus 服务端移动重命名失败 !" + [[ -e "${server_file}/sergate1" ]] && mv "${server_file}/sergate1" "${server_file}/sergate" + exit 1 + else + [[ -e "${server_file}/sergate1" ]] && rm -rf "${server_file}/sergate1" + fi } Download_Server_Status_client() { @@ -59,6 +79,7 @@ Download_Server_Status_Service() { echo -e "${Error} $NAME ${service_note}服务管理脚本下载失败 !" exit 1 } + systemctl enable "status-${mode}.service" echo -e "${Info} $NAME ${service_note}服务管理脚本下载完成 !" } @@ -70,24 +91,44 @@ Service_Server_Status_client() { Download_Server_Status_Service "client" } +Installation_dependency() { + mode=$1 + if [[ ${release} == "centos" ]]; then + yum makecache + yum -y install unzip + yum -y install python3 >/dev/null 2>&1 || yum -y install python + elif [[ ${release} == "debian" ]]; then + apt -y update + apt -y install unzip + apt -y install python3 >/dev/null 2>&1 || apt -y install python + elif [[ ${release} == "archlinux" ]]; then + pacman -Sy python python-pip unzip --noconfirm + fi + [[ ! -e /usr/bin/python ]] && ln -s /usr/bin/python3 /usr/bin/python +} + Write_server_config() { cat >${server_conf} <<-EOF -{"servers": - [ - { - "username": "s01", - "name": "vps-1", - "type": "kvm", - "host": "chengdu", - "location": "🇨🇳", - "password": "USER_DEFAULT_PASSWORD", - "monthstart": 1 - }, - ] -} +{ + "servers": [ + { + "username": "s01", + "name": "vps-1", + "type": "kvm", + "host": "chengdu", + "location": "🇨🇳", + "password": "USER_DEFAULT_PASSWORD", + "monthstart": 1 + } + ] +} EOF } +Write_server_config_conf() { + sed -i "s/m_Port = ${server_port}/m_Port = ${server_port_s}/g" "${server_file}/src/main.cpp" +} + Read_config_client() { client_text="$(sed 's/\"//g;s/,//g;s/ //g' "${client_file}/client-linux.py") " client_server="$(echo -e "${client_text}" | grep "SERVER=" | awk -F "=" '{print $2;exit}')" @@ -97,7 +138,7 @@ Read_config_client() { } Read_config_server() { - server_port="35601" + server_port="$(grep "m_Port = " ${server_file}/src/main.cpp | awk '{print $3}' | sed '{s/;$//}')" } Set_server() { @@ -216,13 +257,22 @@ Set_location() { echo " ================================================" && echo } +Set_monthstart() { + echo -e "请输入 $NAME 服务端要设置的节点月重置流量日[monthstart](每月流量归零的日期(1~28),默认为1(即每月1日))" + read -erp "(默认: 1):" monthstart_s + [[ -z "$monthstart_s" ]] && monthstart_s="1" + echo && echo " ================================================" + echo -e " 月流量重置日[monthstart]: ${Red_background_prefix} ${monthstart_s} ${Font_color_suffix}" + echo " ================================================" && echo +} + Set_config_server() { Set_username "server" Set_password "server" Set_name Set_type Set_location - Set_region + Set_monthstart } Set_config_client() { @@ -272,6 +322,7 @@ Set_ServerStatus_server() { elif [[ ${server_num} == "10" ]]; then Read_config_server Set_server_port + Write_server_config_conf else echo -e "${Error} 请输入正确的数字[1-10]" && exit 1 fi @@ -297,7 +348,7 @@ List_ServerStatus_server() { else now_text_disabled_status="${Red_font_prefix}禁用${Font_color_suffix}" fi - conf_list_all=${conf_list_all}"用户名: ${Green_font_prefix}${now_text_username}${Font_color_suffix} 密码: ${Green_font_prefix}${now_text_password}${Font_color_suffix} 节点名: ${Green_font_prefix}${now_text_name}${Font_color_suffix} 类型: ${Green_font_prefix}${now_text_type}${Font_color_suffix} 位置: ${Green_font_prefix}${now_text_location}${Font_color_suffix} 区域: ${Green_font_prefix}${now_text_region}${Font_color_suffix} 状态: ${Green_font_prefix}${now_text_disabled_status}${Font_color_suffix}\n" + conf_list_all=${conf_list_all}"用户名: ${Green_font_prefix}${now_text_username}${Font_color_suffix} 密码: ${Green_font_prefix}${now_text_password}${Font_color_suffix} 节点名: ${Green_font_prefix}${now_text_name}${Font_color_suffix} 类型: ${Green_font_prefix}${now_text_type}${Font_color_suffix} 位置: ${Green_font_prefix}${now_text_location}${Font_color_suffix} 月流量重置日: ${Green_font_prefix}${now_text_monthstart}${Font_color_suffix} 状态: ${Green_font_prefix}${now_text_disabled_status}${Font_color_suffix}\n" done echo && echo -e "节点总数 ${Green_font_prefix}${conf_text_total}${Font_color_suffix}" echo -e "${conf_list_all}" @@ -308,14 +359,12 @@ Add_ServerStatus_server() { Set_username_ch=$(grep '"username": "'"${username_s}"'"' ${server_conf}) [[ -n "${Set_username_ch}" ]] && echo -e "${Error} 用户名已被使用 !" && exit 1 sed -i '3i\ },' ${server_conf} - sed -i '3i\ "region": "'"${region_s}"'"' ${server_conf} - sed -i '3i\ "disabled": false ,' ${server_conf} - sed -i '3i\ "location": "'"${location_s}"'",' ${server_conf} - sed -i '3i\ "host": "'"None"'",' ${server_conf} - sed -i '3i\ "type": "'"${type_s}"'",' ${server_conf} - sed -i '3i\ "name": "'"${name_s}"'",' ${server_conf} - sed -i '3i\ "password": "'"${password_s}"'",' ${server_conf} sed -i '3i\ "username": "'"${username_s}"'",' ${server_conf} + sed -i '3i\ "name": "'"${name_s}"'",' ${server_conf} + sed -i '3i\ "type": "'"${type_s}"'",' ${server_conf} + sed -i '3i\ "location": "'"${location_s}"'",' ${server_conf} + sed -i '3i\ "password": "'"${password_s}"'",' ${server_conf} + sed -i '3i\ "monthstart": "'"${monthstart_s}"'",' ${server_conf} sed -i '3i\ {' ${server_conf} echo -e "${Info} 添加节点成功 ${Green_font_prefix}[ 节点名称: ${name_s}, 节点用户名: ${username_s}, 节点密码: ${password_s} ]${Font_color_suffix} !" } @@ -428,6 +477,23 @@ Modify_ServerStatus_server_location() { fi } +Modify_ServerStatus_server_monthstart() { + List_ServerStatus_server + echo -e "请输入要修改的节点用户名" + read -erp "(默认: 取消):" manually_username + [[ -z "${manually_username}" ]] && echo -e "已取消..." && exit 1 + Set_username_num=$(cat -n ${server_conf} | grep '"username": "'"${manually_username}"'"' | awk '{print $1}') + if [[ -n ${Set_username_num} ]]; then + Set_monthstart + Set_monthstart_num_a=$((Set_username_num + 1)) + Set_monthstart_num_text=$(sed -n "${Set_monthstart_num_a}p" ${server_conf} | sed 's/\"//g;s/,$//g' | awk -F ": " '{print $2}') + sed -i "${Set_monthstart_num_a}"'s/"monthstart": "'"${Set_monthstart_num_text}"'"/"monthstart": "'"${monthstart_s}"'"/g' ${server_conf} + echo -e "${Info} 修改成功 [ 原月流量重置日: ${Set_monthstart_num_text}, 新月流量重置日: ${monthstart_s} ]" + else + echo -e "${Error} 请输入正确的节点用户名 !" && exit 1 + fi +} + Modify_ServerStatus_server_all() { List_ServerStatus_server echo -e "请输入要修改的节点用户名" @@ -440,7 +506,7 @@ Modify_ServerStatus_server_all() { Set_name Set_type Set_location - Set_region + Set_monthstart sed -i "${Set_username_num}"'s/"username": "'"${manually_username}"'"/"username": "'"${username_s}"'"/g' ${server_conf} Set_password_num_a=$((Set_username_num + 1)) Set_password_num_text=$(sed -n "${Set_password_num_a}p" ${server_conf} | sed 's/\"//g;s/,$//g' | awk -F ": " '{print $2}') @@ -454,9 +520,9 @@ Modify_ServerStatus_server_all() { Set_location_num_a=$((Set_username_num + 5)) Set_location_num_a_text=$(sed -n "${Set_location_num_a}p" ${server_conf} | sed 's/\"//g;s/,$//g' | awk -F ": " '{print $2}') sed -i "${Set_location_num_a}"'s/"location": "'"${Set_location_num_a_text}"'"/"location": "'"${location_s}"'"/g' ${server_conf} - Set_region_num_a=$((Set_username_num + 7)) - Set_region_num_a_text=$(sed -n "${Set_region_num_a}p" ${server_conf} | sed 's/\"//g;s/,$//g' | awk -F ": " '{print $2}') - sed -i "${Set_region_num_a}"'s/"region": "'"${Set_region_num_a_text}"'"/"region": "'"${region_s}"'"/g' ${server_conf} + Set_monthstart_num_a=$((Set_username_num + 7)) + Set_monthstart_num_a_text=$(sed -n "${Set_monthstart_num_a}p" ${server_conf} | sed 's/\"//g;s/,$//g' | awk -F ": " '{print $2}') + sed -i "${Set_monthstart_num_a}"'s/"monthstart": "'"${Set_monthstart_num_a_text}"'"/"monthstart": "'"${monthstart_s}"'"/g' ${server_conf} echo -e "${Info} 修改成功。" else echo -e "${Error} 请输入正确的节点用户名 !" && exit 1 @@ -541,12 +607,11 @@ EOF Install_ServerStatus_server() { [[ -e "${server_file}/sergate" ]] && echo -e "${Error} 检测到 $NAME 服务端已安装 !" && exit 1 Set_server_port - echo -e "${Info} 开始安装/配置 依赖..." Install_caddy echo -e "${Info} 开始下载/安装..." Download_Server_Status_server Install_jq - echo -e "${Info} 开始下载/安装 服务脚本(init)..." + echo -e "${Info} 开始下载/安装 服务脚本..." Service_Server_Status_server echo -e "${Info} 开始写入 配置文件..." Write_server_config @@ -603,7 +668,7 @@ Stop_ServerStatus_server() { check_installed_server_status if (systemctl -q is-active status-server) then - service status-server stop + service status-server stop else echo -e "${Error} $NAME 没有运行,请检查 !" && exit 1 fi @@ -622,7 +687,7 @@ Uninstall_ServerStatus_server() { [[ -z ${unyn} ]] && unyn="n" if [[ ${unyn} == [Yy] ]]; then service status-server stop - Read_config_server + systemctl disable status-server if [[ -e "${client_file}/client-linux.py" ]]; then rm -rf "${server_file}" rm -rf "${web_file}" @@ -651,8 +716,6 @@ if (systemctl -q is-active status-client) then echo -e "${Error} $NAME 正在运行,请检查 !" && exit 1 fi - systemctl daemon-reload - systemctl enable status-client service status-client start if (systemctl -q is-active status-client) then @@ -696,12 +759,12 @@ Uninstall_ServerStatus_client() { [[ -z ${unyn} ]] && unyn="n" if [[ ${unyn} == [Yy] ]]; then service status-client stop + systemctl disable status-client Read_config_client if [[ -e "${server_file}/sergate" ]]; then rm -rf "${client_file}" fi systemctl stop status-client - systemctl disable status-client rm -rf "${client_file}" rm /usr/lib/systemd/system/status-client.service systemctl daemon-reload @@ -724,16 +787,19 @@ View_ServerStatus_client() { ————————————————————" } + View_client_Log() { [[ ! -e ${client_log_file} ]] && echo -e "${Error} 没有找到日志文件 !" && exit 1 echo && echo -e "${Tip} 按 ${Red_font_prefix}Ctrl+C${Font_color_suffix} 终止查看日志" && echo -e "如果需要查看完整日志内容,请用 ${Red_font_prefix}cat ${client_log_file}${Font_color_suffix} 命令。" && echo tail -f ${client_log_file} } + View_server_Log() { [[ ! -e ${server_log_file} ]] && echo -e "${Error} 没有找到日志文件 !" && exit 1 echo && echo -e "${Tip} 按 ${Red_font_prefix}Ctrl+C${Font_color_suffix} 终止查看日志" && echo -e "如果需要查看完整日志内容,请用 ${Red_font_prefix}cat ${server_log_file}${Font_color_suffix} 命令。" && echo tail -f ${server_log_file} } + Update_Shell() { sh_new_ver=$(wget --no-check-certificate -qO- -t1 -T3 "${github_prefix}/status.sh" | grep 'sh_ver="' | awk -F "=" '{print $NF}' | sed 's/\"//g' | head -1) [[ -z ${sh_new_ver} ]] && echo -e "${Error} 无法链接到 Github !" && exit 0 @@ -748,6 +814,7 @@ Update_Shell() { wget -N --no-check-certificate "${github_prefix}/status.sh" echo -e "脚本已更新为最新版本[ ${sh_new_ver} ] !(注意:因为更新方式为直接覆盖当前运行的脚本,所以可能下面会提示一些报错,无视即可)" && exit 0 } + menu_client() { echo && echo -e " $NAME 一键安装管理脚本 ${Red_font_prefix}[v${sh_ver}]${Font_color_suffix} From cab0f8bc9143cae516e1a52415e45ead2c16d6fb Mon Sep 17 00:00:00 2001 From: jwstaceyOvO <38880537+jwstaceyOvO@users.noreply.github.com> Date: Wed, 16 Feb 2022 19:49:16 +0800 Subject: [PATCH 18/23] Update status.sh --- status.sh | 98 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 53 insertions(+), 45 deletions(-) diff --git a/status.sh b/status.sh index e16090f..0ab4487 100644 --- a/status.sh +++ b/status.sh @@ -17,6 +17,7 @@ plugin_file="/usr/local/ServerStatus/plugin" client_file="/usr/local/ServerStatus/clients" client_log_file="/tmp/serverstatus_client.log" server_log_file="/tmp/serverstatus_server.log" +service="/usr/lib/systemd/system" github_prefix="https://raw.githubusercontent.com/jwstaceyOvO/ServerStatus/master" @@ -46,14 +47,9 @@ Download_Server_Status_server() { [[ ! -e "sergate" ]] && echo -e "${Error} ServerStatus 服务端编译失败 !" && cd "${file_1}" && rm -rf "/tmp//ServerStatus-master" && exit 1 cd "${file_1}" || exit 1 mkdir -p "${server_file}" - if [[ -e "${server_file}/sergate" ]]; then - mv "${server_file}/sergate" "${server_file}/sergate1" - mv "/tmp/ServerStatus-master/server/sergate" "${server_file}/sergate" - else - mv "/tmp/ServerStatus-master/server/sergate" "${server_file}/sergate" - mv "/tmp/ServerStatus-master/web" "${web_file}" - mv "/tmp/ServerStatus-master/plugin" "${plugin_file}" - fi + mv "/tmp/ServerStatus-master/server" "${file}" + mv "/tmp/ServerStatus-master/web" "${file}" + mv "/tmp/ServerStatus-master/plugin" "${file}" rm -rf "/tmp/ServerStatus-master" if [[ ! -e "${server_file}/sergate" ]]; then echo -e "${Error} ServerStatus 服务端移动重命名失败 !" @@ -74,7 +70,7 @@ Download_Server_Status_Service() { [[ -z ${mode} ]] && mode="server" local service_note="服务端" [[ ${mode} == "client" ]] && service_note="客户端" - wget --no-check-certificate "${github_prefix}/service/status-${mode}.service" -O "/usr/lib/systemd/system/status-${mode}.service" || + wget --no-check-certificate "${github_prefix}/service/status-${mode}.service" -O "${service}/status-${mode}.service" || { echo -e "${Error} $NAME ${service_note}服务管理脚本下载失败 !" exit 1 @@ -358,14 +354,15 @@ Add_ServerStatus_server() { Set_config_server Set_username_ch=$(grep '"username": "'"${username_s}"'"' ${server_conf}) [[ -n "${Set_username_ch}" ]] && echo -e "${Error} 用户名已被使用 !" && exit 1 - sed -i '3i\ },' ${server_conf} - sed -i '3i\ "username": "'"${username_s}"'",' ${server_conf} - sed -i '3i\ "name": "'"${name_s}"'",' ${server_conf} - sed -i '3i\ "type": "'"${type_s}"'",' ${server_conf} - sed -i '3i\ "location": "'"${location_s}"'",' ${server_conf} - sed -i '3i\ "password": "'"${password_s}"'",' ${server_conf} - sed -i '3i\ "monthstart": "'"${monthstart_s}"'",' ${server_conf} - sed -i '3i\ {' ${server_conf} + sed -i '3i\ },' ${server_conf} + sed -i '3i\ "monthstart": "'"${monthstart_s}"'",' ${server_conf} + sed -i '3i\ "location": "'"${location_s}"'",' ${server_conf} + sed -i '3i\ "host": "'"None"'",' ${server_conf} + sed -i '3i\ "type": "'"${type_s}"'",' ${server_conf} + sed -i '3i\ "name": "'"${name_s}"'",' ${server_conf} + sed -i '3i\ "password": "'"${password_s}"'",' ${server_conf} + sed -i '3i\ "username": "'"${username_s}"'",' ${server_conf} + sed -i '3i\ {' ${server_conf} echo -e "${Info} 添加节点成功 ${Green_font_prefix}[ 节点名称: ${name_s}, 节点用户名: ${username_s}, 节点密码: ${password_s} ]${Font_color_suffix} !" } @@ -610,7 +607,6 @@ Install_ServerStatus_server() { Install_caddy echo -e "${Info} 开始下载/安装..." Download_Server_Status_server - Install_jq echo -e "${Info} 开始下载/安装 服务脚本..." Service_Server_Status_server echo -e "${Info} 开始写入 配置文件..." @@ -645,7 +641,7 @@ Update_ServerStatus_server() { Update_ServerStatus_client() { check_installed_client_status service status-client stop - client_text="$(sed 's/\"//g;s/,//g;s/ //g' "${client_file}/client-linux.py") " + client_text="$(sed 's/\"//g;s/,//g;s/ //g' "${client_file}/client-linux.py")" server_s="$(echo -e "${client_text}" | grep "SERVER=" | awk -F "=" '{print $2;exit}')" server_port_s="$(echo -e "${client_text}" | grep "PORT=" | awk -F "=" '{print $2;exit}')" username_s="$(echo -e "${client_text}" | grep "USER=" | awk -F "=" '{print $2;exit}')" @@ -653,15 +649,21 @@ Update_ServerStatus_client() { Download_Server_Status_client Read_config_client Modify_config_client - rm -rf /usr/lib/systemd/system/status-client.service + rm -rf ${service}/status-client.service Service_Server_Status_client Start_ServerStatus_client } Start_ServerStatus_server() { + port="$(grep "m_Port = " ${server_file}/src/main.cpp | awk '{print $3}' | sed '{s/;$//}')" check_installed_server_status systemctl -q is-active status-server && echo -e "${Error} $NAME 正在运行,请检查 !" && exit 1 service status-server start + if (systemctl -q is-active status-server) then + echo -e "${Info} $NAME 服务端启动成功[监听端口:${port}] !" + else + echo -e "${Error} $NAME 服务端启动失败 !" + fi } Stop_ServerStatus_server() { @@ -672,11 +674,22 @@ if (systemctl -q is-active status-server) else echo -e "${Error} $NAME 没有运行,请检查 !" && exit 1 fi + if (systemctl -q is-active status-server) then + echo -e "${Error} $NAME 服务端停止失败 !" + else + echo -e "${Info} $NAME 服务端停止成功 !" + fi } Restart_ServerStatus_server() { check_installed_server_status - systemctl -q is-active status-client && service status-server stop + service status-server restart +if (systemctl -q is-active status-server) + then + echo -e "${Info} $NAME 服务端重启成功 !" +else + echo -e "${Error} $NAME 服务端重启失败 !" && exit 1 +fi } Uninstall_ServerStatus_server() { @@ -701,7 +714,7 @@ Uninstall_ServerStatus_server() { [[ ${release} == "centos" ]] && yum -y remove caddy [[ ${release} == "archlinux" ]] && pacman -R caddy --noconfirm fi - rm /usr/lib/systemd/system/status-server.service + rm ${service}/status-server.service systemctl daemon-reload echo && echo "ServerStatus 卸载完成 !" && echo else @@ -710,43 +723,39 @@ Uninstall_ServerStatus_server() { } Start_ServerStatus_client() { -NAME="ServerStatus Client" check_installed_client_status -if (systemctl -q is-active status-client) - then - echo -e "${Error} $NAME 正在运行,请检查 !" && exit 1 +if (systemctl -q is-active status-client) then + echo -e "${Error} $NAME 客户端正在运行,请检查 !" && exit 1 fi service status-client start if (systemctl -q is-active status-client) then - echo -e "${Info} $NAME 启动成功 !" + echo -e "${Info} $NAME 客户端启动成功 !" else - echo -e "${Error} $NAME 启动失败 !" + echo -e "${Error} $NAME 客户端启动失败 !" fi } Stop_ServerStatus_client() { check_installed_client_status -if (systemctl -q is-active status-client) - then service status-client stop - if (systemctl -q is-active status-client) - then +if (systemctl -q is-active status-client) then + service status-client stop + if (systemctl -q is-active status-client) then echo -e "${Error}} $NAME 停止失败 !" - else + else echo -e "${Info} $NAME 停止成功 !" fi - else +else echo -e "${Error} $NAME 没有运行,请检查 !" && exit 1 - fi +fi } Restart_ServerStatus_client() { check_installed_client_status service status-client restart -if (systemctl -q is-active status-client) - then +if (systemctl -q is-active status-client) then echo -e "${Info} $NAME 重启成功 !" - else +else echo -e "${Error} $NAME 重启失败 !" && exit 1 fi } @@ -766,7 +775,7 @@ Uninstall_ServerStatus_client() { fi systemctl stop status-client rm -rf "${client_file}" - rm /usr/lib/systemd/system/status-client.service + rm ${service}/status-client.service systemctl daemon-reload echo && echo "ServerStatus 卸载完成 !" && echo else @@ -803,12 +812,12 @@ View_server_Log() { Update_Shell() { sh_new_ver=$(wget --no-check-certificate -qO- -t1 -T3 "${github_prefix}/status.sh" | grep 'sh_ver="' | awk -F "=" '{print $NF}' | sed 's/\"//g' | head -1) [[ -z ${sh_new_ver} ]] && echo -e "${Error} 无法链接到 Github !" && exit 0 - if [[ -e "/usr/lib/systemd/system/status-client.service" ]]; then - rm -rf /usr/lib/systemd/system/status-client.service + if [[ -e "${service}/status-client.service" ]]; then + rm -rf ${service}/status-client.service Service_Server_Status_client fi - if [[ -e "/usr/lib/systemd/system/status-server.service" ]]; then - rm -rf /usr/lib/systemd/system/status-server.service + if [[ -e "${service}/status-server.service" ]]; then + rm -rf ${service}/status-server.service Service_Server_Status_server fi wget -N --no-check-certificate "${github_prefix}/status.sh" @@ -885,8 +894,7 @@ menu_client() { } menu_server() { echo && echo -e " $NAME 一键安装管理脚本 ${Red_font_prefix}[v${sh_ver}]${Font_color_suffix} - -- Toyo | doub.io/shell-jc3 -- - -- Modified by APTX -- + ${Green_font_prefix} 0.${Font_color_suffix} 升级脚本 ———————————— ${Green_font_prefix} 1.${Font_color_suffix} 安装 服务端 From f1559bfb55a9c8f7f8b5ef82787d672f8b530153 Mon Sep 17 00:00:00 2001 From: jwstaceyOvO <38880537+jwstaceyOvO@users.noreply.github.com> Date: Tue, 22 Feb 2022 17:00:13 +0800 Subject: [PATCH 19/23] Update status-server.service --- service/status-server.service | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/status-server.service b/service/status-server.service index 64d48ae..49bbdc1 100644 --- a/service/status-server.service +++ b/service/status-server.service @@ -2,7 +2,7 @@ Description=ServerStatus-Server After=network.target [Service] -ExecStart=/usr/local/ServerStatus/server/sergate --config=/usr/local/ServerStatus/server/config.json --web-dir=/usr/local/ServerStatus/web +ExecStart=/usr/local/ServerStatus/server/sergate --config=/usr/local/ServerStatus/server/config.json --web-dir=/usr/local/ServerStatus/web --port $PORT ExecReload=/bin/kill -HUP $MAINPID Restart=on-failure [Install] From 4c8006d1832bc82a04818c5d4e34691890c5b3ca Mon Sep 17 00:00:00 2001 From: jwstaceyOvO <38880537+jwstaceyOvO@users.noreply.github.com> Date: Tue, 22 Feb 2022 17:01:04 +0800 Subject: [PATCH 20/23] Add files via upload --- status.sh | 152 +++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 105 insertions(+), 47 deletions(-) diff --git a/status.sh b/status.sh index 0ab4487..f2c5b66 100644 --- a/status.sh +++ b/status.sh @@ -15,9 +15,9 @@ server_file="/usr/local/ServerStatus/server" server_conf="/usr/local/ServerStatus/server/config.json" plugin_file="/usr/local/ServerStatus/plugin" client_file="/usr/local/ServerStatus/clients" -client_log_file="/tmp/serverstatus_client.log" -server_log_file="/tmp/serverstatus_server.log" service="/usr/lib/systemd/system" +jq_file="${file}/jq" +[[ ! -e ${jq_file} ]] && jq_file="/usr/bin/jq" github_prefix="https://raw.githubusercontent.com/jwstaceyOvO/ServerStatus/master" @@ -27,6 +27,26 @@ Info="${Green_font_prefix}[信息]${Font_color_suffix}" Error="${Red_font_prefix}[错误]${Font_color_suffix}" Tip="${Green_font_prefix}[注意]${Font_color_suffix}" +#检查系统 +check_sys() { + if [[ -f /etc/redhat-release ]]; then + release="centos" + elif grep -q -E -i "debian|ubuntu" /etc/issue; then + release="debian" + elif grep -q -E -i "centos|red hat|redhat" /etc/issue; then + release="centos" + elif grep -q -E -i "Arch|Manjaro" /etc/issue; then + release="archlinux" + elif grep -q -E -i "debian|ubuntu" /proc/version; then + release="debian" + elif grep -q -E -i "centos|red hat|redhat" /proc/version; then + release="centos" + else + echo -e "ServerStatus 暂不支持该Linux发行版" + fi + bit=$(uname -m) +} + check_installed_server_status() { [[ ! -e "${server_file}/sergate" ]] && echo -e "${Error} $NAME 服务端没有安装,请检查 !" && exit 1 } @@ -93,12 +113,15 @@ Installation_dependency() { yum makecache yum -y install unzip yum -y install python3 >/dev/null 2>&1 || yum -y install python + [[ ${mode} == "server" ]] && yum -y groupinstall "Development Tools" elif [[ ${release} == "debian" ]]; then apt -y update apt -y install unzip apt -y install python3 >/dev/null 2>&1 || apt -y install python + [[ ${mode} == "server" ]] && apt -y install build-essential elif [[ ${release} == "archlinux" ]]; then pacman -Sy python python-pip unzip --noconfirm + [[ ${mode} == "server" ]] && pacman -Sy base-devel --noconfirm fi [[ ! -e /usr/bin/python ]] && ln -s /usr/bin/python3 /usr/bin/python } @@ -109,11 +132,11 @@ Write_server_config() { "servers": [ { "username": "s01", + "password": "password", "name": "vps-1", - "type": "kvm", - "host": "chengdu", - "location": "🇨🇳", - "password": "USER_DEFAULT_PASSWORD", + "type": "KVM", + "host": "azure", + "location": "Hong Kong", "monthstart": 1 } ] @@ -290,9 +313,8 @@ Set_ServerStatus_server() { ${Green_font_prefix} 5.${Font_color_suffix} 修改 节点配置 - 节点名称 ${Green_font_prefix} 6.${Font_color_suffix} 修改 节点配置 - 节点虚拟化 ${Green_font_prefix} 7.${Font_color_suffix} 修改 节点配置 - 节点位置 - ${Green_font_prefix} 8.${Font_color_suffix} 修改 节点配置 - 全部参数 -———————— - ${Green_font_prefix} 9.${Font_color_suffix} 启用/禁用 节点配置 + ${Green_font_prefix} 8.${Font_color_suffix} 修改 节点配置 - 月流量重置日 + ${Green_font_prefix} 9.${Font_color_suffix} 修改 节点配置 - 全部参数 ———————— ${Green_font_prefix}10.${Font_color_suffix} 修改 服务端监听端口" && echo read -erp "(默认: 取消):" server_num @@ -312,9 +334,9 @@ Set_ServerStatus_server() { elif [[ ${server_num} == "7" ]]; then Modify_ServerStatus_server_location elif [[ ${server_num} == "8" ]]; then - Modify_ServerStatus_server_all + Modify_ServerStatus_server_monthstart elif [[ ${server_num} == "9" ]]; then - Modify_ServerStatus_server_disabled + Modify_ServerStatus_server_all elif [[ ${server_num} == "10" ]]; then Read_config_server Set_server_port @@ -338,13 +360,13 @@ List_ServerStatus_server() { now_text_name=$(echo -e "${now_text}" | grep "name" | grep -v "username" | awk -F ": " '{print $2}') now_text_type=$(echo -e "${now_text}" | grep "type" | awk -F ": " '{print $2}') now_text_location=$(echo -e "${now_text}" | grep "location" | awk -F ": " '{print $2}') - now_text_disabled=$(echo -e "${now_text}" | grep "disabled" | awk -F ": " '{print $2}') + now_text_monthstart=$(echo -e "${now_text}" | grep "monthstart" | awk -F ": " '{print $2}') if [[ ${now_text_disabled} == "false" ]]; then now_text_disabled_status="${Green_font_prefix}启用${Font_color_suffix}" else now_text_disabled_status="${Red_font_prefix}禁用${Font_color_suffix}" fi - conf_list_all=${conf_list_all}"用户名: ${Green_font_prefix}${now_text_username}${Font_color_suffix} 密码: ${Green_font_prefix}${now_text_password}${Font_color_suffix} 节点名: ${Green_font_prefix}${now_text_name}${Font_color_suffix} 类型: ${Green_font_prefix}${now_text_type}${Font_color_suffix} 位置: ${Green_font_prefix}${now_text_location}${Font_color_suffix} 月流量重置日: ${Green_font_prefix}${now_text_monthstart}${Font_color_suffix} 状态: ${Green_font_prefix}${now_text_disabled_status}${Font_color_suffix}\n" + conf_list_all=${conf_list_all}"用户名: ${Green_font_prefix}${now_text_username}${Font_color_suffix} 密码: ${Green_font_prefix}${now_text_password}${Font_color_suffix} 节点名: ${Green_font_prefix}${now_text_name}${Font_color_suffix} 虚拟化: ${Green_font_prefix}${now_text_type}${Font_color_suffix} 位置: ${Green_font_prefix}${now_text_location}${Font_color_suffix} 月流量重置日: ${Green_font_prefix}${now_text_monthstart}${Font_color_suffix}\n" done echo && echo -e "节点总数 ${Green_font_prefix}${conf_text_total}${Font_color_suffix}" echo -e "${conf_list_all}" @@ -355,7 +377,7 @@ Add_ServerStatus_server() { Set_username_ch=$(grep '"username": "'"${username_s}"'"' ${server_conf}) [[ -n "${Set_username_ch}" ]] && echo -e "${Error} 用户名已被使用 !" && exit 1 sed -i '3i\ },' ${server_conf} - sed -i '3i\ "monthstart": "'"${monthstart_s}"'",' ${server_conf} + sed -i '3i\ "monthstart": '"${monthstart_s}"'' ${server_conf} sed -i '3i\ "location": "'"${location_s}"'",' ${server_conf} sed -i '3i\ "host": "'"None"'",' ${server_conf} sed -i '3i\ "type": "'"${type_s}"'",' ${server_conf} @@ -375,7 +397,7 @@ Del_ServerStatus_server() { del_username=$(cat -n ${server_conf} | grep '"username": "'"${del_server_username}"'"' | awk '{print $1}') if [[ -n ${del_username} ]]; then del_username_min=$((del_username - 1)) - del_username_max=$((del_username + 8)) + del_username_max=$((del_username + 7)) del_username_max_text=$(sed -n "${del_username_max}p" ${server_conf}) del_username_max_text_last=${del_username_max_text:((${#del_username_max_text} - 1))} if [[ ${del_username_max_text_last} != "," ]]; then @@ -482,9 +504,9 @@ Modify_ServerStatus_server_monthstart() { Set_username_num=$(cat -n ${server_conf} | grep '"username": "'"${manually_username}"'"' | awk '{print $1}') if [[ -n ${Set_username_num} ]]; then Set_monthstart - Set_monthstart_num_a=$((Set_username_num + 1)) + Set_monthstart_num_a=$((Set_username_num + 6)) Set_monthstart_num_text=$(sed -n "${Set_monthstart_num_a}p" ${server_conf} | sed 's/\"//g;s/,$//g' | awk -F ": " '{print $2}') - sed -i "${Set_monthstart_num_a}"'s/"monthstart": "'"${Set_monthstart_num_text}"'"/"monthstart": "'"${monthstart_s}"'"/g' ${server_conf} + sed -i "${Set_monthstart_num_a}"'s/"monthstart": '"${Set_monthstart_num_text}"'/"monthstart": '"${monthstart_s}"'/g' ${server_conf} echo -e "${Info} 修改成功 [ 原月流量重置日: ${Set_monthstart_num_text}, 新月流量重置日: ${monthstart_s} ]" else echo -e "${Error} 请输入正确的节点用户名 !" && exit 1 @@ -517,9 +539,9 @@ Modify_ServerStatus_server_all() { Set_location_num_a=$((Set_username_num + 5)) Set_location_num_a_text=$(sed -n "${Set_location_num_a}p" ${server_conf} | sed 's/\"//g;s/,$//g' | awk -F ": " '{print $2}') sed -i "${Set_location_num_a}"'s/"location": "'"${Set_location_num_a_text}"'"/"location": "'"${location_s}"'"/g' ${server_conf} - Set_monthstart_num_a=$((Set_username_num + 7)) + Set_monthstart_num_a=$((Set_username_num + 6)) Set_monthstart_num_a_text=$(sed -n "${Set_monthstart_num_a}p" ${server_conf} | sed 's/\"//g;s/,$//g' | awk -F ": " '{print $2}') - sed -i "${Set_monthstart_num_a}"'s/"monthstart": "'"${Set_monthstart_num_a_text}"'"/"monthstart": "'"${monthstart_s}"'"/g' ${server_conf} + sed -i "${Set_monthstart_num_a}"'s/"monthstart": '"${Set_monthstart_num_a_text}"'/"monthstart": '"${monthstart_s}"'/g' ${server_conf} echo -e "${Info} 修改成功。" else echo -e "${Error} 请输入正确的节点用户名 !" && exit 1 @@ -562,6 +584,36 @@ Modify_config_client() { sed -i '0,/PASSWORD = "'"${client_password}"'"/s//PASSWORD = "'"${password_s}"'"/' "${client_file}/client-linux.py" } +Install_jq() { + [[ ${mirror_num} == 2 ]] && { + github_link="https://hub.fastgit.org" + raw_link="https://raw.fastgit.org" + } || { + github_link="https://github.com" + raw_link="https://raw.githubusercontent.com" + } + if [[ ! -e ${jq_file} ]]; then + if [[ ${bit} == "x86_64" ]]; then + jq_file="${file}/jq" + wget --no-check-certificate "${github_link}/stedolan/jq/releases/download/jq-1.5/jq-linux64" -O ${jq_file} + elif [[ ${bit} == "i386" ]]; then + jq_file="${file}/jq" + wget --no-check-certificate "${github_link}/stedolan/jq/releases/download/jq-1.5/jq-linux32" -O ${jq_file} + else + # ARM fallback to package manager + [[ ${release} == "archlinux" ]] && pacman -Sy jq --noconfirm + [[ ${release} == "centos" ]] && yum -y install jq + [[ ${release} == "debian" ]] && apt -y install jq + jq_file="/usr/bin/jq" + fi + [[ ! -e ${jq_file} ]] && echo -e "${Error} JQ解析器 下载失败,请检查 !" && exit 1 + chmod +x ${jq_file} + echo -e "${Info} JQ解析器 安装完成,继续..." + else + echo -e "${Info} JQ解析器 已安装,继续..." + fi +} + Install_caddy() { echo echo -e "${Info} 是否由脚本自动配置HTTP服务(服务端的在线监控网站),如果选择 N,则请在其他HTTP服务中配置网站根目录为:${Green_font_prefix}${web_file}${Font_color_suffix} [Y/n]" @@ -604,9 +656,12 @@ EOF Install_ServerStatus_server() { [[ -e "${server_file}/sergate" ]] && echo -e "${Error} 检测到 $NAME 服务端已安装 !" && exit 1 Set_server_port + echo -e "${Info} 开始安装/配置 依赖..." + Installation_dependency "server" Install_caddy echo -e "${Info} 开始下载/安装..." Download_Server_Status_server +Install_jq echo -e "${Info} 开始下载/安装 服务脚本..." Service_Server_Status_server echo -e "${Info} 开始写入 配置文件..." @@ -617,11 +672,14 @@ Install_ServerStatus_server() { Install_ServerStatus_client() { [[ -e "${client_file}/client-linux.py" ]] && echo -e "${Error} 检测到 $NAME 客户端已安装 !" && exit 1 + check_sys echo -e "${Info} 开始设置 用户配置..." Set_config_client + echo -e "${Info} 开始安装/配置 依赖..." + Installation_dependency "client" echo -e "${Info} 开始下载/安装..." Download_Server_Status_client - echo -e "${Info} 开始下载/安装 服务脚本(init)..." + echo -e "${Info} 开始下载/安装 服务脚本..." Service_Server_Status_client echo -e "${Info} 开始写入 配置..." Read_config_client @@ -640,7 +698,7 @@ Update_ServerStatus_server() { Update_ServerStatus_client() { check_installed_client_status - service status-client stop + systemctl stop status-client client_text="$(sed 's/\"//g;s/,//g;s/ //g' "${client_file}/client-linux.py")" server_s="$(echo -e "${client_text}" | grep "SERVER=" | awk -F "=" '{print $2;exit}')" server_port_s="$(echo -e "${client_text}" | grep "PORT=" | awk -F "=" '{print $2;exit}')" @@ -658,7 +716,7 @@ Start_ServerStatus_server() { port="$(grep "m_Port = " ${server_file}/src/main.cpp | awk '{print $3}' | sed '{s/;$//}')" check_installed_server_status systemctl -q is-active status-server && echo -e "${Error} $NAME 正在运行,请检查 !" && exit 1 - service status-server start + systemctl start status-server if (systemctl -q is-active status-server) then echo -e "${Info} $NAME 服务端启动成功[监听端口:${port}] !" else @@ -670,7 +728,7 @@ Stop_ServerStatus_server() { check_installed_server_status if (systemctl -q is-active status-server) then - service status-server stop + systemctl stop status-server else echo -e "${Error} $NAME 没有运行,请检查 !" && exit 1 fi @@ -683,7 +741,7 @@ fi Restart_ServerStatus_server() { check_installed_server_status - service status-server restart + systemctl restart status-server if (systemctl -q is-active status-server) then echo -e "${Info} $NAME 服务端重启成功 !" @@ -699,11 +757,13 @@ Uninstall_ServerStatus_server() { read -erp "(默认: n):" unyn [[ -z ${unyn} ]] && unyn="n" if [[ ${unyn} == [Yy] ]]; then - service status-server stop - systemctl disable status-server + systemctl stop status-server + systemctl disable status-server + rm ${service}/status-server.service -f if [[ -e "${client_file}/client-linux.py" ]]; then rm -rf "${server_file}" rm -rf "${web_file}" + rm -rf "${plugin_file}" else rm -rf "${file}" fi @@ -714,8 +774,8 @@ Uninstall_ServerStatus_server() { [[ ${release} == "centos" ]] && yum -y remove caddy [[ ${release} == "archlinux" ]] && pacman -R caddy --noconfirm fi - rm ${service}/status-server.service - systemctl daemon-reload + systemctl daemon-reload + systemctl reset-failed echo && echo "ServerStatus 卸载完成 !" && echo else echo && echo "卸载已取消..." && echo @@ -727,7 +787,7 @@ Start_ServerStatus_client() { if (systemctl -q is-active status-client) then echo -e "${Error} $NAME 客户端正在运行,请检查 !" && exit 1 fi - service status-client start + systemctl start status-client if (systemctl -q is-active status-client) then echo -e "${Info} $NAME 客户端启动成功 !" @@ -739,7 +799,7 @@ fi Stop_ServerStatus_client() { check_installed_client_status if (systemctl -q is-active status-client) then - service status-client stop + systemctl stop status-client if (systemctl -q is-active status-client) then echo -e "${Error}} $NAME 停止失败 !" else @@ -751,8 +811,7 @@ fi } Restart_ServerStatus_client() { - check_installed_client_status - service status-client restart + systemctl restart status-client if (systemctl -q is-active status-client) then echo -e "${Info} $NAME 重启成功 !" else @@ -767,16 +826,12 @@ Uninstall_ServerStatus_client() { read -erp "(默认: n):" unyn [[ -z ${unyn} ]] && unyn="n" if [[ ${unyn} == [Yy] ]]; then - service status-client stop + systemctl stop status-client systemctl disable status-client - Read_config_client - if [[ -e "${server_file}/sergate" ]]; then - rm -rf "${client_file}" - fi - systemctl stop status-client - rm -rf "${client_file}" - rm ${service}/status-client.service - systemctl daemon-reload + rm ${service}/status-client.service -f + systemctl daemon-reload + systemctl reset-failed + rm -rf "${client_file}" echo && echo "ServerStatus 卸载完成 !" && echo else echo && echo "卸载已取消..." && echo @@ -798,15 +853,17 @@ View_ServerStatus_client() { } View_client_Log() { - [[ ! -e ${client_log_file} ]] && echo -e "${Error} 没有找到日志文件 !" && exit 1 - echo && echo -e "${Tip} 按 ${Red_font_prefix}Ctrl+C${Font_color_suffix} 终止查看日志" && echo -e "如果需要查看完整日志内容,请用 ${Red_font_prefix}cat ${client_log_file}${Font_color_suffix} 命令。" && echo - tail -f ${client_log_file} + journalctl -u status-client.service --no-pager -f + if [[ $# == 0 ]]; then + before_show_menu + fi } View_server_Log() { - [[ ! -e ${server_log_file} ]] && echo -e "${Error} 没有找到日志文件 !" && exit 1 - echo && echo -e "${Tip} 按 ${Red_font_prefix}Ctrl+C${Font_color_suffix} 终止查看日志" && echo -e "如果需要查看完整日志内容,请用 ${Red_font_prefix}cat ${server_log_file}${Font_color_suffix} 命令。" && echo - tail -f ${server_log_file} + journalctl -u status-server.service --no-pager -f + if [[ $# == 0 ]]; then + before_show_menu + fi } Update_Shell() { @@ -961,6 +1018,7 @@ menu_server() { esac } +check_sys action=$1 if [[ -n $action ]]; then if [[ $action == "s" ]]; then From be95052d8f1a548761833dcf0ee7e5379959b608 Mon Sep 17 00:00:00 2001 From: jwstaceyOvO <38880537+jwstaceyOvO@users.noreply.github.com> Date: Tue, 22 Feb 2022 17:38:41 +0800 Subject: [PATCH 21/23] Update status-server.service --- service/status-server.service | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/status-server.service b/service/status-server.service index 49bbdc1..64d48ae 100644 --- a/service/status-server.service +++ b/service/status-server.service @@ -2,7 +2,7 @@ Description=ServerStatus-Server After=network.target [Service] -ExecStart=/usr/local/ServerStatus/server/sergate --config=/usr/local/ServerStatus/server/config.json --web-dir=/usr/local/ServerStatus/web --port $PORT +ExecStart=/usr/local/ServerStatus/server/sergate --config=/usr/local/ServerStatus/server/config.json --web-dir=/usr/local/ServerStatus/web ExecReload=/bin/kill -HUP $MAINPID Restart=on-failure [Install] From e8482bf8acf656f1d949019e6112014e0199f777 Mon Sep 17 00:00:00 2001 From: jwstaceyOvO <38880537+jwstaceyOvO@users.noreply.github.com> Date: Tue, 22 Feb 2022 17:39:14 +0800 Subject: [PATCH 22/23] Add files via upload --- status.sh | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/status.sh b/status.sh index f2c5b66..ea11e4b 100644 --- a/status.sh +++ b/status.sh @@ -13,6 +13,7 @@ file="/usr/local/ServerStatus" web_file="/usr/local/ServerStatus/web" server_file="/usr/local/ServerStatus/server" server_conf="/usr/local/ServerStatus/server/config.json" +server_conf_1="/usr/local/ServerStatus/server/config.conf" plugin_file="/usr/local/ServerStatus/plugin" client_file="/usr/local/ServerStatus/clients" service="/usr/lib/systemd/system" @@ -33,7 +34,7 @@ check_sys() { release="centos" elif grep -q -E -i "debian|ubuntu" /etc/issue; then release="debian" - elif grep -q -E -i "centos|red hat|redhat" /etc/issue; then + elif grep -q -E -i "centonetstat -tunlps|red hat|redhat" /etc/issue; then release="centos" elif grep -q -E -i "Arch|Manjaro" /etc/issue; then release="archlinux" @@ -145,7 +146,9 @@ EOF } Write_server_config_conf() { - sed -i "s/m_Port = ${server_port}/m_Port = ${server_port_s}/g" "${server_file}/src/main.cpp" + cat >${server_conf_1} <<-EOF +PORT = ${server_port_s} +EOF } Read_config_client() { @@ -157,7 +160,13 @@ Read_config_client() { } Read_config_server() { - server_port="$(grep "m_Port = " ${server_file}/src/main.cpp | awk '{print $3}' | sed '{s/;$//}')" + if [[ ! -e "${server_conf_1}" ]]; then + server_port_s="35601" + Write_server_config_conf + server_port="35601" + else + server_port="$(grep "PORT = " ${server_conf_1} | awk '{print $3}')" + fi } Set_server() { @@ -666,6 +675,7 @@ Install_jq Service_Server_Status_server echo -e "${Info} 开始写入 配置文件..." Write_server_config + Write_server_config_conf echo -e "${Info} 所有步骤 安装完毕,开始启动..." Start_ServerStatus_server } From 22847aa5900cfbdebd51acd7384a0cc956e7ae30 Mon Sep 17 00:00:00 2001 From: cppla <10623809+cppla@users.noreply.github.com> Date: Wed, 23 Feb 2022 15:41:08 +0800 Subject: [PATCH 23/23] Update status.sh auto install bash. --- status.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/status.sh b/status.sh index ea11e4b..ba64046 100644 --- a/status.sh +++ b/status.sh @@ -20,7 +20,7 @@ service="/usr/lib/systemd/system" jq_file="${file}/jq" [[ ! -e ${jq_file} ]] && jq_file="/usr/bin/jq" -github_prefix="https://raw.githubusercontent.com/jwstaceyOvO/ServerStatus/master" +github_prefix="https://raw.githubusercontent.com/cppla/ServerStatus/master" NAME="ServerStatus" Green_font_prefix="\033[32m" && Red_font_prefix="\033[31m" && Red_background_prefix="\033[41;37m" && Font_color_suffix="\033[0m" @@ -251,8 +251,8 @@ Set_password() { else echo -e "请输入 $NAME 服务端中对应配置的密码[password](字母/数字)" fi - read -erp "(默认: doub.io):" password_s - [[ -z "$password_s" ]] && password_s="doub.io" + read -erp "(默认: serverstatus):" password_s + [[ -z "$password_s" ]] && password_s="serverstatus" echo && echo " ================================================" echo -e " 密码[password]: ${Red_background_prefix} ${password_s} ${Font_color_suffix}" echo " ================================================" && echo