trojan-go 66 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310
  1. #!/bin/bash
  2. clear
  3. #MIT License
  4. #Copyright (c) 2020 h31105
  5. #Permission is hereby granted, free of charge, to any person obtaining a copy
  6. #of this software and associated documentation files (the "Software"), to deal
  7. #in the Software without restriction, including without limitation the rights
  8. #to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. #copies of the Software, and to permit persons to whom the Software is
  10. #furnished to do so, subject to the following conditions:
  11. #The above copyright notice and this permission notice shall be included in all
  12. #copies or substantial portions of the Software.
  13. #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. #IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. #FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. #AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. #LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. #OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  19. #SOFTWARE.
  20. #====================================================
  21. # System Request:Debian 9+/Ubuntu 18.04+/Centos 7+
  22. # Author: Miroku/h31105
  23. # Dscription: TLS-Shunt-Proxy&Trojan-Go&V2Ray Script
  24. # Official document:
  25. # https://www.v2ray.com/
  26. # https://github.com/p4gefau1t/trojan-go
  27. # https://github.com/liberal-boy/tls-shunt-proxy
  28. # https://www.docker.com/
  29. # https://github.com/containrrr/watchtower
  30. # https://github.com/portainer/portainer
  31. # https://github.com/wulabing/V2Ray_ws-tls_bash_onekey
  32. #====================================================
  33. PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
  34. export PATH
  35. cd "$(
  36. cd "$(dirname "$0")" || exit
  37. pwd
  38. )" || exit
  39. #Fonts Color
  40. Green="\033[32m"
  41. Red="\033[31m"
  42. Yellow="\033[33m"
  43. GreenBG="\033[42;30m"
  44. RedBG="\033[41;30m"
  45. Font="\033[0m"
  46. #Notification Information
  47. OK="${Green}[OK]${Font}"
  48. WARN="${Yellow}[警告]${Font}"
  49. Error="${Red}[错误]${Font}"
  50. #版本、初始化变量
  51. shell_version="1.183"
  52. tsp_cfg_version="0.61.1"
  53. #install_mode="docker"
  54. upgrade_mode="none"
  55. github_branch="master"
  56. version_cmp="/tmp/version_cmp.tmp"
  57. tsp_conf_dir="/etc/tls-shunt-proxy"
  58. trojan_conf_dir="/etc/trojan-go"
  59. v2ray_conf_dir="/etc/v2ray"
  60. tsp_conf="${tsp_conf_dir}/config.yaml"
  61. tsp_cert_dir="/etc/ssl/tls-shunt-proxy/certificates/acme-v02.api.letsencrypt.org-directory"
  62. trojan_conf="${trojan_conf_dir}/config.json"
  63. v2ray_conf="${v2ray_conf_dir}/config.json"
  64. web_dir="/home/wwwroot"
  65. random_num=$((RANDOM % 3 + 7))
  66. #shellcheck disable=SC1091
  67. source '/etc/os-release'
  68. #从VERSION中提取发行版系统的英文名称
  69. VERSION=$(echo "${VERSION}" | awk -F "[()]" '{print $2}')
  70. check_system() {
  71. if [[ "${ID}" == "centos" && ${VERSION_ID} -eq 7 ]]; then
  72. echo -e "${OK} ${GreenBG} O sistema atual é Centos ${VERSION_ID} ${VERSION} ${Font}"
  73. INS="yum -y -q"
  74. elif [[ "${ID}" == "centos" && ${VERSION_ID} -ge 8 ]]; then
  75. echo -e "${OK} ${GreenBG} O sistema atual é Centos ${VERSION_ID} ${VERSION} ${Font}"
  76. INS="dnf -y"
  77. elif [[ "${ID}" == "debian" && ${VERSION_ID} -ge 8 ]]; then
  78. echo -e "${OK} ${GreenBG} O sistema atual é Debian ${VERSION_ID} ${VERSION} ${Font}"
  79. INS="apt -y -qq"
  80. elif [[ "${ID}" == "ubuntu" && $(echo "${VERSION_ID}" | cut -d '.' -f1) -ge 16 ]]; then
  81. echo -e "${OK} ${GreenBG} O sistema atual é Ubuntu ${VERSION_ID} ${UBUNTU_CODENAME} ${Font}"
  82. INS="apt -y -qq"
  83. else
  84. echo -e "${Error} ${RedBG} O sistema atual é ${ID} ${VERSION_ID} Não consta da lista de sistemas suportados, a instalação foi interrompida ${Font}"
  85. exit 1
  86. fi
  87. }
  88. is_root() {
  89. if [ 0 == $UID ]; then
  90. echo -e "${OK} ${GreenBG} O usuário atual é o usuário root, continue a executar ${Font}"
  91. sleep 1
  92. else
  93. echo -e "${Error} ${RedBG} O usuário atual não é o usuário root, mude para o usuário root e execute novamente o script ${Font}"
  94. exit 1
  95. fi
  96. }
  97. judge() {
  98. #shellcheck disable=SC2181
  99. if [[ 0 -eq $? ]]; then
  100. echo -e "${OK} ${GreenBG} $1 Terminar ${Font}"
  101. sleep 1
  102. else
  103. echo -e "${Error} ${RedBG} $1 falhou ${Font}"
  104. exit 1
  105. fi
  106. }
  107. urlEncode() {
  108. jq -R -r @uri <<<"$1"
  109. }
  110. chrony_install() {
  111. ${INS} install chrony
  112. judge "Instale o serviço de sincronização de tempo Chrony"
  113. timedatectl set-ntp true
  114. if [[ "${ID}" == "centos" ]]; then
  115. systemctl enable chronyd && systemctl restart chronyd
  116. else
  117. systemctl enable chrony && systemctl restart chrony
  118. fi
  119. judge "Chrony 启动"
  120. timedatectl set-timezone Asia/Shanghai
  121. echo -e "${OK} ${GreenBG} Esperando pela sincronização de tempo ${Font}"
  122. sleep 10
  123. chronyc sourcestats -v
  124. chronyc tracking -v
  125. date
  126. read -rp "Por favor, confirme se o tempo está correto, a faixa de erro é de ± 3 minutos (Y/N) [Y]: " chrony_install
  127. [[ -z ${chrony_install} ]] && chrony_install="Y"
  128. case $chrony_install in
  129. [yY][eE][sS] | [yY])
  130. echo -e "${GreenBG} Continue a execução ${Font}"
  131. sleep 2
  132. ;;
  133. *)
  134. echo -e "${RedBG} Terminar execução ${Font}"
  135. exit 2
  136. ;;
  137. esac
  138. }
  139. dependency_install() {
  140. if [[ "${ID}" == "centos" && ${VERSION_ID} -eq 7 ]]; then
  141. yum install epel-release -y -q
  142. elif [[ "${ID}" == "centos" && ${VERSION_ID} -ge 8 ]]; then
  143. dnf install epel-release -y -q
  144. dnf config-manager --set-enabled PowerTools
  145. dnf upgrade libseccomp
  146. elif [[ "${ID}" == "debian" && ${VERSION_ID} -ge 8 ]]; then
  147. $INS update
  148. elif [[ "${ID}" == "ubuntu" && $(echo "${VERSION_ID}" | cut -d '.' -f1) -ge 16 ]]; then
  149. $INS update
  150. fi
  151. $INS install dbus
  152. ${INS} install git lsof unzip
  153. judge "Instale dependências git lsof unzip"
  154. ${INS} install haveged
  155. systemctl start haveged && systemctl enable haveged
  156. command -v bc >/dev/null 2>&1 || ${INS} install bc
  157. judge "Instale dependências bc"
  158. command -v jq >/dev/null 2>&1 || ${INS} install jq
  159. judge "Instale dependências jq"
  160. command -v sponge >/dev/null 2>&1 || ${INS} install moreutils
  161. judge "Instale dependências moreutils"
  162. command -v qrencode >/dev/null 2>&1 || ${INS} install qrencode
  163. judge "Instale dependências qrencode"
  164. }
  165. basic_optimization() {
  166. # 最大文件打开数
  167. sed -i '/^\*\ *soft\ *nofile\ *[[:digit:]]*/d' /etc/security/limits.conf
  168. sed -i '/^\*\ *hard\ *nofile\ *[[:digit:]]*/d' /etc/security/limits.conf
  169. echo '* soft nofile 65536' >>/etc/security/limits.conf
  170. echo '* hard nofile 65536' >>/etc/security/limits.conf
  171. # 关闭 Selinux
  172. if [[ "${ID}" == "centos" ]]; then
  173. sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
  174. setenforce 0
  175. fi
  176. }
  177. config_exist_check() {
  178. if [[ -f "$1" ]]; then
  179. echo -e "${OK} ${GreenBG} O arquivo de configuração antigo é detectado e o backup da configuração do arquivo antigo é feito automaticamente ${Font}"
  180. cp "$1" "$1.$(date +%Y%m%d%H)"
  181. echo -e "${OK} ${GreenBG} Foi feito backup da configuração antiga ${Font}"
  182. fi
  183. }
  184. domain_port_check() {
  185. read -rp "Insira a porta TLS (padrão 443):" tspport
  186. [[ -z ${tspport} ]] && tspport="443"
  187. read -rp "Insira as informações do seu nome de domínio (por exemplo, fk.gfw.com):" domain
  188. domain=$(echo "${domain}" | tr '[:upper:]' '[:lower:]')
  189. domain_ip=$(ping -q -c 1 -t 1 "${domain}" | grep PING | sed -e "s/).*//" | sed -e "s/.*(//")
  190. echo -e "${OK} ${GreenBG} Obtendo informações de IP de rede pública, aguarde pacientemente ${Font}"
  191. local_ip=$(curl -s https://api64.ipify.org)
  192. echo -e "IP de resolução de DNS de nome de domínio:${domain_ip}"
  193. echo -e "本机IP: ${local_ip}"
  194. sleep 2
  195. if [[ "${local_ip}" = "${domain_ip}" ]]; then
  196. echo -e "${OK} ${GreenBG} O IP de resolução DNS do nome de domínio corresponde ao IP local ${Font}"
  197. sleep 2
  198. else
  199. echo -e "${Error} ${RedBG} Certifique-se de que o registro A / AAAA correto seja adicionado ao nome de domínio, caso contrário, não será possível conectar-se normalmente ${Font}"
  200. echo -e "${Error} ${RedBG} Se o IP de resolução DNS do nome de domínio não corresponder ao IP da máquina, o aplicativo de certificado SSL falhará. Deseja continuar a instalação?(Y/N)[N]${Font}" && read -r install
  201. case $install in
  202. [yY][eE][sS] | [yY])
  203. echo -e "${GreenBG} Continue a instalar ${Font}"
  204. sleep 2
  205. ;;
  206. *)
  207. echo -e "${RedBG} Instalação encerrada ${Font}"
  208. exit 2
  209. ;;
  210. esac
  211. fi
  212. }
  213. port_exist_check() {
  214. if [[ 0 -eq $(lsof -i:"$1" | grep -i -c "listen") ]]; then
  215. echo -e "${OK} ${GreenBG} $1 A porta não está ocupada ${Font}"
  216. sleep 1
  217. else
  218. echo -e "${Error} ${RedBG} A porta $1 detectada está ocupada, segue-se a informação de ocupação da porta $1 ${Font}"
  219. lsof -i:"$1"
  220. echo -e "${OK} ${GreenBG} 5s Tentará matar automaticamente o processo ocupado ${Font}"
  221. sleep 5
  222. lsof -i:"$1" | awk '{print $2}' | grep -v "PID" | xargs kill -9
  223. echo -e "${OK} ${GreenBG} Kill Completo ${Font}"
  224. sleep 1
  225. fi
  226. }
  227. service_status_check() {
  228. if systemctl is-active "$1" &>/dev/null; then
  229. echo -e "${OK} ${GreenBG} $1 Começou ${Font}"
  230. if systemctl is-enabled "$1" &>/dev/null; then
  231. echo -e "${OK} ${GreenBG} $1 É um item de inicialização ${Font}"
  232. else
  233. echo -e "${WARN} ${Yellow} $1 Não é um item inicializável ${Font}"
  234. systemctl enable "$1"
  235. judge "Defina $1 para começar na inicialização"
  236. fi
  237. else
  238. echo -e "${Error} ${RedBG} Detectado que o serviço $1 não foi iniciado e está tentando iniciar... ${Font}"
  239. systemctl restart "$1" && systemctl enable "$1"
  240. judge "Tente começar $1 "
  241. sleep 5
  242. if systemctl is-active "$1" &>/dev/null; then
  243. echo -e "${OK} ${GreenBG} $1 Começou ${Font}"
  244. else
  245. echo -e "${WARN} ${Yellow} Tente reinstalar e reparar $1 e tente novamente ${Font}"
  246. exit 4
  247. fi
  248. fi
  249. }
  250. prereqcheck() {
  251. service_status_check docker
  252. if [[ -f ${tsp_conf} ]]; then
  253. service_status_check tls-shunt-proxy
  254. else
  255. echo -e "${Error} ${RedBG} A configuração TLS-Shunt-Proxy está anormal, tente reinstalar ${Font}"
  256. exit 4
  257. fi
  258. }
  259. trojan_reset() {
  260. config_exist_check ${trojan_conf}
  261. [[ -f ${trojan_conf} ]] && rm -rf ${trojan_conf}
  262. if [[ -f ${tsp_conf} ]]; then
  263. TSP_Domain=$(grep '#TSP_Domain' ${tsp_conf} | sed -r 's/.*: (.*) #.*/\1/') && echo -e "O nome de domínio TLS detectado é: ${TSP_Domain}"
  264. else
  265. echo -e "${Error} ${RedBG} A configuração TLS-Shunt-Proxy está anormal e as informações do nome de domínio TLS não podem ser detectadas. Reinstale e tente novamente ${Font}"
  266. exit 4
  267. fi
  268. read -rp "Por favor, digite a senha (Trojan-Go), ou padrão é aleatório :" tjpasswd
  269. [[ -z ${tjpasswd} ]] && tjpasswd=$(head -n 10 /dev/urandom | md5sum | head -c ${random_num})
  270. echo -e "${OK} ${GreenBG} Trojan-Go 密码: ${tjpasswd} ${Font}"
  271. read -rp "Deseja habilitar o suporte ao modo WebSocket (Y/N) [N]:" trojan_ws_mode
  272. [[ -z ${trojan_ws_mode} ]] && trojan_ws_mode=false
  273. case $trojan_ws_mode in
  274. [yY][eE][sS] | [yY])
  275. tjwspath="/trojan/$(head -n 10 /dev/urandom | md5sum | head -c ${random_num})/"
  276. echo -e "${OK} ${GreenBG} O modo Trojan-Go WebSocket está ativado, WSPATH: ${tjwspath} ${Font}"
  277. trojan_ws_mode=true
  278. ;;
  279. *)
  280. trojan_ws_mode=false
  281. ;;
  282. esac
  283. trojan_tcp_mode=true
  284. tjport=$((RANDOM % 6666 + 10000)) && echo -e "${OK} ${GreenBG} A porta de escuta do Trojan-Go é: $tjport ${Font}"
  285. mkdir -p $trojan_conf_dir
  286. cat >$trojan_conf <<-EOF
  287. {
  288. "run_type": "server",
  289. "disable_http_check": true,
  290. "local_addr": "127.0.0.1",
  291. "local_port": ${tjport},
  292. "remote_addr": "1.1.1.1",
  293. "remote_port": 80,
  294. "fallback_addr": "1.1.1.1",
  295. "fallback_port": 443,
  296. "password": ["${tjpasswd}"],
  297. "transport_plugin": {
  298. "enabled": true,
  299. "type": "plaintext"
  300. },
  301. "websocket": {
  302. "enabled": ${trojan_ws_mode},
  303. "path": "${tjwspath}",
  304. "host": "${TSP_Domain}"
  305. }
  306. }
  307. EOF
  308. judge "Trojan-Go Geração de configuração"
  309. port_exist_check $tjport
  310. trojan_sync
  311. judge "Sincronizar as definições de configuração do Trojan-Go"
  312. systemctl restart tls-shunt-proxy && service_status_check tls-shunt-proxy
  313. judge "Configurações do aplicativo TLS-Shunt-Proxy"
  314. }
  315. modify_trojan() {
  316. deployed_status_check
  317. echo -e "${WARN} ${Yellow} Modificar a configuração do Trojan-Go redefinirá as informações de configuração do proxy existente, se deve continuar (Y/N) [N]? ${Font}"
  318. read -r modify_confirm
  319. [[ -z ${modify_confirm} ]] && modify_confirm="No"
  320. case $modify_confirm in
  321. [yY][eE][sS] | [yY])
  322. prereqcheck
  323. trojan_reset
  324. docker restart Trojan-Go
  325. ;;
  326. *) ;;
  327. esac
  328. }
  329. trojan_sync() {
  330. [[ -z $tjport ]] && tjport=40001
  331. [[ -z $tjwspath ]] && tjwspath=/trojan/none
  332. [[ -z $trojan_tcp_mode ]] && trojan_tcp_mode=none
  333. [[ -z $trojan_ws_mode ]] && trojan_ws_mode=none
  334. if [[ ${trojan_tcp_mode} = true ]]; then
  335. sed -i "/trojan: #Trojan_TCP/c \\ trojan: #Trojan_TCP" ${tsp_conf}
  336. sed -i "/handler: proxyPass #Trojan_TCP/c \\ handler: proxyPass #Trojan_TCP" ${tsp_conf}
  337. sed -i "/#Trojan_TCP_Port/c \\ args: 127.0.0.1:${tjport} #Trojan_TCP_Port:${trojan_tcp_mode}" ${tsp_conf}
  338. else
  339. sed -i "/trojan: #Trojan_TCP/c \\ #trojan: #Trojan_TCP" ${tsp_conf}
  340. sed -i "/handler: proxyPass #Trojan_TCP/c \\ #handler: proxyPass #Trojan_TCP" ${tsp_conf}
  341. sed -i "/#Trojan_TCP_Port/c \\ #args: 127.0.0.1:${tjport} #Trojan_TCP_Port:${trojan_tcp_mode}" ${tsp_conf}
  342. fi
  343. if [[ ${trojan_ws_mode} = true ]]; then
  344. sed -i "/#Trojan_WS_Path/c \\ - path: ${tjwspath} #Trojan_WS_Path" ${tsp_conf}
  345. sed -i "/handler: proxyPass #Trojan_WS/c \\ handler: proxyPass #Trojan_WS" ${tsp_conf}
  346. sed -i "/#Trojan_WS_Port/c \\ args: 127.0.0.1:${tjport} #Trojan_WS_Port:${trojan_ws_mode}" ${tsp_conf}
  347. else
  348. sed -i "/#Trojan_WS_Path/c \\ #- path: ${tjwspath} #Trojan_WS_Path" ${tsp_conf}
  349. sed -i "/handler: proxyPass #Trojan_WS/c \\ #handler: proxyPass #Trojan_WS" ${tsp_conf}
  350. sed -i "/#Trojan_WS_Port/c \\ #args: 127.0.0.1:${tjport} #Trojan_WS_Port:${trojan_ws_mode}" ${tsp_conf}
  351. fi
  352. }
  353. v2ray_mode_type() {
  354. read -rp "Selecione o tipo de protocolo do modo TCP V2Ray:VMess(M)/VLESS(L),Pular por padrão,(M/L) [Skip]:" v2ray_tcp_mode
  355. [[ -z ${v2ray_tcp_mode} ]] && v2ray_tcp_mode="none"
  356. case $v2ray_tcp_mode in
  357. [mM])
  358. echo -e "${GreenBG} Protocolo de modo TCP selecionado VMess ${Font}"
  359. v2ray_tcp_mode="vmess"
  360. ;;
  361. [lL])
  362. echo -e "${GreenBG} Protocolo de modo TCP selecionado VLESS ${Font}"
  363. v2ray_tcp_mode="vless"
  364. ;;
  365. none)
  366. echo -e "${GreenBG} Pular implantação do modo TCP ${Font}"
  367. v2ray_tcp_mode="none"
  368. ;;
  369. *)
  370. echo -e "${RedBG} Por favor insira a letra correta (M/L) ${Font}"
  371. ;;
  372. esac
  373. read -rp "Selecione o tipo de protocolo do modo V2Ray WebSocket:VMess(M)/VLESS(L),Pular por padrão,(M/L) [Skip]:" v2ray_ws_mode
  374. [[ -z ${v2ray_ws_mode} ]] && v2ray_ws_mode="none"
  375. case $v2ray_ws_mode in
  376. [mM])
  377. echo -e "${GreenBG} Modo WS selecionado VMess ${Font}"
  378. v2ray_ws_mode="vmess"
  379. ;;
  380. [lL])
  381. echo -e "${GreenBG} Modo WS selecionado VLESS ${Font}"
  382. v2ray_ws_mode="vless"
  383. ;;
  384. none)
  385. echo -e "${GreenBG} Pular implantação do modo WS ${Font}"
  386. v2ray_ws_mode="none"
  387. ;;
  388. *)
  389. echo -e "${RedBG} Por favor insira a letra correta (M/L) ${Font}"
  390. ;;
  391. esac
  392. }
  393. v2ray_reset() {
  394. config_exist_check ${v2ray_conf}
  395. [[ -f ${v2ray_conf} ]] && rm -rf ${v2ray_conf}
  396. mkdir -p $v2ray_conf_dir
  397. cat >$v2ray_conf <<-EOF
  398. {
  399. "log": {
  400. "loglevel": "warning"
  401. },
  402. "inbounds":[
  403. ],
  404. "outbounds": [
  405. {
  406. "protocol": "freedom",
  407. "settings": {},
  408. "tag": "direct"
  409. },
  410. {
  411. "protocol": "blackhole",
  412. "settings": {},
  413. "tag": "blocked"
  414. }
  415. ],
  416. "dns": {
  417. "servers": [
  418. "https+local://1.1.1.1/dns-query",
  419. "1.1.1.1",
  420. "1.0.0.1",
  421. "8.8.8.8",
  422. "8.8.4.4",
  423. "localhost"
  424. ]
  425. },
  426. "routing": {
  427. "rules": [
  428. {
  429. "ip": [
  430. "geoip:private"
  431. ],
  432. "outboundTag": "blocked",
  433. "type": "field"
  434. },
  435. {
  436. "type": "field",
  437. "outboundTag": "blocked",
  438. "protocol": ["bittorrent"]
  439. },
  440. {
  441. "type": "field",
  442. "inboundTag": [
  443. ],
  444. "outboundTag": "direct"
  445. }
  446. ]
  447. }
  448. }
  449. EOF
  450. if [[ "${v2ray_ws_mode}" = v*ess ]]; then
  451. UUID=$(cat /proc/sys/kernel/random/uuid)
  452. echo -e "${OK} ${GreenBG} UUID:${UUID} ${Font}"
  453. v2wspath="/v2ray/$(head -n 10 /dev/urandom | md5sum | head -c ${random_num})/"
  454. echo -e "${OK} ${GreenBG} Ligue o modo V2Ray WS,WSPATH: ${v2wspath} ${Font}"
  455. v2wsport=$((RANDOM % 6666 + 30000))
  456. echo -e "${OK} ${GreenBG} V2Ray WS 监听端口为 ${v2wsport} ${Font}"
  457. if [[ "${v2ray_ws_mode}" = "vmess" ]]; then
  458. #read -rp "请输入 WS 模式 AlterID(默认:10 仅允许填非0数字):" alterID
  459. [[ -z ${alterID} ]] && alterID="10"
  460. jq '.inbounds += [{"sniffing":{"enabled":true,"destOverride":["http","tls"]},"port":'${v2wsport}',"listen":"127.0.0.1","tag":"vmess-ws-in","protocol":"vmess","settings":{"clients":[{"id":"'"${UUID}"'","alterId":'${alterID}'}]},"streamSettings":{"network":"ws","wsSettings":{"acceptProxyProtocol":true,"path":"'"${v2wspath}"'"}}}]' ${v2ray_conf} | sponge ${v2ray_conf} &&
  461. jq '.routing.rules[2].inboundTag += ["vmess-ws-in"]' ${v2ray_conf} | sponge ${v2ray_conf}
  462. judge "Geração de configuração V2Ray VMess WS"
  463. fi
  464. if [[ "${v2ray_ws_mode}" = "vless" ]]; then
  465. jq '.inbounds += [{"sniffing":{"enabled":true,"destOverride":["http","tls"]},"port":'${v2wsport}',"listen":"127.0.0.1","tag":"vless-ws-in","protocol":"vless","settings":{"clients":[{"id":"'"${UUID}"'","level":0}],"decryption":"none"},"streamSettings":{"network":"ws","wsSettings":{"acceptProxyProtocol":true,"path":"'"${v2wspath}"'"}}}]' ${v2ray_conf} | sponge ${v2ray_conf} &&
  466. jq '.routing.rules[2].inboundTag += ["vless-ws-in"]' ${v2ray_conf} | sponge ${v2ray_conf}
  467. judge "Geração de configuração V2Ray VLESS WS"
  468. fi
  469. port_exist_check ${v2wsport}
  470. fi
  471. if [[ "${v2ray_tcp_mode}" = v*ess ]]; then
  472. UUID=$(cat /proc/sys/kernel/random/uuid)
  473. echo -e "${OK} ${GreenBG} UUID:${UUID} ${Font}"
  474. v2port=$((RANDOM % 6666 + 20000))
  475. echo -e "${OK} ${GreenBG} A porta de escuta V2Ray TCP é ${v2port} ${Font}"
  476. if [[ "${v2ray_tcp_mode}" = "vmess" ]]; then
  477. #read -rp "请输入 TCP 模式 AlterID(默认:10 仅允许填非0数字):" alterID
  478. [[ -z ${alterID} ]] && alterID="10"
  479. jq '.inbounds += [{"sniffing":{"enabled":true,"destOverride":["http","tls"]},"port":'${v2port}',"listen":"127.0.0.1","tag":"vmess-tcp-in","protocol":"vmess","settings":{"clients":[{"id":"'"${UUID}"'","alterId":'${alterID}'}]},"streamSettings":{"network":"tcp","tcpSettings":{"acceptProxyProtocol":true}}}]' ${v2ray_conf} | sponge ${v2ray_conf} &&
  480. jq '.routing.rules[2].inboundTag += ["vmess-tcp-in"]' ${v2ray_conf} | sponge ${v2ray_conf}
  481. judge "Geração de configuração V2Ray VMess TCP"
  482. fi
  483. if [[ "${v2ray_tcp_mode}" = "vless" ]]; then
  484. jq '.inbounds += [{"sniffing":{"enabled":true,"destOverride":["http","tls"]},"port":'${v2port}',"listen":"127.0.0.1","tag":"vless-tcp-in","protocol":"vless","settings":{"clients":[{"id":"'"${UUID}"'","level":0}],"decryption":"none"},"streamSettings":{"network":"tcp","tcpSettings":{"acceptProxyProtocol":true}}}]' ${v2ray_conf} | sponge ${v2ray_conf} &&
  485. jq '.routing.rules[2].inboundTag += ["vless-tcp-in"]' ${v2ray_conf} | sponge ${v2ray_conf}
  486. judge "Geração de configuração V2Ray VLESS TCP"
  487. fi
  488. port_exist_check ${v2port}
  489. fi
  490. if [[ -f ${tsp_conf} ]]; then
  491. v2ray_sync
  492. judge "Sincronizar configuração V2Ray"
  493. systemctl restart tls-shunt-proxy && service_status_check tls-shunt-proxy
  494. judge "Configurações do aplicativo TLS-Shunt-Proxy"
  495. else
  496. echo -e "${Error} ${RedBG} A configuração TLS-Shunt-Proxy está anormal, reinstale e tente novamente ${Font}"
  497. exit 4
  498. fi
  499. }
  500. modify_v2ray() {
  501. deployed_status_check
  502. echo -e "${WARN} ${Yellow} Modificar a configuração do V2Ray irá redefinir as informações de configuração do proxy existente, se deve continuar (Y/N) [N]? ${Font}"
  503. read -r modify_confirm
  504. [[ -z ${modify_confirm} ]] && modify_confirm="No"
  505. case $modify_confirm in
  506. [yY][eE][sS] | [yY])
  507. prereqcheck
  508. v2ray_mode_type
  509. [[ $v2ray_tcp_mode != "none" || $v2ray_ws_mode != "none" ]] && v2ray_reset
  510. docker restart V2Ray
  511. ;;
  512. *) ;;
  513. esac
  514. }
  515. v2ray_sync() {
  516. [[ -z $v2port ]] && v2port=40003
  517. [[ -z $v2wsport ]] && v2wsport=40002
  518. [[ -z $v2wspath ]] && v2wspath=/v2ray/none
  519. [[ -z $v2ray_tcp_mode ]] && v2ray_tcp_mode=none
  520. [[ -z $v2ray_ws_mode ]] && v2ray_ws_mode=none
  521. if [[ ${v2ray_tcp_mode} = v*ess ]]; then
  522. sed -i "/default: #V2Ray_TCP/c \\ default: #V2Ray_TCP" ${tsp_conf}
  523. sed -i "/handler: proxyPass #V2Ray_TCP/c \\ handler: proxyPass #V2Ray_TCP" ${tsp_conf}
  524. sed -i "/#V2Ray_TCP_Port/c \\ args: 127.0.0.1:${v2port};proxyProtocol #V2Ray_TCP_Port:${v2ray_tcp_mode}" ${tsp_conf}
  525. else
  526. sed -i "/default: #V2Ray_TCP/c \\ #default: #V2Ray_TCP" ${tsp_conf}
  527. sed -i "/handler: proxyPass #V2Ray_TCP/c \\ #handler: proxyPass #V2Ray_TCP" ${tsp_conf}
  528. sed -i "/#V2Ray_TCP_Port/c \\ #args: 127.0.0.1:${v2port};proxyProtocol #V2Ray_TCP_Port:${v2ray_tcp_mode}" ${tsp_conf}
  529. fi
  530. if [[ ${v2ray_ws_mode} = v*ess ]]; then
  531. sed -i "/#V2Ray_WS_Path/c \\ - path: ${v2wspath} #V2Ray_WS_Path" ${tsp_conf}
  532. sed -i "/handler: proxyPass #V2Ray_WS/c \\ handler: proxyPass #V2Ray_WS" ${tsp_conf}
  533. sed -i "/#V2Ray_WS_Port/c \\ args: 127.0.0.1:${v2wsport};proxyProtocol #V2Ray_WS_Port:${v2ray_ws_mode}" ${tsp_conf}
  534. else
  535. sed -i "/#V2Ray_WS_Path/c \\ #- path: ${v2wspath} #V2Ray_WS_Path" ${tsp_conf}
  536. sed -i "/handler: proxyPass #V2Ray_WS/c \\ #handler: proxyPass #V2Ray_WS" ${tsp_conf}
  537. sed -i "/#V2Ray_WS_Port/c \\ #args: 127.0.0.1:${v2wsport};proxyProtocol #V2Ray_WS_Port:${v2ray_ws_mode}" ${tsp_conf}
  538. fi
  539. }
  540. web_camouflage() {
  541. ##Observe que isso está em conflito com o caminho padrão do script LNMP. Não use este script em um ambiente onde o LNMP está instalado, caso contrário, você será responsável pelas consequências.
  542. rm -rf $web_dir
  543. mkdir -p $web_dir
  544. cd $web_dir || exit
  545. websites[0]="https://github.com/h31105/LodeRunner_TotalRecall.git"
  546. websites[1]="https://github.com/h31105/adarkroom.git"
  547. websites[2]="https://github.com/h31105/webosu"
  548. selectedwebsite=${websites[$RANDOM % ${#websites[@]}]}
  549. git clone ${selectedwebsite} web_camouflage
  550. judge "Disfarce de WebSite"
  551. }
  552. install_docker() {
  553. echo -e "${GreenBG} Comece a instalar a versão mais recente do Docker ... ${Font}"
  554. curl -fsSL https://get.docker.com -o /tmp/get-docker.sh
  555. sh /tmp/get-docker.sh
  556. judge "Instale o Docker"
  557. systemctl daemon-reload
  558. systemctl enable docker && systemctl restart docker
  559. judge "Início do Docker"
  560. }
  561. install_tsp() {
  562. bash <(curl -L -s https://raw.githubusercontent.com/liberal-boy/tls-shunt-proxy/master/dist/install.sh)
  563. judge "Instalar TLS-Shunt-Proxy"
  564. chown -R tls-shunt-proxy:tls-shunt-proxy /etc/ssl/tls-shunt-proxy
  565. command -v setcap >/dev/null 2>&1 && setcap "cap_net_bind_service=+ep" /usr/local/bin/tls-shunt-proxy
  566. config_exist_check ${tsp_conf}
  567. [[ -f ${tsp_conf} ]] && rm -rf ${tsp_conf}
  568. mkdir -p $tsp_conf_dir
  569. cat >$tsp_conf <<-EOF
  570. #TSP_CFG_Ver:${tsp_cfg_version}
  571. listen: 0.0.0.0:${tspport} #TSP_Port
  572. redirecthttps: 0.0.0.0:80
  573. inboundbuffersize: 4
  574. outboundbuffersize: 32
  575. vhosts:
  576. - name: ${domain} #TSP_Domain
  577. tlsoffloading: true
  578. managedcert: true
  579. keytype: p256
  580. alpn: h2,http/1.1
  581. protocols: tls12,tls13
  582. http:
  583. paths:
  584. #- path: /trojan/none #Trojan_WS_Path
  585. #handler: proxyPass #Trojan_WS
  586. #args: 127.0.0.1:40000 #Trojan_WS_Port:${trojan_ws_mode}
  587. #- path: /v2ray/none #V2Ray_WS_Path
  588. #handler: proxyPass #V2Ray_WS
  589. #args: 127.0.0.1:40002;proxyProtocol #V2Ray_WS_Port:${v2ray_ws_mode}
  590. handler: fileServer
  591. args: ${web_dir}/web_camouflage #Website_camouflage
  592. #trojan: #Trojan_TCP
  593. #handler: proxyPass #Trojan_TCP
  594. #args: 127.0.0.1:40001 #Trojan_TCP_Port:${trojan_tcp_mode}
  595. #default: #V2Ray_TCP
  596. #handler: proxyPass #V2Ray_TCP
  597. #args: 127.0.0.1:40003;proxyProtocol #V2Ray_TCP_Port:${v2ray_tcp_mode}
  598. EOF
  599. judge "Configurar TLS-Shunt-Proxy"
  600. systemctl daemon-reload && systemctl reset-failed
  601. systemctl enable tls-shunt-proxy && systemctl restart tls-shunt-proxy
  602. judge "Iniciar TLS-Shunt-Proxy"
  603. }
  604. modify_tsp() {
  605. domain_port_check
  606. sed -i "/#TSP_Port/c \\listen: 0.0.0.0:${tspport} #TSP_Port" ${tsp_conf}
  607. sed -i "/#TSP_Domain/c \\ - name: ${domain} #TSP_Domain" ${tsp_conf}
  608. tsp_sync
  609. }
  610. tsp_sync() {
  611. echo -e "${OK} ${GreenBG} Detectar e sincronizar a configuração de proxy existente... ${Font}"
  612. if [[ $trojan_stat = "installed" && -f ${trojan_conf} ]]; then
  613. tjport="$(grep '"local_port"' ${trojan_conf} | sed -r 's/.*: (.*),.*/\1/')" && trojan_tcp_mode=true &&
  614. tjwspath="$(grep '"path":' ${trojan_conf} | awk -F '"' '{print $4}')" && trojan_ws_mode="$(jq -r '.websocket.enabled' ${trojan_conf})"
  615. judge "Detectar a configuração do Trojan-Go"
  616. [[ -z $tjport ]] && trojan_tcp_mode=false
  617. [[ $trojan_ws_mode = null ]] && trojan_ws_mode=false
  618. [[ -z $tjwspath ]] && tjwspath=/trojan/none
  619. echo -e "Detectado: proxy Trojan-Go:TCP:${Green}${trojan_tcp_mode}${Font} / WebSocket:${Green}${trojan_ws_mode}${Font} / porta:${Green}${tjport}${Font} / WebSocket Path:${Green}${tjwspath}${Font}"
  620. fi
  621. if [[ $v2ray_stat = "installed" && -f ${v2ray_conf} ]]; then
  622. sed -i '/\#\"/d' ${v2ray_conf}
  623. v2port="$(jq -r '[.inbounds[] | select(.streamSettings.network=="tcp") | .port][0]' ${v2ray_conf})" &&
  624. v2wsport="$(jq -r '[.inbounds[] | select(.streamSettings.network=="ws") | .port][0]' ${v2ray_conf})" &&
  625. v2ray_tcp_mode="$(jq -r '[.inbounds[] | select(.streamSettings.network=="tcp") | .protocol][0]' ${v2ray_conf})" &&
  626. v2ray_ws_mode="$(jq -r '[.inbounds[] | select(.streamSettings.network=="ws") | .protocol][0]' ${v2ray_conf})" &&
  627. v2wspath="$(jq -r '[.inbounds[] | select(.streamSettings.network=="ws") | .streamSettings.wsSettings.path][0]' ${v2ray_conf})"
  628. judge "Verifique a configuração V2Ray"
  629. [[ $v2port = null ]] && v2port=40003
  630. [[ $v2wsport = null ]] && v2wsport=40002
  631. [[ $v2ray_tcp_mode = null ]] && v2ray_tcp_mode=none
  632. [[ $v2ray_ws_mode = null ]] && v2ray_ws_mode=none
  633. [[ $v2wspath = null ]] && v2wspath=/v2ray/none
  634. echo -e "Detectado: proxy V2Ray:TCP:${Green}${v2ray_tcp_mode}${Font} porta:${Green}${v2port}${Font} / WebSocket:${Green}${v2ray_ws_mode}${Font} porta:${Green}${v2wsport}${Font} / WebSocket Path:${Green}${v2wspath}${Font}"
  635. fi
  636. if [[ -f ${tsp_conf} ]]; then
  637. trojan_sync
  638. v2ray_sync
  639. tsp_config_stat="synchronized"
  640. systemctl restart tls-shunt-proxy
  641. judge "Sincronização de configuração de shunt"
  642. menu_req_check tls-shunt-proxy
  643. else
  644. echo -e "${Error} ${RedBG} A configuração TLS-Shunt-Proxy está anormal, reinstale e tente novamente ${Font}"
  645. exit 4
  646. fi
  647. }
  648. install_trojan() {
  649. systemctl is-active "docker" &>/dev/null || install_docker
  650. prereqcheck
  651. trojan_reset
  652. docker pull teddysun/trojan-go
  653. docker run -d --network host --name Trojan-Go --restart=always -v /etc/trojan-go:/etc/trojan-go teddysun/trojan-go
  654. judge "Instalação do contêiner Trojan-Go"
  655. }
  656. install_v2ray() {
  657. systemctl is-active "docker" &>/dev/null || install_docker
  658. prereqcheck
  659. v2ray_mode_type
  660. [[ $v2ray_tcp_mode = "vmess" || $v2ray_ws_mode = "vmess" ]] && check_system && chrony_install
  661. if [[ $v2ray_tcp_mode != "none" || $v2ray_ws_mode != "none" ]]; then
  662. v2ray_reset
  663. docker pull teddysun/v2ray
  664. docker run -d --network host --name V2Ray --restart=always -v /etc/v2ray:/etc/v2ray teddysun/v2ray
  665. judge "Instalação do contêiner V2Ray"
  666. fi
  667. }
  668. install_watchtower() {
  669. docker pull containrrr/watchtower
  670. docker run -d --name WatchTower --restart=always -v /var/run/docker.sock:/var/run/docker.sock containrrr/watchtower --cleanup
  671. judge "Instalação do contêiner WatchTower"
  672. }
  673. install_portainer() {
  674. docker volume create portainer_data
  675. docker pull portainer/portainer-ce
  676. docker run -d -p 9080:9000 --name Portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce
  677. judge "Instalação do contêiner Portainer"
  678. echo -e "${OK} ${GreenBG} O endereço de gerenciamento do Portainer é http://$TSP_Domain:9080 Abra você mesmo a porta do firewall! ${Font}"
  679. }
  680. install_tls_shunt_proxy() {
  681. check_system
  682. systemctl is-active "firewalld" &>/dev/null && systemctl stop firewalld && echo -e "${OK} ${GreenBG} Firewalld está desligado ${Font}"
  683. systemctl is-active "ufw" &>/dev/null && systemctl stop ufw && echo -e "${OK} ${GreenBG} UFW está fechado ${Font}"
  684. dependency_install
  685. basic_optimization
  686. domain_port_check
  687. port_exist_check "${tspport}"
  688. port_exist_check 80
  689. config_exist_check "${tsp_conf}"
  690. web_camouflage
  691. install_tsp
  692. }
  693. uninstall_all() {
  694. echo -e "${RedBG} !!!Esta operação excluirá TLS-Shunt-Proxy, plataforma Docker e os dados do contêiner instalados por este script!!! ${Font}"
  695. read -rp "Depois de confirmar, digite YES (diferencia maiúsculas de minúsculas):" uninstall
  696. [[ -z ${uninstall} ]] && uninstall="No"
  697. case $uninstall in
  698. YES)
  699. echo -e "${GreenBG} Comece a desinstalação ${Font}"
  700. sleep 2
  701. ;;
  702. *)
  703. echo -e "${RedBG} deixe-me pensar de novo ${Font}"
  704. exit 1
  705. ;;
  706. esac
  707. check_system
  708. uninstall_proxy_server
  709. uninstall_watchtower
  710. uninstall_portainer
  711. systemctl stop docker && systemctl disable docker
  712. if [[ "${ID}" == "centos" ]]; then
  713. ${INS} remove docker-ce docker-ce-cli containerd.io docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine
  714. else
  715. ${INS} remove docker-ce docker-ce-cli containerd.io docker docker-engine docker.io containerd runc
  716. fi
  717. #rm -rf /var/lib/docker #Removes all docker data
  718. rm -rf /etc/systemd/system/docker.service
  719. uninstall_tsp
  720. echo -e "${OK} ${GreenBG} Todos os componentes foram desinstalados, bem-vindo para usar este script novamente! ${Font}"
  721. exit 0
  722. }
  723. uninstall_tsp() {
  724. systemctl stop tls-shunt-proxy && systemctl disable tls-shunt-proxy
  725. rm -rf /etc/systemd/system/tls-shunt-proxy.service
  726. rm -rf /usr/local/bin/tls-shunt-proxy
  727. rm -rf $tsp_conf_dir
  728. userdel -rf tls-shunt-proxy
  729. tsp_stat="none"
  730. rm -rf ${web_dir}/web_camouflage
  731. echo -e "${OK} ${GreenBG} Desinstalação do TLS-Shunt-Proxy concluída!${Font}"
  732. sleep 3
  733. }
  734. uninstall_proxy_server() {
  735. uninstall_trojan
  736. uninstall_v2ray
  737. echo -e "${OK} ${GreenBG} A desinstalação do proxy TCP / WS (Trojan-Go / V2Ray) está concluída! ${Font}"
  738. sleep 3
  739. }
  740. uninstall_trojan() {
  741. rm -rf $trojan_conf_dir
  742. trojan_ws_mode="none" && trojan_tcp_mode="none"
  743. [ -f ${tsp_conf} ] && trojan_sync
  744. systemctl start docker
  745. [[ $trojan_stat = "installed" ]] && docker stop Trojan-Go && docker rm -f Trojan-Go &&
  746. echo -e "${OK} ${GreenBG} A desinstalação do proxy TCP / WS Trojan-Go foi concluída! ${Font}"
  747. }
  748. uninstall_v2ray() {
  749. rm -rf $v2ray_conf_dir
  750. v2ray_ws_mode="none" && v2ray_tcp_mode="none"
  751. [ -f ${tsp_conf} ] && v2ray_sync
  752. systemctl start docker
  753. [[ $v2ray_stat = "installed" ]] && docker stop V2Ray && docker rm -f V2Ray &&
  754. echo -e "${OK} ${GreenBG} Desinstalação do proxy TCP / WS V2Ray concluída! ${Font}"
  755. }
  756. uninstall_watchtower() {
  757. docker stop WatchTower && docker rm -f WatchTower && watchtower_stat="none" &&
  758. echo -e "${OK} ${GreenBG} Desinstalação da WatchTower concluída! ${Font}"
  759. sleep 3
  760. }
  761. uninstall_portainer() {
  762. docker stop Portainer && docker rm -fv Portainer && portainer_stat="none" &&
  763. echo -e "${OK} ${GreenBG} Desinstalação do Portainer concluída! ${Font}"
  764. sleep 3
  765. }
  766. upgrade_tsp() {
  767. current_version="$(/usr/local/bin/tls-shunt-proxy --version 2>&1 | awk 'NR==1{gsub(/"/,"");print $3}')"
  768. echo -e "${GreenBG} Versão atual do TLS-Shunt-Proxy: ${current_version},Comece a testar a versão mais recente... ${Font}"
  769. latest_version="$(wget --no-check-certificate -qO- https://api.github.com/repos/liberal-boy/tls-shunt-proxy/tags | grep 'name' | cut -d\" -f4 | head -1)"
  770. [[ -z ${latest_version} ]] && echo -e "${Error} Falha ao detectar a versão mais recente ! ${Font}" && menu
  771. if [[ ${latest_version} != "${current_version}" ]]; then
  772. echo -e "${OK} ${GreenBG} Versão Atual: ${current_version} A última versão de: ${latest_version},Atualizar (Y/N) [N]? ${Font}"
  773. read -r update_confirm
  774. [[ -z ${update_confirm} ]] && update_confirm="No"
  775. case $update_confirm in
  776. [yY][eE][sS] | [yY])
  777. config_exist_check "${tsp_conf}"
  778. bash <(curl -L -s https://raw.githubusercontent.com/liberal-boy/tls-shunt-proxy/master/dist/install.sh)
  779. judge "Atualização TLS-Shunt-Proxy"
  780. systemctl daemon-reload && systemctl reset-failed
  781. systemctl enable tls-shunt-proxy && systemctl restart tls-shunt-proxy
  782. judge "Reinicialização de TLS-Shunt-Proxy"
  783. ;;
  784. *) ;;
  785. esac
  786. else
  787. echo -e "${OK} ${GreenBG} O TLS-Shunt-Proxy atual é a versão mais recente ${current_version} ${Font}"
  788. fi
  789. }
  790. update_sh() {
  791. command -v curl >/dev/null 2>&1 || ${INS} install curl
  792. judge "Instalar pacote de dependência curl"
  793. ol_version=$(curl -L -s https://raw.githubusercontent.com/h31105/trojan_v2_docker_onekey/${github_branch}/deploy.sh | grep "shell_version=" | head -1 | awk -F '=|"' '{print $3}')
  794. echo "$ol_version" >$version_cmp
  795. echo "$shell_version" >>$version_cmp
  796. if [[ "$shell_version" < "$(sort -rV $version_cmp | head -1)" ]]; then
  797. echo -e "${OK} ${GreenBG} atualizar conteúdo:${Font}"
  798. echo -e "${Yellow}$(curl --silent https://api.github.com/repos/h31105/trojan_v2_docker_onekey/releases/latest | grep body | head -n 1 | awk -F '"' '{print $4}')${Font}"
  799. echo -e "${OK} ${GreenBG} Há uma nova versão, seja para atualizar (Y/N) [N]? ${Font}"
  800. read -r update_confirm
  801. case $update_confirm in
  802. [yY][eE][sS] | [yY])
  803. wget -N --no-check-certificate https://raw.githubusercontent.com/h31105/trojan_v2_docker_onekey/${github_branch}/deploy.sh
  804. echo -e "${OK} ${GreenBG} A atualização está concluída, execute novamente o script:\n#./deploy.sh ${Font}"
  805. exit 0
  806. ;;
  807. *) ;;
  808. esac
  809. else
  810. echo -e "${OK} ${GreenBG} A versão atual é a versão mais recente ${Font}"
  811. fi
  812. }
  813. list() {
  814. case $1 in
  815. uninstall)
  816. deployed_status_check
  817. uninstall_all
  818. ;;
  819. sync)
  820. deployed_status_check
  821. tsp_sync
  822. ;;
  823. debug)
  824. debug="enable"
  825. #set -xv
  826. menu
  827. ;;
  828. *)
  829. menu
  830. ;;
  831. esac
  832. }
  833. deployed_status_check() {
  834. tsp_stat="none" && trojan_stat="none" && v2ray_stat="none" && watchtower_stat="none" && portainer_stat="none"
  835. trojan_tcp_mode="none" && v2ray_tcp_mode="none" && trojan_ws_mode="none" && v2ray_ws_mode="none"
  836. tsp_config_stat="synchronized" && chrony_stat="none"
  837. echo -e "${OK} ${GreenBG} Informações de configuração do shunt de detecção... ${Font}"
  838. [[ -f ${tsp_conf} || -f '/usr/local/bin/tls-shunt-proxy' ]] &&
  839. tsp_template_version=$(grep '#TSP_CFG_Ver' ${tsp_conf} | sed -r 's/.*TSP_CFG_Ver:(.*) */\1/') && tsp_stat="installed" &&
  840. TSP_Port=$(grep '#TSP_Port' ${tsp_conf} | sed -r 's/.*0:(.*) #.*/\1/') && TSP_Domain=$(grep '#TSP_Domain' ${tsp_conf} | sed -r 's/.*: (.*) #.*/\1/') &&
  841. trojan_tcp_port=$(grep '#Trojan_TCP_Port' ${tsp_conf} | sed -r 's/.*:(.*) #.*/\1/') &&
  842. trojan_tcp_mode=$(grep '#Trojan_TCP_Port' ${tsp_conf} | sed -r 's/.*Trojan_TCP_Port:(.*) */\1/') &&
  843. trojan_ws_port=$(grep '#Trojan_WS_Port' ${tsp_conf} | sed -r 's/.*:(.*) #.*/\1/') &&
  844. trojan_ws_mode=$(grep '#Trojan_WS_Port' ${tsp_conf} | sed -r 's/.*Trojan_WS_Port:(.*) */\1/') &&
  845. trojan_ws_path=$(grep '#Trojan_WS_Path' ${tsp_conf} | sed -r 's/.*: (.*) #.*/\1/') &&
  846. v2ray_tcp_port=$(grep '#V2Ray_TCP_Port' ${tsp_conf} | sed -r 's/.*:(.*);.*/\1/') &&
  847. v2ray_tcp_mode=$(grep '#V2Ray_TCP_Port' ${tsp_conf} | sed -r 's/.*V2Ray_TCP_Port:(.*) */\1/') &&
  848. v2ray_ws_port=$(grep '#V2Ray_WS_Port' ${tsp_conf} | sed -r 's/.*:(.*);.*/\1/') &&
  849. v2ray_ws_mode=$(grep '#V2Ray_WS_Port' ${tsp_conf} | sed -r 's/.*V2Ray_WS_Port:(.*) */\1/') &&
  850. v2ray_ws_path=$(grep '#V2Ray_WS_Path' ${tsp_conf} | sed -r 's/.*: (.*) #.*/\1/') &&
  851. menu_req_check tls-shunt-proxy
  852. echo -e "${OK} ${GreenBG} Verifique o status de implantação do componente... ${Font}"
  853. systemctl is-active "docker" &>/dev/null && docker ps -a | grep Trojan-Go &>/dev/null && trojan_stat="installed"
  854. systemctl is-active "docker" &>/dev/null && docker ps -a | grep V2Ray &>/dev/null && v2ray_stat="installed"
  855. systemctl is-active "docker" &>/dev/null && docker ps -a | grep WatchTower &>/dev/null && watchtower_stat="installed"
  856. systemctl is-active "docker" &>/dev/null && docker ps -a | grep Portainer &>/dev/null && portainer_stat="installed"
  857. echo -e "${OK} ${GreenBG} Informações de configuração do agente de detecção... ${Font}"
  858. if [[ -f ${trojan_conf} && $trojan_stat = "installed" ]]; then
  859. tjport=$(grep '"local_port"' ${trojan_conf} | sed -r 's/.*: (.*),.*/\1/')
  860. tjpassword=$(grep '"password"' ${trojan_conf} | awk -F '"' '{print $4}')
  861. [[ $trojan_ws_mode = true ]] && tjwspath=$(grep '"path":' ${trojan_conf} | awk -F '"' '{print $4}') &&
  862. tjwshost=$(grep '"host":' ${trojan_conf} | awk -F '"' '{print $4}')
  863. [[ $trojan_tcp_mode = true && $tjport != "$trojan_tcp_port" ]] && echo -e "${Error} ${RedBG} Detectada anormalidade na configuração do shunt da porta TCP do Trojan-Go ${Font}" && tsp_config_stat="mismatched"
  864. [[ $trojan_ws_mode = true && $tjport != "$trojan_ws_port" ]] && echo -e "${Error} ${RedBG} Detectada anormalidade de configuração de shunt de porta Trojan-Go WS ${Font}" && tsp_config_stat="mismatched"
  865. [[ $trojan_ws_mode = true && $tjwspath != "$trojan_ws_path" ]] && echo -e "${Error} ${RedBG} 检测到 Trojan-Go WS 路径分流配置异常 ${Font}" && tsp_config_stat="mismatched"
  866. [[ $tsp_config_stat = "mismatched" ]] && echo -e "${Error} ${RedBG} Uma configuração de shunt inconsistente é detectada e tentará sincronizar e reparar automaticamente... ${Font}" && tsp_sync
  867. fi
  868. if [[ -f ${v2ray_conf} && $v2ray_stat = "installed" ]]; then
  869. [[ $v2ray_tcp_mode = "vmess" ]] &&
  870. v2port=$(jq -r '[.inbounds[] | select(.protocol=="vmess") | select(.streamSettings.network=="tcp") | .port][0]' ${v2ray_conf}) &&
  871. VMTID=$(jq -r '[.inbounds[] | select(.protocol=="vmess") | select(.streamSettings.network=="tcp") | .settings.clients[].id][0]' ${v2ray_conf}) &&
  872. VMAID=$(jq -r '[.inbounds[] | select(.protocol=="vmess") | select(.streamSettings.network=="tcp") | .settings.clients[].alterId][0]' ${v2ray_conf})
  873. [[ $v2ray_tcp_mode = "vless" ]] &&
  874. v2port=$(jq -r '[.inbounds[] | select(.protocol=="vless") | select(.streamSettings.network=="tcp") | .port][0]' ${v2ray_conf}) &&
  875. VLTID=$(jq -r '[.inbounds[] | select(.protocol=="vless") | select(.streamSettings.network=="tcp") | .settings.clients[].id][0]' ${v2ray_conf})
  876. [[ $v2ray_ws_mode = "vmess" ]] &&
  877. v2wsport=$(jq -r '[.inbounds[] | select(.protocol=="vmess") | select(.streamSettings.network=="ws") | .port][0]' ${v2ray_conf}) &&
  878. v2wspath=$(jq -r '[.inbounds[] | select(.protocol=="vmess") | select(.streamSettings.network=="ws") | .streamSettings.wsSettings.path][0]' ${v2ray_conf}) &&
  879. VMWSID=$(jq -r '[.inbounds[] | select(.protocol=="vmess") | select(.streamSettings.network=="ws") | .settings.clients[].id][0]' ${v2ray_conf}) &&
  880. VMWSAID=$(jq -r '[.inbounds[] | select(.protocol=="vmess") | select(.streamSettings.network=="ws") | .settings.clients[].alterId][0]' ${v2ray_conf})
  881. [[ $v2ray_ws_mode = "vless" ]] &&
  882. v2wsport=$(jq -r '[.inbounds[] | select(.protocol=="vless") | select(.streamSettings.network=="ws") | .port][0]' ${v2ray_conf}) &&
  883. v2wspath=$(jq -r '[.inbounds[] | select(.protocol=="vless") | select(.streamSettings.network=="ws") | .streamSettings.wsSettings.path][0]' ${v2ray_conf}) &&
  884. VLWSID=$(jq -r '[.inbounds[] | select(.protocol=="vless") | select(.streamSettings.network=="ws") | .settings.clients[].id][0]' ${v2ray_conf})
  885. [[ $v2ray_tcp_mode = v*ess && $v2port != "$v2ray_tcp_port" ]] && echo -e "${Error} ${RedBG} Detectada anormalidade de configuração de shunt da porta TCP V2Ray ${Font}" && tsp_config_stat="mismatched"
  886. [[ $v2ray_ws_mode = v*ess && $v2wsport != "$v2ray_ws_port" ]] && echo -e "${Error} ${RedBG} Anormalidade de configuração de shunt de porta V2Ray WS detectada ${Font}" && tsp_config_stat="mismatched"
  887. [[ $v2ray_ws_mode = v*ess && $v2wspath != "$v2ray_ws_path" ]] && echo -e "${Error} ${RedBG} Anormalidade de configuração de shunt de caminho V2Ray WS detectada ${Font}" && tsp_config_stat="mismatched"
  888. [[ $tsp_config_stat = "mismatched" ]] && echo -e "${Error} ${RedBG} Uma configuração de shunt inconsistente é detectada e tentará sincronizar e reparar automaticamente... ${Font}" && tsp_sync
  889. if [[ $v2ray_tcp_mode = "vmess" || $v2ray_ws_mode = "vmess" ]]; then
  890. if [[ "${ID}" == "centos" ]]; then
  891. systemctl is-active "chronyd" &>/dev/null || chrony_stat=inactive
  892. else
  893. systemctl is-active "chrony" &>/dev/null || chrony_stat=inactive
  894. fi
  895. if [[ $chrony_stat = inactive ]]; then
  896. echo -e "${Error} ${RedBG} Foi detectado que o serviço de sincronização de tempo Chrony não foi iniciado. Se a hora do sistema for imprecisa, isso afetará seriamente a disponibilidade do protocolo V2Ray VMess ${Font}\n${WARN} ${Yellow} 当前系统时间: $(date),请确认时间是否准确,误差范围±3分钟内(Y)或 尝试修复时间同步服务(R)[R]: ${Font}"
  897. read -r chrony_confirm
  898. [[ -z ${chrony_confirm} ]] && chrony_confirm="R"
  899. case $chrony_confirm in
  900. [rR])
  901. echo -e "${GreenBG} Instale o serviço de sincronização de tempo Chrony ${Font}"
  902. check_system
  903. chrony_install
  904. ;;
  905. *) ;;
  906. esac
  907. fi
  908. fi
  909. fi
  910. [[ -f ${trojan_conf} || -f ${v2ray_conf} || $trojan_stat = "installed" || $v2ray_stat = "installed" ]] && menu_req_check docker
  911. [[ $trojan_stat = "installed" && ! -f $trojan_conf ]] && echo -e "\n${Error} ${RedBG} Foi detectada anormalidade na configuração do proxy Trojan-Go, as seguintes opções serão bloqueadas, tente reinstalar o reparo e tente novamente ... ${Font}" &&
  912. echo -e "${WARN} ${Yellow}[Shield] Modificação da configuração do Trojan-Go${Font}"
  913. [[ $v2ray_stat = "installed" && ! -f $v2ray_conf ]] && echo -e "\n${Error} ${RedBG} Foi detectada anormalidade na configuração do proxy V2Ray, as seguintes opções serão bloqueadas, tente reinstalar e tente novamente... ${Font}" &&
  914. echo -e "${WARN} ${Yellow}[Shield] Modificação da configuração V2Ray${Font}"
  915. if [[ $tsp_stat = "installed" && $tsp_template_version != "${tsp_cfg_version}" ]]; then
  916. echo -e "${WARN} ${Yellow}Foi detectada uma atualização crítica de TLS-Shunt-Proxy. Para garantir que o script seja executado normalmente, confirme para realizar a atualização imediatamente(Y/N)[Y] ${Font}"
  917. read -r upgrade_confirm
  918. [[ -z ${upgrade_confirm} ]] && upgrade_confirm="Yes"
  919. case $upgrade_confirm in
  920. [yY][eE][sS] | [yY])
  921. uninstall_tsp
  922. install_tls_shunt_proxy
  923. tsp_sync
  924. deployed_status_check
  925. ;;
  926. *) ;;
  927. esac
  928. fi
  929. [[ $debug = "enable" ]] && echo -e "\n Proxy Trojan-Go:TCP:${Green}${trojan_tcp_mode}${Font} / WebSocket:${Green}${trojan_ws_mode}${Font}\n Proxy V2Ray:TCP:${Green}${v2ray_tcp_mode}${Font} / WebSocket:${Green}${v2ray_ws_mode}${Font}" &&
  930. echo -e "\n Recipiente do agente: Trojan-Go:${Green}${trojan_stat}${Font} / V2Ray:${Green}${v2ray_stat}${Font}" &&
  931. echo -e " Outros recipientes: WatchTower:${Green}${watchtower_stat}${Font} / Portainer:${Green}${portainer_stat}${Font}\n"
  932. }
  933. info_config() {
  934. deployed_status_check
  935. cert_stat_check tls-shunt-proxy
  936. echo -e "\n————————————————————Informações de configuração do shunt————————————————————"
  937. if [ -f ${tsp_conf} ]; then
  938. echo -e "TLS-Shunt-Proxy $(/usr/local/bin/tls-shunt-proxy --version 2>&1 | awk 'NR==1{gsub(/"/,"");print $3}')" &&
  939. echo -e "Porta TLS do servidor: ${TSP_Port}" && echo -e "Nome de domínio TLS do servidor: ${TSP_Domain}"
  940. [[ $trojan_tcp_mode = true ]] && echo -e "Porta de descarregamento de TCP Trojan-Go: $trojan_tcp_port" && echo -e "Porta de escuta Trojan-Go: $tjport"
  941. [[ $trojan_ws_mode = true ]] && echo -e "Porta de toque Trojan-Go WebSocket: $trojan_ws_port" &&
  942. echo -e "Caminho de descarregamento do Trojan-Go WebSocket: $trojan_ws_path"
  943. [[ $v2ray_tcp_mode = v*ess ]] && echo -e "Porta shunt V2Ray TCP: $v2ray_tcp_port" && echo -e "Porta de escuta V2Ray TCP: $v2port"
  944. [[ $v2ray_ws_mode = v*ess ]] && echo -e "Porta de derivação V2Ray WebSocket: $v2ray_ws_port" && echo -e "Porta de escuta V2Ray WS: $v2wsport" &&
  945. echo -e "Caminho de shunt V2Ray WebSocket: $v2ray_ws_path"
  946. fi
  947. if [[ -f ${trojan_conf} && $trojan_stat = "installed" ]]; then
  948. echo -e "—————————————————— Implantação do Trojan-Go ——————————————————" &&
  949. echo -e "$(docker exec Trojan-Go sh -c 'trojan-go --version' 2>&1 | awk 'NR==1{gsub(/"/,"");print}')" &&
  950. echo -e "Porta do servidor: ${TSP_Port}" && echo -e "Endereço do servidor:: ${TSP_Domain}"
  951. [[ $trojan_tcp_mode = true ]] && echo -e "Senha do Trojan-Go: ${tjpassword}"
  952. [[ $trojan_ws_mode = true ]] &&
  953. echo -e "Trojan-Go WebSocket Path: ${tjwspath}" && echo -e "Trojan-Go WebSocket Host: ${tjwshost}"
  954. fi
  955. if [[ -f ${v2ray_conf} && $v2ray_stat = "installed" ]]; then
  956. echo -e "\n———————————————————— Configuração V2Ray ————————————————————" &&
  957. echo -e "$(docker exec V2Ray sh -c 'v2ray --version' 2>&1 | awk 'NR==1{gsub(/"/,"");print}')" &&
  958. echo -e "Porta do servidor: ${TSP_Port}" && echo -e "Endereço do servidor:: ${TSP_Domain}"
  959. [[ $v2ray_tcp_mode = "vmess" ]] && echo -e "\nVMess TCP UUID: ${VMTID}" &&
  960. echo -e "VMess AlterID: ${VMAID}" && echo -e "Método de criptografia VMess: Auto" && echo -e "VMess Host: ${TSP_Domain}"
  961. [[ $v2ray_tcp_mode = "vless" ]] && echo -e "\nVLESS TCP UUID: ${VLTID}" &&
  962. echo -e "Método de criptografia VLESS: none" && echo -e "VLESS Host: ${TSP_Domain}"
  963. [[ $v2ray_ws_mode = "vmess" ]] && echo -e "\nVMess WS UUID: ${VMWSID}" && echo -e "VMess AlterID: $VMWSAID" &&
  964. echo -e "Método de criptografia VMess: Auto" && echo -e "VMess WebSocket Host: ${TSP_Domain}" && echo -e "VMess WebSocket Path: ${v2wspath}"
  965. [[ $v2ray_ws_mode = "vless" ]] && echo -e "\nVLESS WS UUID: ${VLWSID}" &&
  966. echo -e "Método de criptografia VLESS: none" && echo -e "VLESS WebSocket Host: ${TSP_Domain}" && echo -e "VLESS WebSocket Path: ${v2wspath}"
  967. fi
  968. echo -e "————————————————————————————————————————————————————\n"
  969. read -t 60 -n 1 -s -rp "Pressione qualquer tecla para continuar(60s)..."
  970. clear
  971. }
  972. info_links() {
  973. deployed_status_check
  974. cert_stat_check tls-shunt-proxy
  975. if [[ -f ${trojan_conf} && $trojan_stat = "installed" ]]; then
  976. echo -e "———————————————— Link de compartilhamento do Trojan-Go ————————————————" &&
  977. [[ $trojan_tcp_mode = true ]] && echo -e "\n Link de compartilhamento TLS do Trojan-Go TCP:" &&
  978. echo -e " ${Yellow}Cliente Trojan:${Font}\n trojan://${tjpassword}@${TSP_Domain}:${TSP_Port}?sni=${TSP_Domain}&allowinsecure=0&mux=0#${HOSTNAME}-TCP" &&
  979. echo ""
  980. echo -e " ${Yellow}Cliente Qv2ray (plug-in trojan-go necessário) :${Font}\n trojan-go://${tjpassword}@${TSP_Domain}:${TSP_Port}/?sni=${TSP_Domain}&type=original&host=${TSP_Domain}#${HOSTNAME}-TCP" &&
  981. echo ""
  982. echo -e " ${Yellow}Código QR Shadowrocket:" &&
  983. qrencode -t ANSIUTF8 -s 1 -m 2 "trojan://${tjpassword}@${TSP_Domain}:${TSP_Port}?sni=${TSP_Domain}&peer=${TSP_Domain}&allowinsecure=0&mux=0#${HOSTNAME}-TCP"
  984. [[ $trojan_ws_mode = true ]] && echo -e "\n Link de compartilhamento Trojan-Go WebSocket TLS:" &&
  985. echo -e " ${Yellow}Cliente Trojan-Qt5:${Font}\n trojan://${tjpassword}@${TSP_Domain}:${TSP_Port}?sni=${TSP_Domain}&peer=${TSP_Domain}&allowinsecure=0&mux=1&ws=1&wspath=${tjwspath}&wshost=${TSP_Domain}#${HOSTNAME}-WS" &&
  986. echo ""
  987. echo -e " ${Yellow}Cliente Qv2ray (plug-in trojan-go necessário) :${Font}\n trojan-go://${tjpassword}@${TSP_Domain}:${TSP_Port}/?sni=${TSP_Domain}&type=ws&host=${TSP_Domain}&path=${tjwspath}#${HOSTNAME}-WS" &&
  988. echo ""
  989. echo -e " ${Yellow}Código QR Shadowrocket:" &&
  990. qrencode -t ANSIUTF8 -s 1 -m 2 "trojan://${tjpassword}@${TSP_Domain}:${TSP_Port}?peer=${TSP_Domain}&mux=1&plugin=obfs-local;obfs=websocket;obfs-host=${TSP_Domain};obfs-uri=${tjwspath}#${HOSTNAME}-WS"
  991. read -t 60 -n 1 -s -rp "Pressione qualquer tecla para continuar(60s)..."
  992. fi
  993. if [[ -f ${v2ray_conf} && $v2ray_stat = "installed" ]]; then
  994. echo -e "\n—————————————————— V2Ray compartilhar link ——————————————————" &&
  995. [[ $v2ray_tcp_mode = "vmess" ]] && echo -e "\n VMess TCP TLS compartilhar link:" &&
  996. echo -e " Formato V2RayN:\n vmess://$(echo "{\"add\":\"${TSP_Domain}\",\"aid\":\"0\",\"host\":\"${TSP_Domain}\",\"peer\":\"${TSP_Domain}\",\"id\":\"${VMTID}\",\"net\":\"tcp\",\"port\":\"${TSP_Port}\",\"ps\":\"${HOSTNAME}-TCP\",\"tls\":\"tls\",\"type\":\"none\",\"v\":\"2\"}" | base64 -w 0)" &&
  997. echo -e " Novo formato de VMess:\n vmess://tcp+tls:${VMTID}-0@${TSP_Domain}:${TSP_Port}/?tlsServerName=${TSP_Domain}#$(urlEncode "${HOSTNAME}-TCP")" &&
  998. echo -e " Código QR Shadowrocket:" &&
  999. qrencode -t ANSIUTF8 -s 1 -m 2 "vmess://$(echo "auto:${VMTID}@${TSP_Domain}:${TSP_Port}" | base64 -w 0)?tls=1&mux=1&peer=${TSP_Domain}&allowInsecure=0&tfo=0&remarks=${HOSTNAME}-TCP"
  1000. [[ $v2ray_ws_mode = "vmess" ]] && echo -e "\n Link de compartilhamento VMess WebSocket TLS:" &&
  1001. echo -e " Formato V2RayN:\n vmess://$(echo "{\"add\":\"${TSP_Domain}\",\"aid\":\"0\",\"host\":\"${TSP_Domain}\",\"peer\":\"${TSP_Domain}\",\"id\":\"${VMWSID}\",\"net\":\"ws\",\"path\":\"${v2wspath}\",\"port\":\"${TSP_Port}\",\"ps\":\"${HOSTNAME}-WS\",\"tls\":\"tls\",\"type\":\"none\",\"v\":\"2\"}" | base64 -w 0)" &&
  1002. echo -e " Novo formato de VMess:\n vmess://ws+tls:${VMWSID}-0@${TSP_Domain}:${TSP_Port}/?path=$(urlEncode "${v2wspath}")&host=${TSP_Domain}&tlsServerName=${TSP_Domain}#$(urlEncode "${HOSTNAME}-WS")" &&
  1003. echo -e " Código QR Shadowrocket:" &&
  1004. qrencode -t ANSIUTF8 -s 1 -m 2 "vmess://$(echo "auto:${VMWSID}@${TSP_Domain}:${TSP_Port}" | base64 -w 0)?tls=1&mux=1&peer=${TSP_Domain}&allowInsecure=0&tfo=0&remarks=${HOSTNAME}-WS&obfs=websocket&obfsParam=${TSP_Domain}&path=${v2wspath}"
  1005. [[ $v2ray_tcp_mode = "vless" ]] && echo -e "\n VLESS TCP TLS compartilhar link:" &&
  1006. echo -e " Novo formato VLESS:\n vless://${VLTID}@${TSP_Domain}:${TSP_Port}?security=tls&sni=${TSP_Domain}#$(urlEncode "${HOSTNAME}-TCP")"
  1007. [[ $v2ray_ws_mode = "vless" ]] && echo -e "\n VLESS WebSocket TLS compartilhar link:" &&
  1008. echo -e " Novo formato VLESS:\n vless://${VLWSID}@${TSP_Domain}:${TSP_Port}?type=ws&security=tls&host=${TSP_Domain}&path=$(urlEncode "${v2wspath}")&sni=${TSP_Domain}#$(urlEncode "${HOSTNAME}-WS")"
  1009. read -t 60 -n 1 -s -rp "Pressione qualquer tecla para continuar(60s)..."
  1010. fi
  1011. if [[ -f ${v2ray_conf} || -f ${trojan_conf} ]]; then
  1012. echo -e "\n——————————————————— Inscreva-se para obter informações sobre o link ———————————————————"
  1013. rm -rf "$(grep '#Website' ${tsp_conf} | sed -r 's/.*: (.*) #.*/\1/')"/subscribe*
  1014. cat >"$(grep '#Website' ${tsp_conf} | sed -r 's/.*: (.*) #.*/\1/')"/robots.txt <<-EOF
  1015. User-agent: *
  1016. Disallow: /
  1017. EOF
  1018. subscribe_file="$(head -n 10 /dev/urandom | md5sum | head -c ${random_num})"
  1019. subscribe_links | base64 -w 0 >"$(grep '#Website' ${tsp_conf} | sed -r 's/.*: (.*) #.*/\1/')"/subscribe"${subscribe_file}"
  1020. echo -e "Link de inscrição:\n https://${TSP_Domain}/subscribe${subscribe_file} \n${Yellow}Observação: O link de inscrição gerado pelo script contém todas as informações de configuração do protocolo proxy atualmente implantadas no servidor. Para considerações de segurança da informação, o endereço do link será atualizado aleatoriamente sempre que você visualizá-lo!!\nAlém disso, como diferentes clientes têm diferentes graus de compatibilidade e suporte para o protocolo de proxy, ajuste-se de acordo com a situação real!${Font}"
  1021. read -t 60 -n 1 -s -rp "Pressione qualquer tecla para continuar(60s)..."
  1022. fi
  1023. clear
  1024. }
  1025. subscribe_links() {
  1026. if [[ -f ${trojan_conf} && $trojan_stat = "installed" ]]; then
  1027. [[ $trojan_tcp_mode = true ]] &&
  1028. echo -e "trojan://${tjpassword}@${TSP_Domain}:${TSP_Port}?sni=${TSP_Domain}&peer=${TSP_Domain}&allowinsecure=0&mux=0#${HOSTNAME}-TCP" &&
  1029. echo -e "trojan-go://${tjpassword}@${TSP_Domain}:${TSP_Port}/?sni=${TSP_Domain}&type=original&host=${TSP_Domain}#${HOSTNAME}-Trojan-Go-TCP"
  1030. [[ $trojan_ws_mode = true ]] &&
  1031. echo -e "trojan-go://${tjpassword}@${TSP_Domain}:${TSP_Port}/?sni=${TSP_Domain}&type=ws&host=${TSP_Domain}&path=${tjwspath}#${HOSTNAME}-Trojan-Go-WS" &&
  1032. echo -e "trojan://${tjpassword}@${TSP_Domain}:${TSP_Port}?peer=${TSP_Domain}&mux=1&plugin=obfs-local;obfs=websocket;obfs-host=${TSP_Domain};obfs-uri=${tjwspath}#${HOSTNAME}-Trojan-Go-WS"
  1033. fi
  1034. if [[ -f ${v2ray_conf} && $v2ray_stat = "installed" ]]; then
  1035. [[ $v2ray_tcp_mode = "vmess" ]] &&
  1036. echo -e "vmess://$(echo "{\"add\":\"${TSP_Domain}\",\"aid\":\"0\",\"host\":\"${TSP_Domain}\",\"peer\":\"${TSP_Domain}\",\"id\":\"${VMTID}\",\"net\":\"tcp\",\"port\":\"${TSP_Port}\",\"ps\":\"${HOSTNAME}-TCP\",\"tls\":\"tls\",\"type\":\"none\",\"v\":\"2\"}" | base64 -w 0)" &&
  1037. echo -e "vmess://tcp+tls:${VMTID}-0@${TSP_Domain}:${TSP_Port}/?tlsServerName=${TSP_Domain}#$(urlEncode "${HOSTNAME}-Novo formato - TCP")"
  1038. [[ $v2ray_ws_mode = "vmess" ]] &&
  1039. echo -e "vmess://$(echo "{\"add\":\"${TSP_Domain}\",\"aid\":\"0\",\"host\":\"${TSP_Domain}\",\"peer\":\"${TSP_Domain}\",\"id\":\"${VMWSID}\",\"net\":\"ws\",\"path\":\"${v2wspath}\",\"port\":\"${TSP_Port}\",\"ps\":\"${HOSTNAME}-WS\",\"tls\":\"tls\",\"type\":\"none\",\"v\":\"2\"}" | base64 -w 0)" &&
  1040. echo -e "vmess://ws+tls:${VMWSID}-0@${TSP_Domain}:${TSP_Port}/?path=$(urlEncode "${v2wspath}")&host=${TSP_Domain}&tlsServerName=${TSP_Domain}#$(urlEncode "${HOSTNAME}-Novo formato-WS")"
  1041. [[ $v2ray_tcp_mode = "vless" ]] &&
  1042. echo -e "vless://${VLTID}@${TSP_Domain}:${TSP_Port}?security=tls&sni=${TSP_Domain}#$(urlEncode "${HOSTNAME}-TCP")"
  1043. [[ $v2ray_ws_mode = "vless" ]] &&
  1044. echo -e "vless://${VLWSID}@${TSP_Domain}:${TSP_Port}?type=ws&security=tls&host=${TSP_Domain}&path=$(urlEncode "${v2wspath}")&sni=${TSP_Domain}#$(urlEncode "${HOSTNAME}-WS")"
  1045. fi
  1046. }
  1047. cert_stat_check() {
  1048. echo -e "${OK} ${GreenBG} Verifique as informações de status do certificado... ${Font}"
  1049. if systemctl is-active "$1" &>/dev/null; then
  1050. [[ $1 = "tls-shunt-proxy" ]] && [[ ! -f ${tsp_cert_dir}/${TSP_Domain}/${TSP_Domain}.crt || ! -f ${tsp_cert_dir}/${TSP_Domain}/${TSP_Domain}.json || ! -f ${tsp_cert_dir}/${TSP_Domain}/${TSP_Domain}.key ]] &&
  1051. echo -e "${Yellow}Nenhum certificado SSL válido foi detectado, execute o seguinte comando:\n#systemctl restart tls-shunt-proxy\n#journalctl -u tls-shunt-proxy.service\nVerifique o log e execute novamente o script depois que o aplicativo de certificado for concluído${Font}" && exit 4
  1052. fi
  1053. }
  1054. menu_req_check() {
  1055. if systemctl is-active "$1" &>/dev/null; then
  1056. [[ $debug = "enable" ]] && echo -e "${OK} ${GreenBG} $1 Começou ${Font}"
  1057. else
  1058. echo -e "\n${Error} ${RedBG} Foi detectado que o serviço $1 não foi iniciado com sucesso. De acordo com a dependência, as seguintes opções serão bloqueadas, corrija e tente novamente... ${Font}"
  1059. [[ $1 = "tls-shunt-proxy" ]] && echo -e "${Yellow}[Shield] Instalar proxy TCP / WS (Trojan-Go / V2Ray) \nModificação de configuração [Shield] (Trojan-Go / V2Ray) \n[Block] Ver informações de configuração${Font}"
  1060. [[ $1 = "docker" ]] && echo -e "${Yellow}[Shield] Instalar / desinstalar WatchTower (atualizar automaticamente o contêiner) \n[Shield] Instalar / desinstalar Portainer(Contêiner de gerenciamento da web)${Font}"
  1061. read -t 60 -n 1 -s -rp "Pressione qualquer tecla para continuar(60s)..."
  1062. fi
  1063. }
  1064. menu() {
  1065. deployed_status_check
  1066. echo -e "\n${Green} Versão do script de implantação TSP e Trojan-Go / V2Ray: ${shell_version} ${Font}"
  1067. echo -e "——————————————————————Gerenciamento de implantação——————————————————————"
  1068. if [[ $tsp_stat = "installed" ]]; then
  1069. echo -e "${Green}1.${Font} ${Yellow}Desinstalar${Font} TLS-Shunt-Proxy"
  1070. else
  1071. echo -e "${Green}1.${Font} Instalar TLS-Shunt-Proxy(Certificado de gerenciamento de site e automático)"
  1072. fi
  1073. systemctl is-active "tls-shunt-proxy" &>/dev/null &&
  1074. if [[ $trojan_stat = "none" ]]; then
  1075. echo -e "${Green}2.${Font} Instalar proxy TCP / WS Trojan-Go"
  1076. else
  1077. echo -e "${Green}2.${Font} ${Yellow}Desinstalar${Font} Proxy Trojan-Go TCP / WS"
  1078. fi
  1079. systemctl is-active "tls-shunt-proxy" &>/dev/null &&
  1080. if [[ $v2ray_stat = "none" ]]; then
  1081. echo -e "${Green}3.${Font} Instalar proxy TCP / WS V2Ray"
  1082. else
  1083. echo -e "${Green}3.${Font} ${Yellow}Desinstalar${Font} Proxy TCP / WS V2Ray"
  1084. fi
  1085. systemctl is-active "docker" &>/dev/null &&
  1086. if [[ $watchtower_stat = "none" ]]; then
  1087. echo -e "${Green}4.${Font} Instalar WatchTower (atualizar automaticamente o contêiner)"
  1088. else
  1089. echo -e "${Green}4.${Font} ${Yellow}Desinstalar${Font} WatchTower (atualiza automaticamente o contêiner)"
  1090. fi
  1091. systemctl is-active "docker" &>/dev/null &&
  1092. if [[ $portainer_stat = "none" ]]; then
  1093. echo -e "${Green}5.${Font} Instalar Portainer (Web Management Container)"
  1094. else
  1095. echo -e "${Green}5.${Font} ${Yellow}Desinstalar${Font} Portainer (contêiner de gerenciamento da Web)"
  1096. fi
  1097. systemctl is-active "tls-shunt-proxy" &>/dev/null &&
  1098. echo -e "——————————————————————Modificação de configuração——————————————————————" &&
  1099. echo -e "${Green}6.${Font} Modificar porta TLS / nome de domínio" &&
  1100. [[ $trojan_stat = "installed" && -f ${trojan_conf} ]] && echo -e "${Green}7.${Font} Modificar a configuração do proxy Trojan-Go"
  1101. systemctl is-active "tls-shunt-proxy" &>/dev/null &&
  1102. [[ $v2ray_stat = "installed" && -f ${v2ray_conf} ]] && echo -e "${Green}8.${Font} Modificar a configuração do proxy V2Ray"
  1103. systemctl is-active "tls-shunt-proxy" &>/dev/null &&
  1104. echo -e "——————————————————————Ver informação——————————————————————" &&
  1105. echo -e "${Green}9.${Font} Ver informações de configuração" &&
  1106. [[ $trojan_stat = "installed" || $v2ray_stat = "installed" ]] && echo -e "${Green}10.${Font} Ver link compartilhar / assinar"
  1107. echo -e "——————————————————————Gestão Diversa——————————————————————"
  1108. [ -f ${tsp_conf} ] && echo -e "${Green}11.${Font} Atualizar plataforma base TLS-Shunt-Proxy / Docker" &&
  1109. echo -e "${Green}12.${Font} ${Yellow}Desinstalar${Font} Todos os componentes instalados"
  1110. echo -e "${Green}13.${Font} Instale o script 4 em 1 BBR Rui Su"
  1111. echo -e "${Green}14.${Font} Execute o script de teste SuperSpeed"
  1112. echo -e "${Green}0.${Font} Sair do script "
  1113. echo -e "————————————————————————————————————————————————————\n"
  1114. read -rp "Por favor insira o número:" menu_num
  1115. case "$menu_num" in
  1116. 1)
  1117. if [[ $tsp_stat = "installed" ]]; then
  1118. uninstall_tsp
  1119. else
  1120. install_tls_shunt_proxy
  1121. tsp_sync
  1122. fi
  1123. ;;
  1124. 2)
  1125. systemctl is-active "tls-shunt-proxy" &>/dev/null &&
  1126. if [[ $trojan_stat = "none" ]]; then
  1127. install_trojan
  1128. else
  1129. uninstall_trojan
  1130. fi
  1131. ;;
  1132. 3)
  1133. systemctl is-active "tls-shunt-proxy" &>/dev/null &&
  1134. if [[ $v2ray_stat = "none" ]]; then
  1135. install_v2ray
  1136. else
  1137. uninstall_v2ray
  1138. fi
  1139. ;;
  1140. 4)
  1141. systemctl is-active "docker" &>/dev/null &&
  1142. if [[ $watchtower_stat = "none" ]]; then
  1143. install_watchtower
  1144. else
  1145. uninstall_watchtower
  1146. fi
  1147. ;;
  1148. 5)
  1149. systemctl is-active "docker" &>/dev/null &&
  1150. if [[ $portainer_stat = "none" ]]; then
  1151. install_portainer
  1152. else
  1153. uninstall_portainer
  1154. fi
  1155. ;;
  1156. 6)
  1157. systemctl is-active "tls-shunt-proxy" &>/dev/null && modify_tsp
  1158. ;;
  1159. 7)
  1160. systemctl is-active "tls-shunt-proxy" &>/dev/null && [[ -f ${trojan_conf} && $trojan_stat = "installed" ]] && modify_trojan
  1161. ;;
  1162. 8)
  1163. systemctl is-active "tls-shunt-proxy" &>/dev/null && [[ -f ${v2ray_conf} && $v2ray_stat = "installed" ]] && modify_v2ray
  1164. ;;
  1165. 9)
  1166. systemctl is-active "tls-shunt-proxy" &>/dev/null && info_config
  1167. ;;
  1168. 10)
  1169. systemctl is-active "tls-shunt-proxy" &>/dev/null && info_links
  1170. ;;
  1171. 11)
  1172. [ -f ${tsp_conf} ] && read -rp "Confirme se deseja atualizar o componente shunt TLS-Shunt-Proxy,(Y/N) [N]:" upgrade_mode
  1173. [[ -z ${upgrade_mode} ]] && upgrade_mode="none"
  1174. case $upgrade_mode in
  1175. [yY])
  1176. echo -e "${GreenBG} Comece a atualizar o componente shunt TLS-Shunt-Proxy ${Font}"
  1177. upgrade_mode="Tsp"
  1178. sleep 1
  1179. upgrade_tsp
  1180. ;;
  1181. *)
  1182. echo -e "${GreenBG} Pule para atualizar o componente shunt TLS-Shunt-Proxy ${Font}"
  1183. ;;
  1184. esac
  1185. [ -f ${tsp_conf} ] && read -rp "Confirme se deseja atualizar os componentes da plataforma Docker,(Y/N) [N]:" upgrade_mode
  1186. [[ -z ${upgrade_mode} ]] && upgrade_mode="none"
  1187. case $upgrade_mode in
  1188. [yY])
  1189. echo -e "${GreenBG} Comece a atualizar os componentes da plataforma Docker ${Font}"
  1190. upgrade_mode="Docker"
  1191. sleep 1
  1192. install_docker
  1193. ;;
  1194. *)
  1195. echo -e "${GreenBG} Pular a atualização dos componentes da plataforma Docker ${Font}"
  1196. ;;
  1197. esac
  1198. ;;
  1199. 12)
  1200. [ -f ${tsp_conf} ] && uninstall_all
  1201. ;;
  1202. 13)
  1203. kernel_change="YES"
  1204. systemctl is-active "docker" &>/dev/null && echo -e "${RedBG} !!!Como o Docker está intimamente relacionado ao kernel do sistema, alterar o kernel do sistema pode fazer com que o Docker fique inutilizável!!! ${Font}\n${WARN} ${Yellow} 如果内核更换后 Docker 无法正常启动,请尝试通过 脚本 <选项10:升级 Docker> 修复 或 <选项11:完全卸载> 后重新部署 ${Font}" &&
  1205. read -rp "Depois de confirmar, digite YES (diferencia maiúsculas de minúsculas):" kernel_change
  1206. [[ -z ${kernel_change} ]] && kernel_change="no"
  1207. case $kernel_change in
  1208. YES)
  1209. [ -f "tcp.sh" ] && rm -rf ./tcp.sh
  1210. wget -N --no-check-certificate "https://raw.githubusercontent.com/ylx2016/Linux-NetSpeed/master/tcpx.sh" && chmod +x tcpx.sh && ./tcpx.sh
  1211. ;;
  1212. *)
  1213. echo -e "${RedBG} Deixe-me pensar de novo ${Font}"
  1214. exit 0
  1215. ;;
  1216. esac
  1217. ;;
  1218. 14)
  1219. bash <(curl -Lso- https://git.io/superspeed)
  1220. ;;
  1221. 0)
  1222. exit 0
  1223. ;;
  1224. *)
  1225. echo -e "${RedBG} Por favor insira o número correto ${Font}"
  1226. sleep 3
  1227. ;;
  1228. esac
  1229. menu
  1230. }
  1231. clear
  1232. check_system
  1233. is_root
  1234. update_sh
  1235. list "$1"