status.sh 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041
  1. #!/usr/bin/env bash
  2. PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
  3. export PATH
  4. sh_ver="1.0.0"
  5. filepath=$(
  6. cd "$(dirname "$0")" || exit
  7. pwd
  8. )
  9. file_1=$(echo -e "${filepath}" | awk -F "$0" '{print $1}')
  10. file="/usr/local/ServerStatus"
  11. web_file="/usr/local/ServerStatus/web"
  12. server_file="/usr/local/ServerStatus/server"
  13. server_conf="/usr/local/ServerStatus/server/config.json"
  14. server_conf_1="/usr/local/ServerStatus/server/config.conf"
  15. plugin_file="/usr/local/ServerStatus/plugin"
  16. client_file="/usr/local/ServerStatus/clients"
  17. service="/usr/lib/systemd/system"
  18. jq_file="${file}/jq"
  19. [[ ! -e ${jq_file} ]] && jq_file="/usr/bin/jq"
  20. github_prefix="https://raw.githubusercontent.com/cppla/ServerStatus/master"
  21. NAME="ServerStatus"
  22. Green_font_prefix="\033[32m" && Red_font_prefix="\033[31m" && Red_background_prefix="\033[41;37m" && Font_color_suffix="\033[0m"
  23. Info="${Green_font_prefix}[信息]${Font_color_suffix}"
  24. Error="${Red_font_prefix}[错误]${Font_color_suffix}"
  25. Tip="${Green_font_prefix}[注意]${Font_color_suffix}"
  26. #检查系统
  27. check_sys() {
  28. if [[ -f /etc/redhat-release ]]; then
  29. release="centos"
  30. elif grep -q -E -i "debian|ubuntu" /etc/issue; then
  31. release="debian"
  32. elif grep -q -E -i "centonetstat -tunlps|red hat|redhat" /etc/issue; then
  33. release="centos"
  34. elif grep -q -E -i "Arch|Manjaro" /etc/issue; then
  35. release="archlinux"
  36. elif grep -q -E -i "debian|ubuntu" /proc/version; then
  37. release="debian"
  38. elif grep -q -E -i "centos|red hat|redhat" /proc/version; then
  39. release="centos"
  40. else
  41. echo -e "ServerStatus 暂不支持该Linux发行版"
  42. fi
  43. bit=$(uname -m)
  44. }
  45. check_installed_server_status() {
  46. [[ ! -e "${server_file}/sergate" ]] && echo -e "${Error} $NAME 服务端没有安装,请检查 !" && exit 1
  47. }
  48. check_installed_client_status() {
  49. [[ ! -e "${client_file}/client-linux.py" ]] && echo -e "${Error} $NAME 客户端没有安装,请检查 !" && exit 1
  50. }
  51. Download_Server_Status_server() {
  52. cd "/tmp" || exit 1
  53. wget -N --no-check-certificate https://github.com/cppla/ServerStatus/archive/refs/heads/master.zip
  54. [[ ! -e "master.zip" ]] && echo -e "${Error} ServerStatus 服务端下载失败 !" && exit 1
  55. unzip master.zip
  56. rm -rf master.zip
  57. [[ ! -d "/tmp/ServerStatus-master" ]] && echo -e "${Error} ServerStatus 服务端解压失败 !" && exit 1
  58. cd "/tmp/ServerStatus-master/server" || exit 1
  59. make
  60. [[ ! -e "sergate" ]] && echo -e "${Error} ServerStatus 服务端编译失败 !" && cd "${file_1}" && rm -rf "/tmp//ServerStatus-master" && exit 1
  61. cd "${file_1}" || exit 1
  62. mkdir -p "${server_file}"
  63. mv "/tmp/ServerStatus-master/server" "${file}"
  64. mv "/tmp/ServerStatus-master/web" "${file}"
  65. mv "/tmp/ServerStatus-master/plugin" "${file}"
  66. rm -rf "/tmp/ServerStatus-master"
  67. if [[ ! -e "${server_file}/sergate" ]]; then
  68. echo -e "${Error} ServerStatus 服务端移动重命名失败 !"
  69. [[ -e "${server_file}/sergate1" ]] && mv "${server_file}/sergate1" "${server_file}/sergate"
  70. exit 1
  71. else
  72. [[ -e "${server_file}/sergate1" ]] && rm -rf "${server_file}/sergate1"
  73. fi
  74. }
  75. Download_Server_Status_client() {
  76. mkdir -p "${client_file}"
  77. wget -N --no-check-certificate "${github_prefix}/clients/client-linux.py" -P "${client_file}"
  78. }
  79. Download_Server_Status_Service() {
  80. mode=$1
  81. [[ -z ${mode} ]] && mode="server"
  82. local service_note="服务端"
  83. [[ ${mode} == "client" ]] && service_note="客户端"
  84. wget --no-check-certificate "${github_prefix}/service/status-${mode}.service" -O "${service}/status-${mode}.service" ||
  85. {
  86. echo -e "${Error} $NAME ${service_note}服务管理脚本下载失败 !"
  87. exit 1
  88. }
  89. systemctl enable "status-${mode}.service"
  90. echo -e "${Info} $NAME ${service_note}服务管理脚本下载完成 !"
  91. }
  92. Service_Server_Status_server() {
  93. Download_Server_Status_Service "server"
  94. }
  95. Service_Server_Status_client() {
  96. Download_Server_Status_Service "client"
  97. }
  98. Installation_dependency() {
  99. mode=$1
  100. if [[ ${release} == "centos" ]]; then
  101. yum makecache
  102. yum -y install unzip
  103. yum -y install python3 >/dev/null 2>&1 || yum -y install python
  104. [[ ${mode} == "server" ]] && yum -y groupinstall "Development Tools"
  105. elif [[ ${release} == "debian" ]]; then
  106. apt -y update
  107. apt -y install unzip
  108. apt -y install python3 >/dev/null 2>&1 || apt -y install python
  109. [[ ${mode} == "server" ]] && apt -y install build-essential
  110. elif [[ ${release} == "archlinux" ]]; then
  111. pacman -Sy python python-pip unzip --noconfirm
  112. [[ ${mode} == "server" ]] && pacman -Sy base-devel --noconfirm
  113. fi
  114. [[ ! -e /usr/bin/python ]] && ln -s /usr/bin/python3 /usr/bin/python
  115. }
  116. Write_server_config() {
  117. cat >${server_conf} <<-EOF
  118. {
  119. "servers": [
  120. {
  121. "username": "s01",
  122. "password": "password",
  123. "name": "vps-1",
  124. "type": "KVM",
  125. "host": "azure",
  126. "location": "Hong Kong",
  127. "monthstart": 1
  128. }
  129. ]
  130. }
  131. EOF
  132. }
  133. Write_server_config_conf() {
  134. cat >${server_conf_1} <<-EOF
  135. PORT = ${server_port_s}
  136. EOF
  137. }
  138. Read_config_client() {
  139. client_text="$(sed 's/\"//g;s/,//g;s/ //g' "${client_file}/client-linux.py") "
  140. client_server="$(echo -e "${client_text}" | grep "SERVER=" | awk -F "=" '{print $2;exit}')"
  141. client_port="$(echo -e "${client_text}" | grep "PORT=" | awk -F "=" '{print $2;exit}')"
  142. client_user="$(echo -e "${client_text}" | grep "USER=" | awk -F "=" '{print $2;exit}')"
  143. client_password="$(echo -e "${client_text}" | grep "PASSWORD=" | awk -F "=" '{print $2;exit}')"
  144. }
  145. Read_config_server() {
  146. if [[ ! -e "${server_conf_1}" ]]; then
  147. server_port_s="35601"
  148. Write_server_config_conf
  149. server_port="35601"
  150. else
  151. server_port="$(grep "PORT = " ${server_conf_1} | awk '{print $3}')"
  152. fi
  153. }
  154. Set_server() {
  155. mode=$1
  156. [[ -z ${mode} ]] && mode="server"
  157. if [[ ${mode} == "server" ]]; then
  158. echo -e "请输入 $NAME 服务端中网站要设置的 域名[server]
  159. 默认为本机IP为域名,例如输入: toyoo.pw ,如果要使用本机IP,请留空直接回车"
  160. read -erp "(默认: 本机IP):" server_s
  161. [[ -z "$server_s" ]] && server_s=""
  162. else
  163. echo -e "请输入 $NAME 服务端的 IP/域名[server],请注意,如果你的域名使用了CDN,请直接填写IP"
  164. read -erp "(默认: 127.0.0.1):" server_s
  165. [[ -z "$server_s" ]] && server_s="127.0.0.1"
  166. fi
  167. echo && echo " ================================================"
  168. echo -e " IP/域名[server]: ${Red_background_prefix} ${server_s} ${Font_color_suffix}"
  169. echo " ================================================" && echo
  170. }
  171. Set_server_http_port() {
  172. while true; do
  173. echo -e "请输入 $NAME 服务端中网站要设置的 域名/IP的端口[1-65535](如果是域名的话,一般用 80 端口)"
  174. read -erp "(默认: 8888):" server_http_port_s
  175. [[ -z "$server_http_port_s" ]] && server_http_port_s="8888"
  176. if [[ "$server_http_port_s" =~ ^[0-9]*$ ]]; then
  177. if [[ ${server_http_port_s} -ge 1 ]] && [[ ${server_http_port_s} -le 65535 ]]; then
  178. echo && echo " ================================================"
  179. echo -e " 端口: ${Red_background_prefix} ${server_http_port_s} ${Font_color_suffix}"
  180. echo " ================================================" && echo
  181. break
  182. else
  183. echo "输入错误, 请输入正确的端口。"
  184. fi
  185. else
  186. echo "输入错误, 请输入正确的端口。"
  187. fi
  188. done
  189. }
  190. Set_server_port() {
  191. while true; do
  192. echo -e "请输入 $NAME 服务端监听的端口[1-65535](用于服务端接收客户端消息的端口,客户端要填写这个端口)"
  193. read -erp "(默认: 35601):" server_port_s
  194. [[ -z "$server_port_s" ]] && server_port_s="35601"
  195. if [[ "$server_port_s" =~ ^[0-9]*$ ]]; then
  196. if [[ ${server_port_s} -ge 1 ]] && [[ ${server_port_s} -le 65535 ]]; then
  197. echo && echo " ================================================"
  198. echo -e " 端口: ${Red_background_prefix} ${server_port_s} ${Font_color_suffix}"
  199. echo " ================================================" && echo
  200. break
  201. else
  202. echo "输入错误, 请输入正确的端口。"
  203. fi
  204. else
  205. echo "输入错误, 请输入正确的端口。"
  206. fi
  207. done
  208. }
  209. Set_username() {
  210. mode=$1
  211. [[ -z ${mode} ]] && mode="server"
  212. if [[ ${mode} == "server" ]]; then
  213. echo -e "请输入 $NAME 服务端要设置的用户名[username](字母/数字,不可与其他账号重复)"
  214. else
  215. echo -e "请输入 $NAME 服务端中对应配置的用户名[username](字母/数字,不可与其他账号重复)"
  216. fi
  217. read -erp "(默认: 取消):" username_s
  218. [[ -z "$username_s" ]] && echo "已取消..." && exit 0
  219. echo && echo " ================================================"
  220. echo -e " 账号[username]: ${Red_background_prefix} ${username_s} ${Font_color_suffix}"
  221. echo " ================================================" && echo
  222. }
  223. Set_password() {
  224. mode=$1
  225. [[ -z ${mode} ]] && mode="server"
  226. if [[ ${mode} == "server" ]]; then
  227. echo -e "请输入 $NAME 服务端要设置的密码[password](字母/数字,可重复)"
  228. else
  229. echo -e "请输入 $NAME 服务端中对应配置的密码[password](字母/数字)"
  230. fi
  231. read -erp "(默认: serverstatus):" password_s
  232. [[ -z "$password_s" ]] && password_s="serverstatus"
  233. echo && echo " ================================================"
  234. echo -e " 密码[password]: ${Red_background_prefix} ${password_s} ${Font_color_suffix}"
  235. echo " ================================================" && echo
  236. }
  237. Set_name() {
  238. echo -e "请输入 $NAME 服务端要设置的节点名称[name](支持中文,前提是你的系统和SSH工具支持中文输入,仅仅是个名字)"
  239. read -erp "(默认: Server 01):" name_s
  240. [[ -z "$name_s" ]] && name_s="Server 01"
  241. echo && echo " ================================================"
  242. echo -e " 节点名称[name]: ${Red_background_prefix} ${name_s} ${Font_color_suffix}"
  243. echo " ================================================" && echo
  244. }
  245. Set_type() {
  246. echo -e "请输入 $NAME 服务端要设置的节点虚拟化类型[type](例如 OpenVZ / KVM)"
  247. read -erp "(默认: KVM):" type_s
  248. [[ -z "$type_s" ]] && type_s="KVM"
  249. echo && echo " ================================================"
  250. echo -e " 虚拟化类型[type]: ${Red_background_prefix} ${type_s} ${Font_color_suffix}"
  251. echo " ================================================" && echo
  252. }
  253. Set_location() {
  254. echo -e "请输入 $NAME 服务端要设置的节点位置[location](支持中文,前提是你的系统和SSH工具支持中文输入)"
  255. read -erp "(默认: Hong Kong):" location_s
  256. [[ -z "$location_s" ]] && location_s="Hong Kong"
  257. echo && echo " ================================================"
  258. echo -e " 节点位置[location]: ${Red_background_prefix} ${location_s} ${Font_color_suffix}"
  259. echo " ================================================" && echo
  260. }
  261. Set_monthstart() {
  262. echo -e "请输入 $NAME 服务端要设置的节点月重置流量日[monthstart](每月流量归零的日期(1~28),默认为1(即每月1日))"
  263. read -erp "(默认: 1):" monthstart_s
  264. [[ -z "$monthstart_s" ]] && monthstart_s="1"
  265. echo && echo " ================================================"
  266. echo -e " 月流量重置日[monthstart]: ${Red_background_prefix} ${monthstart_s} ${Font_color_suffix}"
  267. echo " ================================================" && echo
  268. }
  269. Set_config_server() {
  270. Set_username "server"
  271. Set_password "server"
  272. Set_name
  273. Set_type
  274. Set_location
  275. Set_monthstart
  276. }
  277. Set_config_client() {
  278. Set_server "client"
  279. Set_server_port
  280. Set_username "client"
  281. Set_password "client"
  282. }
  283. Set_ServerStatus_server() {
  284. check_installed_server_status
  285. echo && echo -e " 你要做什么?
  286. ${Green_font_prefix} 1.${Font_color_suffix} 添加 节点配置
  287. ${Green_font_prefix} 2.${Font_color_suffix} 删除 节点配置
  288. ————————
  289. ${Green_font_prefix} 3.${Font_color_suffix} 修改 节点配置 - 节点用户名
  290. ${Green_font_prefix} 4.${Font_color_suffix} 修改 节点配置 - 节点密码
  291. ${Green_font_prefix} 5.${Font_color_suffix} 修改 节点配置 - 节点名称
  292. ${Green_font_prefix} 6.${Font_color_suffix} 修改 节点配置 - 节点虚拟化
  293. ${Green_font_prefix} 7.${Font_color_suffix} 修改 节点配置 - 节点位置
  294. ${Green_font_prefix} 8.${Font_color_suffix} 修改 节点配置 - 月流量重置日
  295. ${Green_font_prefix} 9.${Font_color_suffix} 修改 节点配置 - 全部参数
  296. ————————
  297. ${Green_font_prefix}10.${Font_color_suffix} 修改 服务端监听端口" && echo
  298. read -erp "(默认: 取消):" server_num
  299. [[ -z "${server_num}" ]] && echo "已取消..." && exit 1
  300. if [[ ${server_num} == "1" ]]; then
  301. Add_ServerStatus_server
  302. elif [[ ${server_num} == "2" ]]; then
  303. Del_ServerStatus_server
  304. elif [[ ${server_num} == "3" ]]; then
  305. Modify_ServerStatus_server_username
  306. elif [[ ${server_num} == "4" ]]; then
  307. Modify_ServerStatus_server_password
  308. elif [[ ${server_num} == "5" ]]; then
  309. Modify_ServerStatus_server_name
  310. elif [[ ${server_num} == "6" ]]; then
  311. Modify_ServerStatus_server_type
  312. elif [[ ${server_num} == "7" ]]; then
  313. Modify_ServerStatus_server_location
  314. elif [[ ${server_num} == "8" ]]; then
  315. Modify_ServerStatus_server_monthstart
  316. elif [[ ${server_num} == "9" ]]; then
  317. Modify_ServerStatus_server_all
  318. elif [[ ${server_num} == "10" ]]; then
  319. Read_config_server
  320. Set_server_port
  321. Write_server_config_conf
  322. else
  323. echo -e "${Error} 请输入正确的数字[1-10]" && exit 1
  324. fi
  325. Restart_ServerStatus_server
  326. }
  327. List_ServerStatus_server() {
  328. conf_text=$(${jq_file} '.servers' ${server_conf} | ${jq_file} ".[]|.username" | sed 's/\"//g')
  329. conf_text_total=$(echo -e "${conf_text}" | wc -l)
  330. [[ ${conf_text_total} == "0" ]] && echo -e "${Error} 没有发现 一个节点配置,请检查 !" && exit 1
  331. conf_text_total_a=$((conf_text_total - 1))
  332. conf_list_all=""
  333. for ((integer = 0; integer <= conf_text_total_a; integer++)); do
  334. now_text=$(${jq_file} '.servers' ${server_conf} | ${jq_file} ".[${integer}]" | sed 's/\"//g;s/,$//g' | sed '$d;1d')
  335. now_text_username=$(echo -e "${now_text}" | grep "username" | awk -F ": " '{print $2}')
  336. now_text_password=$(echo -e "${now_text}" | grep "password" | awk -F ": " '{print $2}')
  337. now_text_name=$(echo -e "${now_text}" | grep "name" | grep -v "username" | awk -F ": " '{print $2}')
  338. now_text_type=$(echo -e "${now_text}" | grep "type" | awk -F ": " '{print $2}')
  339. now_text_location=$(echo -e "${now_text}" | grep "location" | awk -F ": " '{print $2}')
  340. now_text_monthstart=$(echo -e "${now_text}" | grep "monthstart" | awk -F ": " '{print $2}')
  341. if [[ ${now_text_disabled} == "false" ]]; then
  342. now_text_disabled_status="${Green_font_prefix}启用${Font_color_suffix}"
  343. else
  344. now_text_disabled_status="${Red_font_prefix}禁用${Font_color_suffix}"
  345. fi
  346. 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"
  347. done
  348. echo && echo -e "节点总数 ${Green_font_prefix}${conf_text_total}${Font_color_suffix}"
  349. echo -e "${conf_list_all}"
  350. }
  351. Add_ServerStatus_server() {
  352. Set_config_server
  353. Set_username_ch=$(grep '"username": "'"${username_s}"'"' ${server_conf})
  354. [[ -n "${Set_username_ch}" ]] && echo -e "${Error} 用户名已被使用 !" && exit 1
  355. sed -i '3i\ },' ${server_conf}
  356. sed -i '3i\ "monthstart": '"${monthstart_s}"'' ${server_conf}
  357. sed -i '3i\ "location": "'"${location_s}"'",' ${server_conf}
  358. sed -i '3i\ "host": "'"None"'",' ${server_conf}
  359. sed -i '3i\ "type": "'"${type_s}"'",' ${server_conf}
  360. sed -i '3i\ "name": "'"${name_s}"'",' ${server_conf}
  361. sed -i '3i\ "password": "'"${password_s}"'",' ${server_conf}
  362. sed -i '3i\ "username": "'"${username_s}"'",' ${server_conf}
  363. sed -i '3i\ {' ${server_conf}
  364. echo -e "${Info} 添加节点成功 ${Green_font_prefix}[ 节点名称: ${name_s}, 节点用户名: ${username_s}, 节点密码: ${password_s} ]${Font_color_suffix} !"
  365. }
  366. Del_ServerStatus_server() {
  367. List_ServerStatus_server
  368. [[ "${conf_text_total}" == "1" ]] && echo -e "${Error} 节点配置仅剩 1个,不能删除 !" && exit 1
  369. echo -e "请输入要删除的节点用户名"
  370. read -erp "(默认: 取消):" del_server_username
  371. [[ -z "${del_server_username}" ]] && echo -e "已取消..." && exit 1
  372. del_username=$(cat -n ${server_conf} | grep '"username": "'"${del_server_username}"'"' | awk '{print $1}')
  373. if [[ -n ${del_username} ]]; then
  374. del_username_min=$((del_username - 1))
  375. del_username_max=$((del_username + 7))
  376. del_username_max_text=$(sed -n "${del_username_max}p" ${server_conf})
  377. del_username_max_text_last=${del_username_max_text:((${#del_username_max_text} - 1))}
  378. if [[ ${del_username_max_text_last} != "," ]]; then
  379. del_list_num=$((del_username_min - 1))
  380. sed -i "${del_list_num}s/,$//g" ${server_conf}
  381. fi
  382. sed -i "${del_username_min},${del_username_max}d" ${server_conf}
  383. echo -e "${Info} 节点删除成功 ${Green_font_prefix}[ 节点用户名: ${del_server_username} ]${Font_color_suffix} "
  384. else
  385. echo -e "${Error} 请输入正确的节点用户名 !" && exit 1
  386. fi
  387. }
  388. Modify_ServerStatus_server_username() {
  389. List_ServerStatus_server
  390. echo -e "请输入要修改的节点用户名"
  391. read -erp "(默认: 取消):" manually_username
  392. [[ -z "${manually_username}" ]] && echo -e "已取消..." && exit 1
  393. Set_username_num=$(cat -n ${server_conf} | grep '"username": "'"${manually_username}"'"' | awk '{print $1}')
  394. if [[ -n ${Set_username_num} ]]; then
  395. Set_username
  396. Set_username_ch=$(grep '"username": "'"${username_s}"'"' ${server_conf})
  397. [[ -n "${Set_username_ch}" ]] && echo -e "${Error} 用户名已被使用 !" && exit 1
  398. sed -i "${Set_username_num}"'s/"username": "'"${manually_username}"'"/"username": "'"${username_s}"'"/g' ${server_conf}
  399. echo -e "${Info} 修改成功 [ 原节点用户名: ${manually_username}, 新节点用户名: ${username_s} ]"
  400. else
  401. echo -e "${Error} 请输入正确的节点用户名 !" && exit 1
  402. fi
  403. }
  404. Modify_ServerStatus_server_password() {
  405. List_ServerStatus_server
  406. echo -e "请输入要修改的节点用户名"
  407. read -erp "(默认: 取消):" manually_username
  408. [[ -z "${manually_username}" ]] && echo -e "已取消..." && exit 1
  409. Set_username_num=$(cat -n ${server_conf} | grep '"username": "'"${manually_username}"'"' | awk '{print $1}')
  410. if [[ -n ${Set_username_num} ]]; then
  411. Set_password
  412. Set_password_num_a=$((Set_username_num + 1))
  413. Set_password_num_text=$(sed -n "${Set_password_num_a}p" ${server_conf} | sed 's/\"//g;s/,$//g' | awk -F ": " '{print $2}')
  414. sed -i "${Set_password_num_a}"'s/"password": "'"${Set_password_num_text}"'"/"password": "'"${password_s}"'"/g' ${server_conf}
  415. echo -e "${Info} 修改成功 [ 原节点密码: ${Set_password_num_text}, 新节点密码: ${password_s} ]"
  416. else
  417. echo -e "${Error} 请输入正确的节点用户名 !" && exit 1
  418. fi
  419. }
  420. Modify_ServerStatus_server_name() {
  421. List_ServerStatus_server
  422. echo -e "请输入要修改的节点用户名"
  423. read -erp "(默认: 取消):" manually_username
  424. [[ -z "${manually_username}" ]] && echo -e "已取消..." && exit 1
  425. Set_username_num=$(cat -n ${server_conf} | grep '"username": "'"${manually_username}"'"' | awk '{print $1}')
  426. if [[ -n ${Set_username_num} ]]; then
  427. Set_name
  428. Set_name_num_a=$((Set_username_num + 2))
  429. Set_name_num_a_text=$(sed -n "${Set_name_num_a}p" ${server_conf} | sed 's/\"//g;s/,$//g' | awk -F ": " '{print $2}')
  430. sed -i "${Set_name_num_a}"'s/"name": "'"${Set_name_num_a_text}"'"/"name": "'"${name_s}"'"/g' ${server_conf}
  431. echo -e "${Info} 修改成功 [ 原节点名称: ${Set_name_num_a_text}, 新节点名称: ${name_s} ]"
  432. else
  433. echo -e "${Error} 请输入正确的节点用户名 !" && exit 1
  434. fi
  435. }
  436. Modify_ServerStatus_server_type() {
  437. List_ServerStatus_server
  438. echo -e "请输入要修改的节点用户名"
  439. read -erp "(默认: 取消):" manually_username
  440. [[ -z "${manually_username}" ]] && echo -e "已取消..." && exit 1
  441. Set_username_num=$(cat -n ${server_conf} | grep '"username": "'"${manually_username}"'"' | awk '{print $1}')
  442. if [[ -n ${Set_username_num} ]]; then
  443. Set_type
  444. Set_type_num_a=$((Set_username_num + 3))
  445. Set_type_num_a_text=$(sed -n "${Set_type_num_a}p" ${server_conf} | sed 's/\"//g;s/,$//g' | awk -F ": " '{print $2}')
  446. sed -i "${Set_type_num_a}"'s/"type": "'"${Set_type_num_a_text}"'"/"type": "'"${type_s}"'"/g' ${server_conf}
  447. echo -e "${Info} 修改成功 [ 原节点虚拟化: ${Set_type_num_a_text}, 新节点虚拟化: ${type_s} ]"
  448. else
  449. echo -e "${Error} 请输入正确的节点用户名 !" && exit 1
  450. fi
  451. }
  452. Modify_ServerStatus_server_location() {
  453. List_ServerStatus_server
  454. echo -e "请输入要修改的节点用户名"
  455. read -erp "(默认: 取消):" manually_username
  456. [[ -z "${manually_username}" ]] && echo -e "已取消..." && exit 1
  457. Set_username_num=$(cat -n ${server_conf} | grep '"username": "'"${manually_username}"'"' | awk '{print $1}')
  458. if [[ -n ${Set_username_num} ]]; then
  459. Set_location
  460. Set_location_num_a=$((Set_username_num + 5))
  461. Set_location_num_a_text=$(sed -n "${Set_location_num_a}p" ${server_conf} | sed 's/\"//g;s/,$//g' | awk -F ": " '{print $2}')
  462. sed -i "${Set_location_num_a}"'s/"location": "'"${Set_location_num_a_text}"'"/"location": "'"${location_s}"'"/g' ${server_conf}
  463. echo -e "${Info} 修改成功 [ 原节点位置: ${Set_location_num_a_text}, 新节点位置: ${location_s} ]"
  464. else
  465. echo -e "${Error} 请输入正确的节点用户名 !" && exit 1
  466. fi
  467. }
  468. Modify_ServerStatus_server_monthstart() {
  469. List_ServerStatus_server
  470. echo -e "请输入要修改的节点用户名"
  471. read -erp "(默认: 取消):" manually_username
  472. [[ -z "${manually_username}" ]] && echo -e "已取消..." && exit 1
  473. Set_username_num=$(cat -n ${server_conf} | grep '"username": "'"${manually_username}"'"' | awk '{print $1}')
  474. if [[ -n ${Set_username_num} ]]; then
  475. Set_monthstart
  476. Set_monthstart_num_a=$((Set_username_num + 6))
  477. Set_monthstart_num_text=$(sed -n "${Set_monthstart_num_a}p" ${server_conf} | sed 's/\"//g;s/,$//g' | awk -F ": " '{print $2}')
  478. sed -i "${Set_monthstart_num_a}"'s/"monthstart": '"${Set_monthstart_num_text}"'/"monthstart": '"${monthstart_s}"'/g' ${server_conf}
  479. echo -e "${Info} 修改成功 [ 原月流量重置日: ${Set_monthstart_num_text}, 新月流量重置日: ${monthstart_s} ]"
  480. else
  481. echo -e "${Error} 请输入正确的节点用户名 !" && exit 1
  482. fi
  483. }
  484. Modify_ServerStatus_server_all() {
  485. List_ServerStatus_server
  486. echo -e "请输入要修改的节点用户名"
  487. read -erp "(默认: 取消):" manually_username
  488. [[ -z "${manually_username}" ]] && echo -e "已取消..." && exit 1
  489. Set_username_num=$(cat -n ${server_conf} | grep '"username": "'"${manually_username}"'"' | awk '{print $1}')
  490. if [[ -n ${Set_username_num} ]]; then
  491. Set_username
  492. Set_password
  493. Set_name
  494. Set_type
  495. Set_location
  496. Set_monthstart
  497. sed -i "${Set_username_num}"'s/"username": "'"${manually_username}"'"/"username": "'"${username_s}"'"/g' ${server_conf}
  498. Set_password_num_a=$((Set_username_num + 1))
  499. Set_password_num_text=$(sed -n "${Set_password_num_a}p" ${server_conf} | sed 's/\"//g;s/,$//g' | awk -F ": " '{print $2}')
  500. sed -i "${Set_password_num_a}"'s/"password": "'"${Set_password_num_text}"'"/"password": "'"${password_s}"'"/g' ${server_conf}
  501. Set_name_num_a=$((Set_username_num + 2))
  502. Set_name_num_a_text=$(sed -n "${Set_name_num_a}p" ${server_conf} | sed 's/\"//g;s/,$//g' | awk -F ": " '{print $2}')
  503. sed -i "${Set_name_num_a}"'s/"name": "'"${Set_name_num_a_text}"'"/"name": "'"${name_s}"'"/g' ${server_conf}
  504. Set_type_num_a=$((Set_username_num + 3))
  505. Set_type_num_a_text=$(sed -n "${Set_type_num_a}p" ${server_conf} | sed 's/\"//g;s/,$//g' | awk -F ": " '{print $2}')
  506. sed -i "${Set_type_num_a}"'s/"type": "'"${Set_type_num_a_text}"'"/"type": "'"${type_s}"'"/g' ${server_conf}
  507. Set_location_num_a=$((Set_username_num + 5))
  508. Set_location_num_a_text=$(sed -n "${Set_location_num_a}p" ${server_conf} | sed 's/\"//g;s/,$//g' | awk -F ": " '{print $2}')
  509. sed -i "${Set_location_num_a}"'s/"location": "'"${Set_location_num_a_text}"'"/"location": "'"${location_s}"'"/g' ${server_conf}
  510. Set_monthstart_num_a=$((Set_username_num + 6))
  511. Set_monthstart_num_a_text=$(sed -n "${Set_monthstart_num_a}p" ${server_conf} | sed 's/\"//g;s/,$//g' | awk -F ": " '{print $2}')
  512. sed -i "${Set_monthstart_num_a}"'s/"monthstart": '"${Set_monthstart_num_a_text}"'/"monthstart": '"${monthstart_s}"'/g' ${server_conf}
  513. echo -e "${Info} 修改成功。"
  514. else
  515. echo -e "${Error} 请输入正确的节点用户名 !" && exit 1
  516. fi
  517. }
  518. Modify_ServerStatus_server_disabled() {
  519. List_ServerStatus_server
  520. echo -e "请输入要修改的节点用户名"
  521. read -erp "(默认: 取消):" manually_username
  522. [[ -z "${manually_username}" ]] && echo -e "已取消..." && exit 1
  523. Set_username_num=$(cat -n ${server_conf} | grep '"username": "'"${manually_username}"'"' | awk '{print $1}')
  524. if [[ -n ${Set_username_num} ]]; then
  525. Set_disabled_num_a=$((Set_username_num + 6))
  526. Set_disabled_num_a_text=$(sed -n "${Set_disabled_num_a}p" ${server_conf} | sed 's/\"//g;s/,$//g' | awk -F ": " '{print $2}')
  527. if [[ ${Set_disabled_num_a_text} == "false" ]]; then
  528. disabled_s="true"
  529. else
  530. disabled_s="false"
  531. fi
  532. sed -i "${Set_disabled_num_a}"'s/"disabled": '"${Set_disabled_num_a_text}"'/"disabled": '"${disabled_s}"'/g' ${server_conf}
  533. echo -e "${Info} 修改成功 [ 原禁用状态: ${Set_disabled_num_a_text}, 新禁用状态: ${disabled_s} ]"
  534. else
  535. echo -e "${Error} 请输入正确的节点用户名 !" && exit 1
  536. fi
  537. }
  538. Set_ServerStatus_client() {
  539. check_installed_client_status
  540. Set_config_client
  541. Read_config_client
  542. Modify_config_client
  543. Restart_ServerStatus_client
  544. }
  545. Modify_config_client() {
  546. sed -i '0,/SERVER = "'"${client_server}"'"/s//SERVER = "'"${server_s}"'"/' "${client_file}/client-linux.py"
  547. sed -i '0,/PORT = ${client_port}/s//PORT = ${server_port_s}/' "${client_file}/client-linux.py"
  548. sed -i '0,/USER = "'"${client_user}"'"/s//USER = "'"${username_s}"'"/' "${client_file}/client-linux.py"
  549. sed -i '0,/PASSWORD = "'"${client_password}"'"/s//PASSWORD = "'"${password_s}"'"/' "${client_file}/client-linux.py"
  550. }
  551. Install_jq() {
  552. [[ ${mirror_num} == 2 ]] && {
  553. github_link="https://hub.fastgit.org"
  554. raw_link="https://raw.fastgit.org"
  555. } || {
  556. github_link="https://github.com"
  557. raw_link="https://raw.githubusercontent.com"
  558. }
  559. if [[ ! -e ${jq_file} ]]; then
  560. if [[ ${bit} == "x86_64" ]]; then
  561. jq_file="${file}/jq"
  562. wget --no-check-certificate "${github_link}/stedolan/jq/releases/download/jq-1.5/jq-linux64" -O ${jq_file}
  563. elif [[ ${bit} == "i386" ]]; then
  564. jq_file="${file}/jq"
  565. wget --no-check-certificate "${github_link}/stedolan/jq/releases/download/jq-1.5/jq-linux32" -O ${jq_file}
  566. else
  567. # ARM fallback to package manager
  568. [[ ${release} == "archlinux" ]] && pacman -Sy jq --noconfirm
  569. [[ ${release} == "centos" ]] && yum -y install jq
  570. [[ ${release} == "debian" ]] && apt -y install jq
  571. jq_file="/usr/bin/jq"
  572. fi
  573. [[ ! -e ${jq_file} ]] && echo -e "${Error} JQ解析器 下载失败,请检查 !" && exit 1
  574. chmod +x ${jq_file}
  575. echo -e "${Info} JQ解析器 安装完成,继续..."
  576. else
  577. echo -e "${Info} JQ解析器 已安装,继续..."
  578. fi
  579. }
  580. Install_caddy() {
  581. echo
  582. echo -e "${Info} 是否由脚本自动配置HTTP服务(服务端的在线监控网站),如果选择 N,则请在其他HTTP服务中配置网站根目录为:${Green_font_prefix}${web_file}${Font_color_suffix} [Y/n]"
  583. read -erp "(默认: Y 自动部署):" caddy_yn
  584. [[ -z "$caddy_yn" ]] && caddy_yn="y"
  585. if [[ "${caddy_yn}" == [Yy] ]]; then
  586. caddy_file="/etc/caddy/Caddyfile" # Where is the default Caddyfile specified in Archlinux?
  587. [[ ! -e /usr/bin/caddy ]] && {
  588. if [[ ${release} == "debian" ]]; then
  589. apt install -y debian-keyring debian-archive-keyring apt-transport-https curl
  590. curl -1sLf "https://dl.cloudsmith.io/public/caddy/stable/gpg.key" | tee /etc/apt/trusted.gpg.d/caddy-stable.asc
  591. curl -1sLf "https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt" | tee /etc/apt/sources.list.d/caddy-stable.list
  592. apt update && apt install caddy
  593. elif [[ ${release} == "centos" ]]; then
  594. yum install yum-plugin-copr -y
  595. yum copr enable @caddy/caddy -y
  596. yum install caddy -y
  597. elif [[ ${release} == "archlinux" ]]; then
  598. pacman -Sy caddy --noconfirm
  599. fi
  600. [[ ! -e "/usr/bin/caddy" ]] && echo -e "${Error} Caddy安装失败,请手动部署,Web网页文件位置:${web_file}" && exit 1
  601. systemctl enable caddy
  602. echo "" >${caddy_file}
  603. }
  604. Set_server "server"
  605. Set_server_http_port
  606. cat >>${caddy_file} <<-EOF
  607. http://${server_s}:${server_http_port_s} {
  608. root * ${web_file}
  609. encode gzip
  610. file_server
  611. }
  612. EOF
  613. systemctl restart caddy
  614. else
  615. echo -e "${Info} 跳过 HTTP服务部署,请手动部署,Web网页文件位置:${web_file} ,如果位置改变,请注意修改服务脚本文件 /etc/init.d/status-server 中的 WEB_BIN 变量 !"
  616. fi
  617. }
  618. Install_ServerStatus_server() {
  619. [[ -e "${server_file}/sergate" ]] && echo -e "${Error} 检测到 $NAME 服务端已安装 !" && exit 1
  620. Set_server_port
  621. echo -e "${Info} 开始安装/配置 依赖..."
  622. Installation_dependency "server"
  623. Install_caddy
  624. echo -e "${Info} 开始下载/安装..."
  625. Download_Server_Status_server
  626. Install_jq
  627. echo -e "${Info} 开始下载/安装 服务脚本..."
  628. Service_Server_Status_server
  629. echo -e "${Info} 开始写入 配置文件..."
  630. Write_server_config
  631. Write_server_config_conf
  632. echo -e "${Info} 所有步骤 安装完毕,开始启动..."
  633. Start_ServerStatus_server
  634. }
  635. Install_ServerStatus_client() {
  636. [[ -e "${client_file}/client-linux.py" ]] && echo -e "${Error} 检测到 $NAME 客户端已安装 !" && exit 1
  637. check_sys
  638. echo -e "${Info} 开始设置 用户配置..."
  639. Set_config_client
  640. echo -e "${Info} 开始安装/配置 依赖..."
  641. Installation_dependency "client"
  642. echo -e "${Info} 开始下载/安装..."
  643. Download_Server_Status_client
  644. echo -e "${Info} 开始下载/安装 服务脚本..."
  645. Service_Server_Status_client
  646. echo -e "${Info} 开始写入 配置..."
  647. Read_config_client
  648. Modify_config_client
  649. echo -e "${Info} 所有步骤 安装完毕,开始启动..."
  650. Start_ServerStatus_client
  651. }
  652. Update_ServerStatus_server() {
  653. check_installed_server_status
  654. Download_Server_Status_server
  655. rm -rf /etc/init.d/status-server
  656. Service_Server_Status_server
  657. Start_ServerStatus_server
  658. }
  659. Update_ServerStatus_client() {
  660. check_installed_client_status
  661. systemctl stop status-client
  662. client_text="$(sed 's/\"//g;s/,//g;s/ //g' "${client_file}/client-linux.py")"
  663. server_s="$(echo -e "${client_text}" | grep "SERVER=" | awk -F "=" '{print $2;exit}')"
  664. server_port_s="$(echo -e "${client_text}" | grep "PORT=" | awk -F "=" '{print $2;exit}')"
  665. username_s="$(echo -e "${client_text}" | grep "USER=" | awk -F "=" '{print $2;exit}')"
  666. password_s="$(echo -e "${client_text}" | grep "PASSWORD=" | awk -F "=" '{print $2;exit}')"
  667. Download_Server_Status_client
  668. Read_config_client
  669. Modify_config_client
  670. rm -rf ${service}/status-client.service
  671. Service_Server_Status_client
  672. Start_ServerStatus_client
  673. }
  674. Start_ServerStatus_server() {
  675. port="$(grep "m_Port = " ${server_file}/src/main.cpp | awk '{print $3}' | sed '{s/;$//}')"
  676. check_installed_server_status
  677. systemctl -q is-active status-server && echo -e "${Error} $NAME 正在运行,请检查 !" && exit 1
  678. systemctl start status-server
  679. if (systemctl -q is-active status-server) then
  680. echo -e "${Info} $NAME 服务端启动成功[监听端口:${port}] !"
  681. else
  682. echo -e "${Error} $NAME 服务端启动失败 !"
  683. fi
  684. }
  685. Stop_ServerStatus_server() {
  686. check_installed_server_status
  687. if (systemctl -q is-active status-server)
  688. then
  689. systemctl stop status-server
  690. else
  691. echo -e "${Error} $NAME 没有运行,请检查 !" && exit 1
  692. fi
  693. if (systemctl -q is-active status-server) then
  694. echo -e "${Error} $NAME 服务端停止失败 !"
  695. else
  696. echo -e "${Info} $NAME 服务端停止成功 !"
  697. fi
  698. }
  699. Restart_ServerStatus_server() {
  700. check_installed_server_status
  701. systemctl restart status-server
  702. if (systemctl -q is-active status-server)
  703. then
  704. echo -e "${Info} $NAME 服务端重启成功 !"
  705. else
  706. echo -e "${Error} $NAME 服务端重启失败 !" && exit 1
  707. fi
  708. }
  709. Uninstall_ServerStatus_server() {
  710. check_installed_server_status
  711. echo "确定要卸载 $NAME 服务端(如果同时安装了客户端,则只会删除服务端) ? [y/N]"
  712. echo
  713. read -erp "(默认: n):" unyn
  714. [[ -z ${unyn} ]] && unyn="n"
  715. if [[ ${unyn} == [Yy] ]]; then
  716. systemctl stop status-server
  717. systemctl disable status-server
  718. rm ${service}/status-server.service -f
  719. if [[ -e "${client_file}/client-linux.py" ]]; then
  720. rm -rf "${server_file}"
  721. rm -rf "${web_file}"
  722. rm -rf "${plugin_file}"
  723. else
  724. rm -rf "${file}"
  725. fi
  726. if [[ -e "/usr/bin/caddy" ]]; then
  727. systemctl stop caddy
  728. systemctl disable caddy
  729. [[ ${release} == "debian" ]] && apt purge -y caddy
  730. [[ ${release} == "centos" ]] && yum -y remove caddy
  731. [[ ${release} == "archlinux" ]] && pacman -R caddy --noconfirm
  732. fi
  733. systemctl daemon-reload
  734. systemctl reset-failed
  735. echo && echo "ServerStatus 卸载完成 !" && echo
  736. else
  737. echo && echo "卸载已取消..." && echo
  738. fi
  739. }
  740. Start_ServerStatus_client() {
  741. check_installed_client_status
  742. if (systemctl -q is-active status-client) then
  743. echo -e "${Error} $NAME 客户端正在运行,请检查 !" && exit 1
  744. fi
  745. systemctl start status-client
  746. if (systemctl -q is-active status-client)
  747. then
  748. echo -e "${Info} $NAME 客户端启动成功 !"
  749. else
  750. echo -e "${Error} $NAME 客户端启动失败 !"
  751. fi
  752. }
  753. Stop_ServerStatus_client() {
  754. check_installed_client_status
  755. if (systemctl -q is-active status-client) then
  756. systemctl stop status-client
  757. if (systemctl -q is-active status-client) then
  758. echo -e "${Error}} $NAME 停止失败 !"
  759. else
  760. echo -e "${Info} $NAME 停止成功 !"
  761. fi
  762. else
  763. echo -e "${Error} $NAME 没有运行,请检查 !" && exit 1
  764. fi
  765. }
  766. Restart_ServerStatus_client() {
  767. systemctl restart status-client
  768. if (systemctl -q is-active status-client) then
  769. echo -e "${Info} $NAME 重启成功 !"
  770. else
  771. echo -e "${Error} $NAME 重启失败 !" && exit 1
  772. fi
  773. }
  774. Uninstall_ServerStatus_client() {
  775. check_installed_client_status
  776. echo "确定要卸载 $NAME 客户端(如果同时安装了服务端,则只会删除客户端) ? [y/N]"
  777. echo
  778. read -erp "(默认: n):" unyn
  779. [[ -z ${unyn} ]] && unyn="n"
  780. if [[ ${unyn} == [Yy] ]]; then
  781. systemctl stop status-client
  782. systemctl disable status-client
  783. rm ${service}/status-client.service -f
  784. systemctl daemon-reload
  785. systemctl reset-failed
  786. rm -rf "${client_file}"
  787. echo && echo "ServerStatus 卸载完成 !" && echo
  788. else
  789. echo && echo "卸载已取消..." && echo
  790. fi
  791. }
  792. View_ServerStatus_client() {
  793. check_installed_client_status
  794. Read_config_client
  795. clear && echo "————————————————————" && echo
  796. echo -e " $NAME 客户端配置信息:
  797. IP \t: ${Green_font_prefix}${client_server}${Font_color_suffix}
  798. 端口 \t: ${Green_font_prefix}${client_port}${Font_color_suffix}
  799. 账号 \t: ${Green_font_prefix}${client_user}${Font_color_suffix}
  800. 密码 \t: ${Green_font_prefix}${client_password}${Font_color_suffix}
  801. ————————————————————"
  802. }
  803. View_client_Log() {
  804. journalctl -u status-client.service --no-pager -f
  805. if [[ $# == 0 ]]; then
  806. before_show_menu
  807. fi
  808. }
  809. View_server_Log() {
  810. journalctl -u status-server.service --no-pager -f
  811. if [[ $# == 0 ]]; then
  812. before_show_menu
  813. fi
  814. }
  815. Update_Shell() {
  816. 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)
  817. [[ -z ${sh_new_ver} ]] && echo -e "${Error} 无法链接到 Github !" && exit 0
  818. if [[ -e "${service}/status-client.service" ]]; then
  819. rm -rf ${service}/status-client.service
  820. Service_Server_Status_client
  821. fi
  822. if [[ -e "${service}/status-server.service" ]]; then
  823. rm -rf ${service}/status-server.service
  824. Service_Server_Status_server
  825. fi
  826. wget -N --no-check-certificate "${github_prefix}/status.sh"
  827. echo -e "脚本已更新为最新版本[ ${sh_new_ver} ] !(注意:因为更新方式为直接覆盖当前运行的脚本,所以可能下面会提示一些报错,无视即可)" && exit 0
  828. }
  829. menu_client() {
  830. echo && echo -e " $NAME 一键安装管理脚本 ${Red_font_prefix}[v${sh_ver}]${Font_color_suffix}
  831. ${Green_font_prefix} 0.${Font_color_suffix} 升级脚本
  832. ————————————
  833. ${Green_font_prefix} 1.${Font_color_suffix} 安装 客户端
  834. ${Green_font_prefix} 2.${Font_color_suffix} 更新 客户端
  835. ${Green_font_prefix} 3.${Font_color_suffix} 卸载 客户端
  836. ————————————
  837. ${Green_font_prefix} 4.${Font_color_suffix} 启动 客户端
  838. ${Green_font_prefix} 5.${Font_color_suffix} 停止 客户端
  839. ${Green_font_prefix} 6.${Font_color_suffix} 重启 客户端
  840. ————————————
  841. ${Green_font_prefix} 7.${Font_color_suffix} 设置 客户端配置
  842. ${Green_font_prefix} 8.${Font_color_suffix} 查看 客户端信息
  843. ${Green_font_prefix} 9.${Font_color_suffix} 查看 客户端日志
  844. ————————————
  845. ${Green_font_prefix}10.${Font_color_suffix} 切换为 服务端菜单" && echo
  846. if [[ -e "${client_file}/client-linux.py" ]]; then
  847. if (systemctl -q is-active status-client); then
  848. echo -e " 当前状态: 客户端 ${Green_font_prefix}已安装${Font_color_suffix} 并 ${Green_font_prefix}已启动${Font_color_suffix}"
  849. else
  850. echo -e " 当前状态: 客户端 ${Green_font_prefix}已安装${Font_color_suffix} 但 ${Red_font_prefix}未启动${Font_color_suffix}"
  851. fi
  852. else
  853. echo -e " 当前状态: 客户端 ${Red_font_prefix}未安装${Font_color_suffix}"
  854. fi
  855. echo
  856. read -erp " 请输入数字 [0-10]:" num
  857. case "$num" in
  858. 0)
  859. Update_Shell
  860. ;;
  861. 1)
  862. Install_ServerStatus_client
  863. ;;
  864. 2)
  865. Update_ServerStatus_client
  866. ;;
  867. 3)
  868. Uninstall_ServerStatus_client
  869. ;;
  870. 4)
  871. Start_ServerStatus_client
  872. ;;
  873. 5)
  874. Stop_ServerStatus_client
  875. ;;
  876. 6)
  877. Restart_ServerStatus_client
  878. ;;
  879. 7)
  880. Set_ServerStatus_client
  881. ;;
  882. 8)
  883. View_ServerStatus_client
  884. ;;
  885. 9)
  886. View_client_Log
  887. ;;
  888. 10)
  889. menu_server
  890. ;;
  891. *)
  892. echo "请输入正确数字 [0-10]"
  893. ;;
  894. esac
  895. }
  896. menu_server() {
  897. echo && echo -e " $NAME 一键安装管理脚本 ${Red_font_prefix}[v${sh_ver}]${Font_color_suffix}
  898. ${Green_font_prefix} 0.${Font_color_suffix} 升级脚本
  899. ————————————
  900. ${Green_font_prefix} 1.${Font_color_suffix} 安装 服务端
  901. ${Green_font_prefix} 2.${Font_color_suffix} 更新 服务端
  902. ${Green_font_prefix} 3.${Font_color_suffix} 卸载 服务端
  903. ————————————
  904. ${Green_font_prefix} 4.${Font_color_suffix} 启动 服务端
  905. ${Green_font_prefix} 5.${Font_color_suffix} 停止 服务端
  906. ${Green_font_prefix} 6.${Font_color_suffix} 重启 服务端
  907. ————————————
  908. ${Green_font_prefix} 7.${Font_color_suffix} 设置 服务端配置
  909. ${Green_font_prefix} 8.${Font_color_suffix} 查看 服务端信息
  910. ${Green_font_prefix} 9.${Font_color_suffix} 查看 服务端日志
  911. ————————————
  912. ${Green_font_prefix}10.${Font_color_suffix} 切换为 客户端菜单" && echo
  913. if [[ -e "${server_file}/sergate" ]]; then
  914. if (systemctl -q is-active status-server) then
  915. echo -e " 当前状态: 服务端 ${Green_font_prefix}已安装${Font_color_suffix} 并 ${Green_font_prefix}已启动${Font_color_suffix}"
  916. else
  917. echo -e " 当前状态: 服务端 ${Green_font_prefix}已安装${Font_color_suffix} 但 ${Red_font_prefix}未启动${Font_color_suffix}"
  918. fi
  919. else
  920. echo -e " 当前状态: 服务端 ${Red_font_prefix}未安装${Font_color_suffix}"
  921. fi
  922. echo
  923. read -erp " 请输入数字 [0-10]:" num
  924. case "$num" in
  925. 0)
  926. Update_Shell
  927. ;;
  928. 1)
  929. Install_ServerStatus_server
  930. ;;
  931. 2)
  932. Update_ServerStatus_server
  933. ;;
  934. 3)
  935. Uninstall_ServerStatus_server
  936. ;;
  937. 4)
  938. Start_ServerStatus_server
  939. ;;
  940. 5)
  941. Stop_ServerStatus_server
  942. ;;
  943. 6)
  944. Restart_ServerStatus_server
  945. ;;
  946. 7)
  947. Set_ServerStatus_server
  948. ;;
  949. 8)
  950. List_ServerStatus_server
  951. ;;
  952. 9)
  953. View_server_Log
  954. ;;
  955. 10)
  956. menu_client
  957. ;;
  958. *)
  959. echo "请输入正确数字 [0-10]"
  960. ;;
  961. esac
  962. }
  963. check_sys
  964. action=$1
  965. if [[ -n $action ]]; then
  966. if [[ $action == "s" ]]; then
  967. menu_server
  968. elif [[ $action == "c" ]]; then
  969. menu_client
  970. fi
  971. else
  972. menu_client
  973. fi