install_script.sh 78 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063
  1. #!/usr/bin/env bash
  2. PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
  3. export PATH
  4. # System Required: CentOS 7+/Ubuntu 18+/Debian 10+
  5. # Version: v2.2.0
  6. # Description: One click Install Trojan Panel server
  7. # Author: jonssonyan <https://jonssonyan.com>
  8. # Github: https://github.com/trojanpanel/install-script
  9. init_var() {
  10. ECHO_TYPE="echo -e"
  11. package_manager=""
  12. release=""
  13. get_arch=""
  14. can_google=0
  15. # Docker
  16. DOCKER_MIRROR='"https://hub-mirror.c.163.com","https://ccr.ccs.tencentyun.com","https://mirror.baidubce.com","https://dockerproxy.com"'
  17. # Project directory
  18. TP_DATA="/tpdata/"
  19. STATIC_HTML="https://github.com/trojanpanel/install-script/releases/download/v1.0/html.tar.gz"
  20. # Web
  21. WEB_PATH="/tpdata/web/"
  22. # Cert
  23. CERT_PATH="/tpdata/cert/"
  24. DOMAIN_FILE="/tpdata/domain.lock"
  25. domain=""
  26. crt_path=""
  27. key_path=""
  28. # Caddy2
  29. CADDY_DATA="/tpdata/caddy/"
  30. CADDY_CONFIG="${CADDY_DATA}config.json"
  31. CADDY_LOG="${CADDY_DATA}logs/"
  32. CADDY_CERT_DIR="${CERT_PATH}certificates/acme-v02.api.letsencrypt.org-directory/"
  33. caddy_port=80
  34. caddy_remote_port=8863
  35. your_email=""
  36. ssl_option=1
  37. ssl_module_type=1
  38. ssl_module="acme"
  39. # Nginx
  40. NGINX_DATA="/tpdata/nginx/"
  41. NGINX_CONFIG="${NGINX_DATA}default.conf"
  42. nginx_port=80
  43. nginx_remote_port=8863
  44. nginx_https=1
  45. # MariaDB
  46. MARIA_DATA="/tpdata/mariadb/"
  47. mariadb_ip="127.0.0.1"
  48. mariadb_port=9507
  49. mariadb_user="root"
  50. mariadb_pas=""
  51. # Redis
  52. REDIS_DATA="/tpdata/redis/"
  53. redis_host="127.0.0.1"
  54. redis_port=6378
  55. redis_pass=""
  56. # Trojan Panel Frontend
  57. TROJAN_PANEL_UI_DATA="/tpdata/trojan-panel-ui/"
  58. # Nginx
  59. UI_NGINX_DATA="${TROJAN_PANEL_UI_DATA}nginx/"
  60. UI_NGINX_CONFIG="${UI_NGINX_DATA}default.conf"
  61. trojan_panel_ui_port=8888
  62. ui_https=1
  63. trojan_panel_ip="127.0.0.1"
  64. trojan_panel_server_port=8081
  65. # Trojan Panel Backend
  66. TROJAN_PANEL_DATA="/tpdata/trojan-panel/"
  67. TROJAN_PANEL_WEBFILE="${TROJAN_PANEL_DATA}webfile/"
  68. TROJAN_PANEL_LOGS="${TROJAN_PANEL_DATA}logs/"
  69. TROJAN_PANEL_CONFIG="${TROJAN_PANEL_DATA}config/"
  70. trojan_panel_config_path="${TROJAN_PANEL_DATA}config/config.ini"
  71. trojan_panel_port=8081
  72. # Trojan Panel Core
  73. TROJAN_PANEL_CORE_DATA="/tpdata/trojan-panel-core/"
  74. TROJAN_PANEL_CORE_LOGS="${TROJAN_PANEL_CORE_DATA}logs/"
  75. TROJAN_PANEL_CORE_CONFIG="${TROJAN_PANEL_CORE_DATA}config/"
  76. trojan_panel_core_config_path="${TROJAN_PANEL_CORE_DATA}config/config.ini"
  77. database="trojan_panel_db"
  78. account_table="account"
  79. grpc_port=8100
  80. trojan_panel_core_port=8082
  81. # Version
  82. trojan_panel_ui_current_version=""
  83. trojan_panel_ui_latest_version="v2.1.6"
  84. trojan_panel_current_version=""
  85. trojan_panel_latest_version="v2.1.5"
  86. trojan_panel_core_current_version=""
  87. trojan_panel_core_latest_version="v2.1.2"
  88. # SQL
  89. sql_200="alter table \`system\` add template_config varchar(512) default '' not null comment '模板设置' after email_config;update \`system\` set template_config = \"{\\\"systemName\\\":\\\"Trojan Panel\\\"}\" where name = \"trojan-panel\";insert into \`casbin_rule\` values ('p','sysadmin','/api/nodeServer/nodeServerState','GET','','','');insert into \`casbin_rule\` values ('p','user','/api/node/selectNodeInfo','GET','','','');insert into \`casbin_rule\` values ('p','sysadmin','/api/node/selectNodeInfo','GET','','','');"
  90. sql_203="alter table node add node_server_grpc_port int(10) unsigned default 8100 not null comment 'gRPC端口' after node_server_ip;alter table node_server add grpc_port int(10) unsigned default 8100 not null comment 'gRPC端口' after name;alter table node_xray add xray_flow varchar(32) default 'xtls-rprx-vision' not null comment 'Xray流控' after protocol;alter table node_xray add xray_ss_method varchar(32) default 'aes-256-gcm' not null comment 'Xray Shadowsocks加密方式' after xray_flow;"
  91. sql_205="DROP TABLE IF EXISTS \`file_task\`;CREATE TABLE \`file_task\` ( \`id\` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '自增主键', \`name\` varchar(64) NOT NULL DEFAULT '' COMMENT '文件名称', \`path\` varchar(128) NOT NULL DEFAULT '' COMMENT '文件路径', \`type\` tinyint(2) unsigned NOT NULL DEFAULT '1' COMMENT '类型 1/用户导入 2/服务器导入 3/用户导出 4/服务器导出', \`status\` tinyint(1) NOT NULL DEFAULT '0' COMMENT '状态 -1/失败 0/等待 1/正在执行 2/成功', \`err_msg\` varchar(128) NOT NULL DEFAULT '' COMMENT '错误信息', \`account_id\` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '账户id', \`account_username\` varchar(64) NOT NULL DEFAULT '' COMMENT '账户登录用户名', \`create_time\` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', \`update_time\` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', PRIMARY KEY (\`id\`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='文件任务';INSERT INTO trojan_panel_db.casbin_rule (p_type, v0, v1, v2, v3, v4, v5) VALUES ('p', 'sysadmin', '/api/account/exportAccount', 'POST', '', '', '');INSERT INTO trojan_panel_db.casbin_rule (p_type, v0, v1, v2, v3, v4, v5) VALUES ('p', 'sysadmin', '/api/account/importAccount', 'POST', '', '', '');INSERT INTO trojan_panel_db.casbin_rule (p_type, v0, v1, v2, v3, v4, v5) VALUES ('p', 'sysadmin', '/api/system/uploadLogo', 'POST', '', '', '');INSERT INTO trojan_panel_db.casbin_rule (p_type, v0, v1, v2, v3, v4, v5) VALUES ('p', 'sysadmin', '/api/nodeServer/exportNodeServer', 'POST', '', '', '');INSERT INTO trojan_panel_db.casbin_rule (p_type, v0, v1, v2, v3, v4, v5) VALUES ('p', 'sysadmin', '/api/nodeServer/importNodeServer', 'POST', '', '', '');INSERT INTO trojan_panel_db.casbin_rule (p_type, v0, v1, v2, v3, v4, v5) VALUES ('p', 'sysadmin', '/api/fileTask/selectFileTaskPage', 'GET', '', '', '');INSERT INTO trojan_panel_db.casbin_rule (p_type, v0, v1, v2, v3, v4, v5) VALUES ('p', 'sysadmin', '/api/fileTask/deleteFileTaskById', 'POST', '', '', '');INSERT INTO trojan_panel_db.casbin_rule (p_type, v0, v1, v2, v3, v4, v5) VALUES ('p', 'sysadmin', '/api/fileTask/downloadFileTask', 'POST', '', '', '');INSERT INTO trojan_panel_db.casbin_rule (p_type, v0, v1, v2, v3, v4, v5) VALUES ('p', 'sysadmin', '/api/fileTask/downloadCsvTemplate', 'POST', '', '', '');"
  92. sql_210="UPDATE casbin_rule SET v1 = '/api/fileTask/downloadTemplate' WHERE v1 = '/api/fileTask/downloadCsvTemplate';UPDATE casbin_rule SET v1 = '/api/account/updateAccountPass' WHERE v1 = '/api/account/updateAccountProfile';INSERT INTO casbin_rule (p_type, v0, v1, v2) VALUES ('p', 'sysadmin', '/api/account/updateAccountProperty', 'POST');INSERT INTO casbin_rule (p_type, v0, v1, v2) VALUES ('p', 'user', '/api/account/updateAccountProperty', 'POST');alter table node_xray modify settings varchar(1024) default '' not null comment 'settings';alter table node_xray modify stream_settings varchar(1024) default '' not null comment 'streamSettings';alter table node_xray add reality_pbk varchar(64) default '' not null comment 'reality的公钥' after xray_ss_method;alter table node_hysteria add obfs varchar(64) default '' not null comment '混淆密码' after protocol;"
  93. sql_211="UPDATE \`system\` SET account_config = '{\"registerEnable\":1,\"registerQuota\":0,\"registerExpireDays\":0,\"resetDownloadAndUploadMonth\":0,\"trafficRankEnable\":1,\"captchaEnable\":0}' WHERE name = 'trojan-panel';INSERT INTO casbin_rule (p_type, v0, v1, v2, v3, v4, v5) VALUES ('p', 'sysadmin', '/api/node/nodeDefault', 'GET', '', '', '');INSERT INTO casbin_rule (p_type, v0, v1, v2, v3, v4, v5) VALUES ('p', 'user', '/api/node/nodeDefault', 'GET', '', '', '');"
  94. sql_212="alter table account add validity_period int unsigned default 0 not null comment '账户有效期' after email;alter table account add last_login_time bigint unsigned default 0 not null comment '最后一次登录时间' after validity_period;update account set last_login_time = unix_timestamp(NOW()) * 1000 where last_login_time = 0;INSERT INTO casbin_rule (p_type, v0, v1, v2, v3, v4, v5) VALUES ('p', 'sysadmin', '/api/account/createAccountBatch', 'POST', '', '', '');INSERT INTO casbin_rule (p_type, v0, v1, v2, v3, v4, v5) VALUES ('p', 'sysadmin', '/api/account/exportAccountUnused', 'POST', '', '', '');"
  95. sql_215="alter table account change validity_period preset_expire int unsigned default 0 not null comment '预设过期时长';alter table account add preset_quota bigint default 0 not null comment '预设配额' after preset_expire;update account set preset_quota = quota where last_login_time = 0;update account set quota = 0 where last_login_time = 0;alter table node add priority int default 100 not null comment '优先级' after port;INSERT INTO casbin_rule (p_type, v0, v1, v2, v3, v4, v5) VALUES ('p', 'sysadmin', '/api/account/clashSubscribeForSb', 'GET', 'default', 'default', 'default');alter table node_hysteria add server_name varchar(64) default '' not null comment '用于验证服务端证书的 hostname' after down_mbps;alter table node_hysteria add insecure tinyint(1) default 0 not null comment '忽略一切证书错误' after server_name;alter table node_hysteria add fast_open tinyint(1) default 0 not null comment '启用 Fast Open (降低连接建立延迟)' after insecure;"
  96. }
  97. echo_content() {
  98. case $1 in
  99. "red")
  100. ${ECHO_TYPE} "\033[31m$2\033[0m"
  101. ;;
  102. "green")
  103. ${ECHO_TYPE} "\033[32m$2\033[0m"
  104. ;;
  105. "yellow")
  106. ${ECHO_TYPE} "\033[33m$2\033[0m"
  107. ;;
  108. "blue")
  109. ${ECHO_TYPE} "\033[34m$2\033[0m"
  110. ;;
  111. "purple")
  112. ${ECHO_TYPE} "\033[35m$2\033[0m"
  113. ;;
  114. "skyBlue")
  115. ${ECHO_TYPE} "\033[36m$2\033[0m"
  116. ;;
  117. "white")
  118. ${ECHO_TYPE} "\033[37m$2\033[0m"
  119. ;;
  120. esac
  121. }
  122. mkdir_tools() {
  123. # Project directory
  124. mkdir -p ${TP_DATA}
  125. # Web
  126. mkdir -p ${WEB_PATH}
  127. # Cert
  128. mkdir -p ${CERT_PATH}
  129. touch ${DOMAIN_FILE}
  130. # Caddy2
  131. mkdir -p ${CADDY_DATA}
  132. touch ${CADDY_CONFIG}
  133. mkdir -p ${CADDY_LOG}
  134. # Nginx
  135. mkdir -p ${NGINX_DATA}
  136. touch ${NGINX_CONFIG}
  137. # MariaDB
  138. mkdir -p ${MARIA_DATA}
  139. # Redis
  140. mkdir -p ${REDIS_DATA}
  141. # Trojan Panel Frontend
  142. mkdir -p ${TROJAN_PANEL_UI_DATA}
  143. # Nginx
  144. mkdir -p ${UI_NGINX_DATA}
  145. touch ${UI_NGINX_CONFIG}
  146. # Trojan Panel Backend
  147. mkdir -p ${TROJAN_PANEL_DATA}
  148. mkdir -p ${TROJAN_PANEL_LOGS}
  149. # Trojan Panel Core
  150. mkdir -p ${TROJAN_PANEL_CORE_DATA}
  151. mkdir -p ${TROJAN_PANEL_CORE_LOGS}
  152. }
  153. can_connect() {
  154. ping -c2 -i0.3 -W1 "$1" &>/dev/null
  155. if [[ "$?" == "0" ]]; then
  156. return 0
  157. else
  158. return 1
  159. fi
  160. }
  161. # query .ini configuration file information
  162. get_ini_value() {
  163. local config_file="$1"
  164. local key="$2"
  165. local section=""
  166. local section_flag=0
  167. # split group and key names
  168. IFS='.' read -r group_name key_name <<<"$key"
  169. while IFS='=' read -r name val; do
  170. # processing section name
  171. if [[ $name =~ ^\[(.*)\]$ ]]; then
  172. section="${BASH_REMATCH[1]}"
  173. if [[ $section == $group_name ]]; then
  174. section_flag=1
  175. else
  176. section_flag=0
  177. fi
  178. continue
  179. fi
  180. # extract the value of the configuration item
  181. if [[ $section_flag -eq 1 && $name == $key_name ]]; then
  182. echo "$val"
  183. return
  184. fi
  185. done <"$config_file"
  186. }
  187. check_sys() {
  188. if [[ $(command -v yum) ]]; then
  189. package_manager='yum'
  190. elif [[ $(command -v dnf) ]]; then
  191. package_manager='dnf'
  192. elif [[ $(command -v apt) ]]; then
  193. package_manager='apt'
  194. elif [[ $(command -v apt-get) ]]; then
  195. package_manager='apt-get'
  196. fi
  197. if [[ -z "${package_manager}" ]]; then
  198. echo_content red "The system is not currently supported"
  199. exit 0
  200. fi
  201. if [[ -n $(find /etc -name "redhat-release") ]] || grep </proc/version -q -i "centos"; then
  202. release="centos"
  203. elif grep </etc/issue -q -i "debian" && [[ -f "/etc/issue" ]] || grep </etc/issue -q -i "debian" && [[ -f "/proc/version" ]]; then
  204. release="debian"
  205. elif grep </etc/issue -q -i "ubuntu" && [[ -f "/etc/issue" ]] || grep </etc/issue -q -i "ubuntu" && [[ -f "/proc/version" ]]; then
  206. release="ubuntu"
  207. fi
  208. if [[ -z "${release}" ]]; then
  209. echo_content red "The operating system only supports CentOS 7+/Ubuntu 18+/Debian 10+"
  210. exit 0
  211. fi
  212. if [[ $(arch) =~ ("x86_64"|"amd64"|"arm64"|"aarch64"|"arm"|"s390x") ]]; then
  213. get_arch=$(arch)
  214. fi
  215. if [[ -z "${get_arch}" ]]; then
  216. echo_content red "The processor architecture only supports amd64/arm64/arm/s390x"
  217. exit 0
  218. fi
  219. can_connect www.google.com
  220. [[ "$?" == "0" ]] && can_google=1
  221. }
  222. depend_install() {
  223. if [[ "${package_manager}" != 'yum' && "${package_manager}" != 'dnf' ]]; then
  224. ${package_manager} update -y
  225. fi
  226. ${package_manager} install -y \
  227. curl \
  228. wget \
  229. tar \
  230. lsof \
  231. systemd
  232. }
  233. # Install Docker
  234. install_docker() {
  235. if [[ ! $(docker -v 2>/dev/null) ]]; then
  236. echo_content green "---> Install Docker"
  237. # turn off firewall
  238. if [[ "$(firewall-cmd --state 2>/dev/null)" == "running" ]]; then
  239. systemctl stop firewalld.service && systemctl disable firewalld.service
  240. fi
  241. # set time zone
  242. timedatectl set-timezone Asia/Shanghai
  243. if [[ ${can_google} == 0 ]]; then
  244. sh <(curl -sL https://get.docker.com) --mirror Aliyun
  245. mkdir -p /etc/docker &&
  246. cat >/etc/docker/daemon.json <<EOF
  247. {
  248. "registry-mirrors":[${DOCKER_MIRROR}],
  249. "log-driver":"json-file",
  250. "log-opts":{
  251. "max-size":"50m",
  252. "max-file":"3"
  253. }
  254. }
  255. EOF
  256. else
  257. sh <(curl -sL https://get.docker.com)
  258. mkdir -p /etc/docker &&
  259. cat >/etc/docker/daemon.json <<EOF
  260. {
  261. "log-driver":"json-file",
  262. "log-opts":{
  263. "max-size":"50m",
  264. "max-file":"3"
  265. }
  266. }
  267. EOF
  268. fi
  269. systemctl enable docker &&
  270. systemctl restart docker
  271. if [[ $(docker -v 2>/dev/null) ]]; then
  272. echo_content skyBlue "---> Docker installation completed"
  273. else
  274. echo_content red "---> Docker installation failed"
  275. exit 0
  276. fi
  277. else
  278. echo_content skyBlue "---> You have installed Docker"
  279. fi
  280. }
  281. # Custom Settings Certificate
  282. install_custom_cert() {
  283. if [[ -z "$(cat "${DOMAIN_FILE}")" ]]; then
  284. while read -r -p "Please enter the file path of the .crt certificate (required): " crt_path; do
  285. if [[ -z "${crt_path}" ]]; then
  286. echo_content red "Path cannot be empty"
  287. else
  288. if [[ ! -f "${crt_path}" ]]; then
  289. echo_content red "The file path for the .crt certificate does not exist"
  290. else
  291. cp "${crt_path}" "${CERT_PATH}$1.crt"
  292. break
  293. fi
  294. fi
  295. done
  296. while read -r -p "Please enter the file path of the .key certificate (required): " key_path; do
  297. if [[ -z "${key_path}" ]]; then
  298. echo_content red "Path cannot be empty"
  299. else
  300. if [[ ! -f "${key_path}" ]]; then
  301. echo_content red "The file path for the .key certificate does not exist"
  302. else
  303. cp "${key_path}" "${CERT_PATH}$1.key"
  304. break
  305. fi
  306. fi
  307. done
  308. cat >${DOMAIN_FILE} <<EOF
  309. $1
  310. EOF
  311. echo_content red "\n=============================================================="
  312. echo_content skyBlue "---> Custom settings certificate installation completed"
  313. echo_content yellow "Certificate Directory: ${CERT_PATH}"
  314. echo_content red "\n=============================================================="
  315. fi
  316. }
  317. # Caddy2 https custom settings certificate configuration file
  318. caddy2_https_config() {
  319. domain=$1
  320. cat >${CADDY_CONFIG} <<EOF
  321. {
  322. "admin":{
  323. "disabled":true
  324. },
  325. "logging":{
  326. "logs":{
  327. "default":{
  328. "writer":{
  329. "output":"file",
  330. "filename":"${CADDY_LOG}error.log"
  331. },
  332. "level":"ERROR"
  333. }
  334. }
  335. },
  336. "storage":{
  337. "module":"file_system",
  338. "root":"${CERT_PATH}"
  339. },
  340. "apps":{
  341. "http":{
  342. "http_port": ${caddy_port},
  343. "servers":{
  344. "srv0":{
  345. "listen":[
  346. ":${caddy_port}"
  347. ],
  348. "routes":[
  349. {
  350. "match":[
  351. {
  352. "host":[
  353. "${domain}"
  354. ]
  355. }
  356. ],
  357. "handle":[
  358. {
  359. "handler":"static_response",
  360. "headers":{
  361. "Location":[
  362. "https://{http.request.host}:${caddy_remote_port}{http.request.uri}"
  363. ]
  364. },
  365. "status_code":301
  366. }
  367. ]
  368. }
  369. ]
  370. },
  371. "srv1":{
  372. "listen":[
  373. ":${caddy_remote_port}"
  374. ],
  375. "routes":[
  376. {
  377. "handle":[
  378. {
  379. "handler":"subroute",
  380. "routes":[
  381. {
  382. "match":[
  383. {
  384. "host":[
  385. "${domain}"
  386. ]
  387. }
  388. ],
  389. "handle":[
  390. {
  391. "handler":"file_server",
  392. "root":"${WEB_PATH}",
  393. "index_names":[
  394. "index.html",
  395. "index.htm"
  396. ]
  397. }
  398. ],
  399. "terminal":true
  400. }
  401. ]
  402. }
  403. ]
  404. }
  405. ],
  406. "tls_connection_policies":[
  407. {
  408. "match":{
  409. "sni":[
  410. "${domain}"
  411. ]
  412. }
  413. }
  414. ],
  415. "automatic_https":{
  416. "disable":true
  417. }
  418. }
  419. }
  420. },
  421. "tls":{
  422. "certificates":{
  423. "automate":[
  424. "${domain}"
  425. ],
  426. "load_files":[
  427. {
  428. "certificate":"${CADDY_CERT_DIR}${domain}/${domain}.crt",
  429. "key":"${CADDY_CERT_DIR}${domain}/${domain}.key"
  430. }
  431. ]
  432. },
  433. "automation":{
  434. "policies":[
  435. {
  436. "issuers":[
  437. {
  438. "module":"${ssl_module}",
  439. "email":"${your_email}"
  440. }
  441. ]
  442. }
  443. ]
  444. }
  445. }
  446. }
  447. }
  448. EOF
  449. }
  450. # Caddy2 https automatic application and renewal certificate configuration file
  451. caddy2_https_auto_config() {
  452. domain=$1
  453. cat >${CADDY_CONFIG} <<EOF
  454. {
  455. "admin":{
  456. "disabled":true
  457. },
  458. "logging":{
  459. "logs":{
  460. "default":{
  461. "writer":{
  462. "output":"file",
  463. "filename":"${CADDY_LOG}error.log"
  464. },
  465. "level":"ERROR"
  466. }
  467. }
  468. },
  469. "storage":{
  470. "module":"file_system",
  471. "root":"${CERT_PATH}"
  472. },
  473. "apps":{
  474. "http":{
  475. "http_port": ${caddy_port},
  476. "servers":{
  477. "srv0":{
  478. "listen":[
  479. ":${caddy_port}"
  480. ],
  481. "routes":[
  482. {
  483. "match":[
  484. {
  485. "host":[
  486. "${domain}"
  487. ]
  488. }
  489. ],
  490. "handle":[
  491. {
  492. "handler":"static_response",
  493. "headers":{
  494. "Location":[
  495. "https://{http.request.host}:${caddy_remote_port}{http.request.uri}"
  496. ]
  497. },
  498. "status_code":301
  499. }
  500. ]
  501. }
  502. ]
  503. },
  504. "srv1":{
  505. "listen":[
  506. ":${caddy_remote_port}"
  507. ],
  508. "routes":[
  509. {
  510. "handle":[
  511. {
  512. "handler":"subroute",
  513. "routes":[
  514. {
  515. "match":[
  516. {
  517. "host":[
  518. "${domain}"
  519. ]
  520. }
  521. ],
  522. "handle":[
  523. {
  524. "handler":"file_server",
  525. "root":"${WEB_PATH}",
  526. "index_names":[
  527. "index.html",
  528. "index.htm"
  529. ]
  530. }
  531. ],
  532. "terminal":true
  533. }
  534. ]
  535. }
  536. ]
  537. }
  538. ],
  539. "tls_connection_policies":[
  540. {
  541. "match":{
  542. "sni":[
  543. "${domain}"
  544. ]
  545. }
  546. }
  547. ],
  548. "automatic_https":{
  549. "disable":true
  550. }
  551. }
  552. }
  553. },
  554. "tls":{
  555. "certificates":{
  556. "automate":[
  557. "${domain}"
  558. ]
  559. },
  560. "automation":{
  561. "policies":[
  562. {
  563. "issuers":[
  564. {
  565. "module":"${ssl_module}",
  566. "email":"${your_email}"
  567. }
  568. ]
  569. }
  570. ]
  571. }
  572. }
  573. }
  574. }
  575. EOF
  576. }
  577. # Install Caddy2
  578. install_caddy2() {
  579. if [[ -z $(docker ps -a -q -f "name=^trojan-panel-caddy$") ]]; then
  580. echo_content green "---> Install Caddy2+https"
  581. wget --no-check-certificate -O ${WEB_PATH}html.tar.gz -N ${STATIC_HTML} &&
  582. tar -zxvf ${WEB_PATH}html.tar.gz -k -C ${WEB_PATH}
  583. read -r -p "Please enter the port of Caddy2 (default: 80): " caddy_port
  584. [[ -z "${caddy_port}" ]] && caddy_port=80
  585. read -r -p "Please enter the forwarding port of Caddy2 (default: 8863): " caddy_remote_port
  586. [[ -z "${caddy_remote_port}" ]] && caddy_remote_port=8863
  587. echo_content yellow "Tip: Please confirm that the domain name has been resolved to this machine, otherwise the installation may fail"
  588. while read -r -p "Please enter your domain name (required): " domain; do
  589. if [[ -z "${domain}" ]]; then
  590. echo_content red "Domain name cannot be empty"
  591. else
  592. break
  593. fi
  594. done
  595. read -r -p "Please enter your email (optional): " your_email
  596. while read -r -p "Please choose the way to set up the certificate? (1/automatically apply for and renew the certificate 2/manually set the certificate path default: 1: " ssl_option; do
  597. if [[ -z ${ssl_option} || ${ssl_option} == 1 ]]; then
  598. while read -r -p "Please choose the way to apply for the certificate (1/acme 2/zerossl default: 1: " ssl_module_type; do
  599. if [[ -z "${ssl_module_type}" || ${ssl_module_type} == 1 ]]; then
  600. ssl_module="acme"
  601. CADDY_CERT_DIR="${CERT_PATH}certificates/acme-v02.api.letsencrypt.org-directory/"
  602. break
  603. elif [[ ${ssl_module_type} == 2 ]]; then
  604. ssl_module="zerossl"
  605. CADDY_CERT_DIR="${CERT_PATH}certificates/acme.zerossl.com-v2-dv90/"
  606. break
  607. else
  608. echo_content red "Cannot enter other characters except 1 and 2"
  609. fi
  610. done
  611. caddy2_https_auto_config "${domain}"
  612. break
  613. elif [[ ${ssl_option} == 2 ]]; then
  614. install_custom_cert "${domain}"
  615. caddy2_https_config "${domain}"
  616. break
  617. else
  618. echo_content red "Cannot enter other characters except 1 and 2"
  619. fi
  620. done
  621. # Caddy2 temporary listening port for automatic certificate application
  622. if [[ -n $(lsof -i:${caddy_port},${caddy_remote_port} -t) ]]; then
  623. kill -9 "$(lsof -i:${caddy_port},${caddy_remote_port} -t)"
  624. fi
  625. docker pull caddy:2.6.2 &&
  626. docker run -d --name trojan-panel-caddy --restart always \
  627. --network=host \
  628. -v "${CADDY_CONFIG}":"${CADDY_CONFIG}" \
  629. -v ${CERT_PATH}:"${CADDY_CERT_DIR}${domain}/" \
  630. -v ${WEB_PATH}:${WEB_PATH} \
  631. -v ${CADDY_LOG}:${CADDY_LOG} \
  632. caddy:2.6.2 caddy run --config ${CADDY_CONFIG}
  633. cat >${DOMAIN_FILE} <<EOF
  634. ${domain}
  635. EOF
  636. if [[ -n $(docker ps -q -f "name=^trojan-panel-caddy$" -f "status=running") ]]; then
  637. echo_content red "\n=============================================================="
  638. echo_content skyBlue "---> Caddy2+https installation completed"
  639. echo_content yellow "Certificate Directory: ${CERT_PATH}"
  640. echo_content red "\n=============================================================="
  641. else
  642. echo_content red "---> Caddy2+https installation fails or runs abnormally, please try to repair or uninstall and reinstall"
  643. exit 0
  644. fi
  645. else
  646. echo_content skyBlue "---> You have installed Caddy2+https"
  647. fi
  648. }
  649. # Nginx http configuration file
  650. nginx_http_config() {
  651. cat >${NGINX_CONFIG} <<-EOF
  652. server {
  653. listen ${nginx_port};
  654. server_name localhost;
  655. location / {
  656. root ${WEB_PATH};
  657. index index.html index.htm;
  658. }
  659. error_page 497 http://\$host:${nginx_port}\$request_uri;
  660. error_page 500 502 503 504 /50x.html;
  661. location = /50x.html {
  662. root /usr/share/nginx/html;
  663. }
  664. }
  665. EOF
  666. }
  667. # Nginx https configuration file
  668. nginx_https_config() {
  669. domain=$1
  670. cat >${NGINX_CONFIG} <<-EOF
  671. server {
  672. listen ${nginx_port};
  673. server_name localhost;
  674. return 301 http://\$host:${nginx_remote_port}\$request_uri;
  675. }
  676. server {
  677. listen ${nginx_remote_port} ssl;
  678. server_name localhost;
  679. # force ssl
  680. ssl on;
  681. ssl_certificate ${CERT_PATH}${domain}.crt;
  682. ssl_certificate_key ${CERT_PATH}${domain}.key;
  683. # cache validity period
  684. ssl_session_timeout 5m;
  685. # secure link optional encryption protocol
  686. ssl_protocols TLSv1.3;
  687. # encryption algorithm
  688. ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
  689. # use server-side preferred algorithm
  690. ssl_prefer_server_ciphers on;
  691. #access_log /var/log/nginx/host.access.log main;
  692. location / {
  693. root ${WEB_PATH};
  694. index index.html index.htm;
  695. }
  696. #error_page 404 /404.html;
  697. #497 http->https
  698. error_page 497 https://\$host:${nginx_remote_port}\$request_uri;
  699. # redirect server error pages to the static page /50x.html
  700. #
  701. error_page 500 502 503 504 /50x.html;
  702. location = /50x.html {
  703. root /usr/share/nginx/html;
  704. }
  705. }
  706. EOF
  707. }
  708. # Install Nginx
  709. install_nginx() {
  710. if [[ -z $(docker ps -a -q -f "name=^trojan-panel-nginx$") ]]; then
  711. echo_content green "---> Install Nginx"
  712. wget --no-check-certificate -O ${WEB_PATH}html.tar.gz -N ${STATIC_HTML} &&
  713. tar -zxvf ${WEB_PATH}html.tar.gz -k -C ${WEB_PATH}
  714. read -r -p "Please enter the port of Nginx (default: 80): " nginx_port
  715. [[ -z "${nginx_port}" ]] && nginx_port=80
  716. read -r -p "Please enter the forwarding port of Nginx (default: 8863): " nginx_remote_port
  717. [[ -z "${nginx_remote_port}" ]] && nginx_remote_port=8863
  718. while read -r -p "Please choose whether to enable https in Nginx? (0/off 1/on default: 1): " nginx_https; do
  719. if [[ -z ${nginx_https} || ${nginx_https} == 1 ]]; then
  720. install_custom_cert "custom_cert"
  721. nginx_https_config "custom_cert"
  722. break
  723. elif [[ ${nginx_https} == 0 ]]; then
  724. nginx_http_config
  725. break
  726. else
  727. echo_content red "Cannot enter other characters except 1 and 2"
  728. fi
  729. done
  730. docker pull nginx:1.20-alpine &&
  731. docker run -d --name trojan-panel-nginx --restart always \
  732. --network=host \
  733. -v "${NGINX_CONFIG}":"/etc/nginx/conf.d/default.conf" \
  734. -v ${CERT_PATH}:${CERT_PATH} \
  735. -v ${WEB_PATH}:${WEB_PATH} \
  736. nginx:1.20-alpine
  737. if [[ -n $(docker ps -q -f "name=^trojan-panel-nginx$" -f "status=running") ]]; then
  738. echo_content skyBlue "---> Nginx installation completed"
  739. else
  740. echo_content red "---> Nginx installation fails or runs abnormally, please try to repair or uninstall and reinstall"
  741. exit 0
  742. fi
  743. else
  744. echo_content skyBlue "---> You have installed Nginx"
  745. fi
  746. }
  747. # Install a web server
  748. install_reverse_proxy() {
  749. if [[ -z $(docker ps -a -q -f "name=^trojan-panel-caddy$|^trojan-panel-nginx$") ]]; then
  750. echo_content green "---> Install a web server"
  751. while :; do
  752. echo_content yellow "1. Install Caddy2+https (recommend)"
  753. echo_content yellow "2. Install Nginx"
  754. echo_content yellow "3. Not install"
  755. read -r -p "Please select (default: 1): " whether_install_reverse_proxy
  756. [[ -z "${whether_install_reverse_proxy}" ]] && whether_install_reverse_proxy=1
  757. case ${whether_install_reverse_proxy} in
  758. 1)
  759. install_caddy2
  760. break
  761. ;;
  762. 2)
  763. install_nginx
  764. break
  765. ;;
  766. 3)
  767. break
  768. ;;
  769. *)
  770. echo_content red "No such option"
  771. continue
  772. ;;
  773. esac
  774. done
  775. echo_content skyBlue "---> Web server installation completed"
  776. fi
  777. }
  778. # Set certificate
  779. install_cert() {
  780. if [[ -z "$(cat "${DOMAIN_FILE}")" ]]; then
  781. echo_content green "---> Set certificate"
  782. while :; do
  783. echo_content yellow "1. Custom certificate"
  784. echo_content yellow "2. Not set"
  785. read -r -p "Please select (default: 1): " whether_install_cert
  786. [[ -z "${whether_install_cert}" ]] && whether_install_cert=1
  787. case ${whether_install_cert} in
  788. 1)
  789. install_custom_cert "custom_cert"
  790. break
  791. ;;
  792. 2)
  793. break
  794. ;;
  795. *)
  796. echo_content red "No such option"
  797. continue
  798. ;;
  799. esac
  800. done
  801. echo_content green "---> Certificate setup completed"
  802. fi
  803. }
  804. # Install MariaDB
  805. install_mariadb() {
  806. if [[ -z $(docker ps -a -q -f "name=^trojan-panel-mariadb$") ]]; then
  807. echo_content green "---> Install MariaDB"
  808. read -r -p "Please enter the port of MariaDB (default: 9507): " mariadb_port
  809. [[ -z "${mariadb_port}" ]] && mariadb_port=9507
  810. read -r -p "Please enter the username of MariaDB (default: root): " mariadb_user
  811. [[ -z "${mariadb_user}" ]] && mariadb_user="root"
  812. while read -r -p "Please enter the password of MariaDB (required): " mariadb_pas; do
  813. if [[ -z "${mariadb_pas}" ]]; then
  814. echo_content red "Password can not be empty"
  815. else
  816. break
  817. fi
  818. done
  819. if [[ "${mariadb_user}" == "root" ]]; then
  820. docker pull mariadb:10.7.3 &&
  821. docker run -d --name trojan-panel-mariadb --restart always \
  822. --network=host \
  823. -e MYSQL_DATABASE="trojan_panel_db" \
  824. -e MYSQL_ROOT_PASSWORD="${mariadb_pas}" \
  825. -e TZ=Asia/Shanghai \
  826. mariadb:10.7.3 \
  827. --port ${mariadb_port} \
  828. --character-set-server=utf8mb4 \
  829. --collation-server=utf8mb4_unicode_ci
  830. else
  831. docker pull mariadb:10.7.3 &&
  832. docker run -d --name trojan-panel-mariadb --restart always \
  833. --network=host \
  834. -e MYSQL_DATABASE="trojan_panel_db" \
  835. -e MYSQL_ROOT_PASSWORD="${mariadb_pas}" \
  836. -e MYSQL_USER="${mariadb_user}" \
  837. -e MYSQL_PASSWORD="${mariadb_pas}" \
  838. -e TZ=Asia/Shanghai \
  839. mariadb:10.7.3 \
  840. --port ${mariadb_port} \
  841. --character-set-server=utf8mb4 \
  842. --collation-server=utf8mb4_unicode_ci
  843. fi
  844. if [[ -n $(docker ps -q -f "name=^trojan-panel-mariadb$" -f "status=running") ]]; then
  845. echo_content skyBlue "---> MariaDB installation completed"
  846. echo_content yellow "---> The MariaDB password of root (please keep it safe): ${mariadb_pas}"
  847. if [[ "${mariadb_user}" != "root" ]]; then
  848. echo_content yellow "---> The MariaDB password of ${mariadb_user} (please keep it safe): ${mariadb_pas}"
  849. fi
  850. else
  851. echo_content red "---> MariaDB installation fails or runs abnormally, please try to repair or uninstall and reinstall"
  852. exit 0
  853. fi
  854. else
  855. echo_content skyBlue "---> You have installed MariaDB"
  856. fi
  857. }
  858. # Install Redis
  859. install_redis() {
  860. if [[ -z $(docker ps -a -q -f "name=^trojan-panel-redis$") ]]; then
  861. echo_content green "---> Install Redis"
  862. read -r -p "Please enter the port of Redis (default: 6378): " redis_port
  863. [[ -z "${redis_port}" ]] && redis_port=6378
  864. while read -r -p "Please enter the Redis password (required): " redis_pass; do
  865. if [[ -z "${redis_pass}" ]]; then
  866. echo_content red "Password can not be empty"
  867. else
  868. break
  869. fi
  870. done
  871. docker pull redis:6.2.7 &&
  872. docker run -d --name trojan-panel-redis --restart always \
  873. --network=host \
  874. redis:6.2.7 \
  875. redis-server --requirepass "${redis_pass}" --port "${redis_port}"
  876. if [[ -n $(docker ps -q -f "name=^trojan-panel-redis$" -f "status=running") ]]; then
  877. echo_content skyBlue "---> Redis installation completed"
  878. echo_content yellow "---> Redis password (please keep it safe): ${redis_pass}"
  879. else
  880. echo_content red "---> Redis installation fails or runs abnormally, please try to repair or uninstall and reinstall"
  881. exit 0
  882. fi
  883. else
  884. echo_content skyBlue "---> You have installed Redis"
  885. fi
  886. }
  887. # Trojan Panel Frontend Nginx http configuration file
  888. ui_http_config() {
  889. cat >${UI_NGINX_CONFIG} <<-EOF
  890. server {
  891. listen ${trojan_panel_ui_port};
  892. server_name localhost;
  893. location / {
  894. root ${TROJAN_PANEL_UI_DATA};
  895. index index.html index.htm;
  896. }
  897. location /api {
  898. proxy_pass http://${trojan_panel_ip}:${trojan_panel_server_port};
  899. }
  900. error_page 497 http://\$host:${trojan_panel_ui_port}\$request_uri;
  901. error_page 500 502 503 504 /50x.html;
  902. location = /50x.html {
  903. root /usr/share/nginx/html;
  904. }
  905. }
  906. EOF
  907. }
  908. # Trojan Panel Frontend Nginx https configuration file
  909. ui_https_config() {
  910. cat >${UI_NGINX_CONFIG} <<-EOF
  911. server {
  912. listen ${trojan_panel_ui_port} ssl;
  913. server_name localhost;
  914. # force ssl
  915. ssl on;
  916. ssl_certificate ${CERT_PATH}${domain}.crt;
  917. ssl_certificate_key ${CERT_PATH}${domain}.key;
  918. # cache validity period
  919. ssl_session_timeout 5m;
  920. # secure link optional encryption protocol
  921. ssl_protocols TLSv1.3;
  922. # encryption algorithm
  923. ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
  924. # use server-side preferred algorithm
  925. ssl_prefer_server_ciphers on;
  926. #access_log /var/log/nginx/host.access.log main;
  927. location / {
  928. root ${TROJAN_PANEL_UI_DATA};
  929. index index.html index.htm;
  930. }
  931. location /api {
  932. proxy_pass http://${trojan_panel_ip}:${trojan_panel_server_port};
  933. }
  934. #error_page 404 /404.html;
  935. #497 http->https
  936. error_page 497 https://\$host:${trojan_panel_ui_port}\$request_uri;
  937. # redirect server error pages to the static page /50x.html
  938. #
  939. error_page 500 502 503 504 /50x.html;
  940. location = /50x.html {
  941. root /usr/share/nginx/html;
  942. }
  943. }
  944. EOF
  945. }
  946. # Install Trojan Panel Frontend
  947. install_trojan_panel_ui() {
  948. if [[ -z $(docker ps -a -q -f "name=^trojan-panel-ui$") ]]; then
  949. echo_content green "---> Install Trojan Panel Frontend"
  950. read -r -p "Please enter the IP address of the Trojan Panel Backend (default: local host): " trojan_panel_ip
  951. [[ -z "${trojan_panel_ip}" ]] && trojan_panel_ip="127.0.0.1"
  952. read -r -p "Please enter the service port of the Trojan Panel Backend (default: 8081): " trojan_panel_server_port
  953. [[ -z "${trojan_panel_server_port}" ]] && trojan_panel_server_port=8081
  954. read -r -p "Please enter the port of the Trojan Panel Frontend (default: 8888): " trojan_panel_ui_port
  955. [[ -z "${trojan_panel_ui_port}" ]] && trojan_panel_ui_port="8888"
  956. while read -r -p "Please choose whether to enable https on the Trojan Panel Frontend? (0/off 1/on default: 1): " ui_https; do
  957. if [[ -z ${ui_https} || ${ui_https} == 1 ]]; then
  958. install_custom_cert "custom_cert"
  959. domain=$(cat "${DOMAIN_FILE}")
  960. ui_https_config
  961. break
  962. elif [[ ${ui_https} == 0 ]]; then
  963. ui_http_config
  964. break
  965. else
  966. echo_content red "Cannot enter other characters except 1 and 2"
  967. fi
  968. done
  969. docker pull jonssonyan/trojan-panel-ui &&
  970. docker run -d --name trojan-panel-ui --restart always \
  971. --network=host \
  972. -v "${UI_NGINX_CONFIG}":"/etc/nginx/conf.d/default.conf" \
  973. -v ${CERT_PATH}:${CERT_PATH} \
  974. jonssonyan/trojan-panel-ui
  975. if [[ -n $(docker ps -q -f "name=^trojan-panel-ui$" -f "status=running") ]]; then
  976. echo_content skyBlue "---> Trojan Panel Frontend installation completed"
  977. https_flag=$([[ -z ${ui_https} || ${ui_https} == 1 ]] && echo "https" || echo "http")
  978. domain_or_ip=$([[ -z ${domain} || "${domain}" == "custom_cert" ]] && echo "ip" || echo "${domain}")
  979. echo_content red "\n=============================================================="
  980. echo_content skyBlue "Trojan Panel Frontend installed successfully"
  981. echo_content yellow "Web management panel address: ${https_flag}://${domain_or_ip}:${trojan_panel_ui_port}"
  982. echo_content red "\n=============================================================="
  983. else
  984. echo_content red "---> Trojan Panel Frontend installation fails or runs abnormally, please try to repair or uninstall and reinstall"
  985. exit 0
  986. fi
  987. else
  988. echo_content skyBlue "---> You have installed the Trojan Panel Frontend"
  989. fi
  990. }
  991. # Install Trojan Panel Backend
  992. install_trojan_panel() {
  993. if [[ -z $(docker ps -a -q -f "name=^trojan-panel$") ]]; then
  994. echo_content green "---> Install Trojan Panel Backend"
  995. read -r -p "Please enter the service port of the Trojan Panel Backend (default: 8081): " trojan_panel_port
  996. [[ -z "${trojan_panel_port}" ]] && trojan_panel_port=8081
  997. read -r -p "Please enter the IP address of MariaDB (default: local host): " mariadb_ip
  998. [[ -z "${mariadb_ip}" ]] && mariadb_ip="127.0.0.1"
  999. read -r -p "Please enter the port of MariaDB (default: 9507): " mariadb_port
  1000. [[ -z "${mariadb_port}" ]] && mariadb_port=9507
  1001. read -r -p "Please enter the username of MariaDB (default: root): " mariadb_user
  1002. [[ -z "${mariadb_user}" ]] && mariadb_user="root"
  1003. while read -r -p "Please enter the password of MariaDB (required): " mariadb_pas; do
  1004. if [[ -z "${mariadb_pas}" ]]; then
  1005. echo_content red "Password can not be empty"
  1006. else
  1007. break
  1008. fi
  1009. done
  1010. docker exec trojan-panel-mariadb mysql -h"${mariadb_ip}" -P"${mariadb_port}" -u"${mariadb_user}" -p"${mariadb_pas}" -e "create database if not exists trojan_panel_db;" &>/dev/null
  1011. read -r -p "Please enter the IP address of Redis (default: local host): " redis_host
  1012. [[ -z "${redis_host}" ]] && redis_host="127.0.0.1"
  1013. read -r -p "Please enter the port of Redis (default: 6378): " redis_port
  1014. [[ -z "${redis_port}" ]] && redis_port=6378
  1015. while read -r -p "Please enter the Redis password (required): " redis_pass; do
  1016. if [[ -z "${redis_pass}" ]]; then
  1017. echo_content red "Password can not be empty"
  1018. else
  1019. break
  1020. fi
  1021. done
  1022. docker exec trojan-panel-redis redis-cli -h "${redis_host}" -p "${redis_port}" -a "${redis_pass}" -e "flushall" &>/dev/null
  1023. docker pull jonssonyan/trojan-panel &&
  1024. docker run -d --name trojan-panel --restart always \
  1025. --network=host \
  1026. -v ${WEB_PATH}:${TROJAN_PANEL_WEBFILE} \
  1027. -v ${TROJAN_PANEL_LOGS}:${TROJAN_PANEL_LOGS} \
  1028. -v ${TROJAN_PANEL_CONFIG}:${TROJAN_PANEL_CONFIG} \
  1029. -v /etc/localtime:/etc/localtime \
  1030. -e GIN_MODE=release \
  1031. -e "mariadb_ip=${mariadb_ip}" \
  1032. -e "mariadb_port=${mariadb_port}" \
  1033. -e "mariadb_user=${mariadb_user}" \
  1034. -e "mariadb_pas=${mariadb_pas}" \
  1035. -e "redis_host=${redis_host}" \
  1036. -e "redis_port=${redis_port}" \
  1037. -e "redis_pass=${redis_pass}" \
  1038. -e "server_port=${trojan_panel_port}" \
  1039. jonssonyan/trojan-panel
  1040. if [[ -n $(docker ps -q -f "name=^trojan-panel$" -f "status=running") ]]; then
  1041. echo_content skyBlue "---> Trojan Panel Backend installation completed"
  1042. echo_content red "\n=============================================================="
  1043. echo_content skyBlue "Trojan Panel Backend installed successfully"
  1044. echo_content yellow "MariaDB ${mariadb_user} password (please keep it safe): ${mariadb_pas}"
  1045. echo_content yellow "Redis password (please keep it safe): ${redis_pass}"
  1046. echo_content yellow "System administrator Default username: sysadmin Default password: 123456 Please log in to the management panel to change the password in time"
  1047. echo_content red "\n=============================================================="
  1048. else
  1049. echo_content red "---> Trojan Panel Backend installation fails or runs abnormally, please try to repair or uninstall and reinstall"
  1050. exit 0
  1051. fi
  1052. else
  1053. echo_content skyBlue "---> You have installed the Trojan Panel Backend"
  1054. fi
  1055. }
  1056. # Install Trojan Panel Core
  1057. install_trojan_panel_core() {
  1058. if [[ -z $(docker ps -a -q -f "name=^trojan-panel-core$") ]]; then
  1059. echo_content green "---> Install Trojan Panel Core"
  1060. read -r -p "Please enter the service port of the Trojan Panel Core (default: 8082): " trojan_panel_core_port
  1061. [[ -z "${trojan_panel_core_port}" ]] && trojan_panel_core_port=8082
  1062. read -r -p "Please enter the IP address of MariaDB (default: local host): " mariadb_ip
  1063. [[ -z "${mariadb_ip}" ]] && mariadb_ip="127.0.0.1"
  1064. read -r -p "Please enter the port of MariaDB (default: 9507): " mariadb_port
  1065. [[ -z "${mariadb_port}" ]] && mariadb_port=9507
  1066. read -r -p "Please enter the username of MariaDB (default: root): " mariadb_user
  1067. [[ -z "${mariadb_user}" ]] && mariadb_user="root"
  1068. while read -r -p "Please enter the password of MariaDB (required): " mariadb_pas; do
  1069. if [[ -z "${mariadb_pas}" ]]; then
  1070. echo_content red "Password can not be empty"
  1071. else
  1072. break
  1073. fi
  1074. done
  1075. read -r -p "Please enter the database name (default: trojan_panel_db): " database
  1076. [[ -z "${database}" ]] && database="trojan_panel_db"
  1077. read -r -p "Please enter the user table name of the database (default: account): " account_table
  1078. [[ -z "${account_table}" ]] && account_table="account"
  1079. read -r -p "Please enter the IP address of Redis (default: local host): " redis_host
  1080. [[ -z "${redis_host}" ]] && redis_host="127.0.0.1"
  1081. read -r -p "Please enter the port of Redis (default: 6378): " redis_port
  1082. [[ -z "${redis_port}" ]] && redis_port=6378
  1083. while read -r -p "Please enter the Redis password (required): " redis_pass; do
  1084. if [[ -z "${redis_pass}" ]]; then
  1085. echo_content red "Password can not be empty"
  1086. else
  1087. break
  1088. fi
  1089. done
  1090. read -r -p "Please enter the API port (default: 8100): " grpc_port
  1091. [[ -z "${grpc_port}" ]] && grpc_port=8100
  1092. domain=$(cat "${DOMAIN_FILE}")
  1093. docker pull jonssonyan/trojan-panel-core &&
  1094. docker run -d --name trojan-panel-core --restart always \
  1095. --network=host \
  1096. -v ${TROJAN_PANEL_CORE_DATA}bin/xray/config:${TROJAN_PANEL_CORE_DATA}bin/xray/config \
  1097. -v ${TROJAN_PANEL_CORE_DATA}bin/trojango/config:${TROJAN_PANEL_CORE_DATA}bin/trojango/config \
  1098. -v ${TROJAN_PANEL_CORE_DATA}bin/hysteria/config:${TROJAN_PANEL_CORE_DATA}bin/hysteria/config \
  1099. -v ${TROJAN_PANEL_CORE_DATA}bin/naiveproxy/config:${TROJAN_PANEL_CORE_DATA}bin/naiveproxy/config \
  1100. -v ${TROJAN_PANEL_CORE_LOGS}:${TROJAN_PANEL_CORE_LOGS} \
  1101. -v ${TROJAN_PANEL_CORE_CONFIG}:${TROJAN_PANEL_CORE_CONFIG} \
  1102. -v ${CERT_PATH}:${CERT_PATH} \
  1103. -v ${WEB_PATH}:${WEB_PATH} \
  1104. -v /etc/localtime:/etc/localtime \
  1105. -e GIN_MODE=release \
  1106. -e "mariadb_ip=${mariadb_ip}" \
  1107. -e "mariadb_port=${mariadb_port}" \
  1108. -e "mariadb_user=${mariadb_user}" \
  1109. -e "mariadb_pas=${mariadb_pas}" \
  1110. -e "database=${database}" \
  1111. -e "account-table=${account_table}" \
  1112. -e "redis_host=${redis_host}" \
  1113. -e "redis_port=${redis_port}" \
  1114. -e "redis_pass=${redis_pass}" \
  1115. -e "crt_path=${CERT_PATH}${domain}.crt" \
  1116. -e "key_path=${CERT_PATH}${domain}.key" \
  1117. -e "grpc_port=${grpc_port}" \
  1118. -e "server_port=${trojan_panel_core_port}" \
  1119. jonssonyan/trojan-panel-core
  1120. if [[ -n $(docker ps -q -f "name=^trojan-panel-core$" -f "status=running") ]]; then
  1121. echo_content skyBlue "---> Trojan Panel Core installation completed"
  1122. else
  1123. echo_content red "---> Trojan Panel Core installation fails or runs abnormally, please try to repair or uninstall and reinstall"
  1124. exit 0
  1125. fi
  1126. else
  1127. echo_content skyBlue "---> You have installed the Trojan Panel Core"
  1128. fi
  1129. }
  1130. # Update Trojan Panel database structure
  1131. update_trojan_panel_database() {
  1132. echo_content skyBlue "---> Update Trojan Panel database structure"
  1133. if [[ "${trojan_panel_current_version}" == "v1.3.1" ]]; then
  1134. docker exec trojan-panel-mariadb mysql -h"${mariadb_ip}" -P"${mariadb_port}" -u"${mariadb_user}" -p"${mariadb_pas}" -Dtrojan_panel_db -e "${sql_200}" &>/dev/null &&
  1135. trojan_panel_current_version="v2.0.0"
  1136. fi
  1137. version_200_203=("v2.0.0" "v2.0.1" "v2.0.2")
  1138. if [[ "${version_200_203[*]}" =~ "${trojan_panel_current_version}" ]]; then
  1139. docker exec trojan-panel-mariadb mysql -h"${mariadb_ip}" -P"${mariadb_port}" -u"${mariadb_user}" -p"${mariadb_pas}" -Dtrojan_panel_db -e "${sql_203}" &>/dev/null &&
  1140. trojan_panel_current_version="v2.0.3"
  1141. fi
  1142. version_203_205=("v2.0.3" "v2.0.4")
  1143. if [[ "${version_203_205[*]}" =~ "${trojan_panel_current_version}" ]]; then
  1144. docker exec trojan-panel-mariadb mysql -h"${mariadb_ip}" -P"${mariadb_port}" -u"${mariadb_user}" -p"${mariadb_pas}" -Dtrojan_panel_db -e "${sql_205}" &>/dev/null &&
  1145. trojan_panel_current_version="v2.0.5"
  1146. fi
  1147. version_205_210=("v2.0.5")
  1148. if [[ "${version_205_210[*]}" =~ "${trojan_panel_current_version}" ]]; then
  1149. if [[ -z "$(cat "${DOMAIN_FILE}")" ]]; then
  1150. docker rm -f trojan-panel-caddy
  1151. rm -rf /tpdata/caddy/srv/
  1152. rm -rf /tpdata/caddy/cert/
  1153. rm -f /tpdata/caddy/domain.lock
  1154. install_reverse_proxy
  1155. cp /tpdata/nginx/default.conf ${UI_NGINX_CONFIG} &&
  1156. sed -i "s#/tpdata/caddy/cert/#${CERT_PATH}#g" ${UI_NGINX_CONFIG}
  1157. fi
  1158. docker exec trojan-panel-mariadb mysql -h"${mariadb_ip}" -P"${mariadb_port}" -u"${mariadb_user}" -p"${mariadb_pas}" -Dtrojan_panel_db -e "${sql_210}" &>/dev/null &&
  1159. trojan_panel_current_version="v2.1.0"
  1160. fi
  1161. version_210_211=("v2.1.0")
  1162. if [[ "${version_210_211[*]}" =~ "${trojan_panel_current_version}" ]]; then
  1163. docker exec trojan-panel-mariadb mysql -h"${mariadb_ip}" -P"${mariadb_port}" -u"${mariadb_user}" -p"${mariadb_pas}" -Dtrojan_panel_db -e "${sql_211}" &>/dev/null &&
  1164. trojan_panel_current_version="v2.1.1"
  1165. fi
  1166. version_211_212=("v2.1.1")
  1167. if [[ "${version_211_212[*]}" =~ "${trojan_panel_current_version}" ]]; then
  1168. docker exec trojan-panel-mariadb mysql -h"${mariadb_ip}" -P"${mariadb_port}" -u"${mariadb_user}" -p"${mariadb_pas}" -Dtrojan_panel_db -e "${sql_212}" &>/dev/null &&
  1169. trojan_panel_current_version="v2.1.2"
  1170. fi
  1171. version_212_214=("v2.1.2" "v2.1.3")
  1172. if [[ "${version_212_214[*]}" =~ "${trojan_panel_current_version}" ]]; then
  1173. docker cp trojan-panel:${trojan_panel_config_path} ${trojan_panel_config_path} &&
  1174. trojan_panel_current_version="v2.1.4" &&
  1175. echo '[server]
  1176. port=8081' >>${trojan_panel_config_path}
  1177. docker rm -f trojan-panel-ui &&
  1178. docker rmi -f jonssonyan/trojan-panel-ui
  1179. docker pull jonssonyan/trojan-panel-ui &&
  1180. docker run -d --name trojan-panel-ui --restart always \
  1181. --network=host \
  1182. -v "${UI_NGINX_CONFIG}":"/etc/nginx/conf.d/default.conf" \
  1183. -v ${CERT_PATH}:${CERT_PATH} \
  1184. jonssonyan/trojan-panel-ui
  1185. fi
  1186. version_214_215=("v2.1.4")
  1187. if [[ "${version_214_215[*]}" =~ "${trojan_panel_current_version}" ]]; then
  1188. docker exec trojan-panel-mariadb mysql -h"${mariadb_ip}" -P"${mariadb_port}" -u"${mariadb_user}" -p"${mariadb_pas}" -Dtrojan_panel_db -e "${sql_215}" &>/dev/null &&
  1189. trojan_panel_current_version="v2.1.5"
  1190. fi
  1191. echo_content skyBlue "---> Trojan Panel database structure update completed"
  1192. }
  1193. # Update Trojan Panel Core database structure
  1194. update_trojan_panel_core_database() {
  1195. echo_content skyBlue "---> Update Trojan Panel Core database structure"
  1196. version_204_210=("v2.0.4")
  1197. if [[ "${version_204_210[*]}" =~ "${trojan_panel_core_current_version}" ]]; then
  1198. if [[ -z "$(cat "${DOMAIN_FILE}")" ]]; then
  1199. docker rm -f trojan-panel-caddy
  1200. rm -rf /tpdata/caddy/srv/
  1201. rm -rf /tpdata/caddy/cert/
  1202. rm -f /tpdata/caddy/domain.lock
  1203. install_reverse_proxy
  1204. cp /tpdata/nginx/default.conf ${UI_NGINX_CONFIG} &&
  1205. sed -i "s#/tpdata/caddy/cert/#${CERT_PATH}#g" ${UI_NGINX_CONFIG}
  1206. fi
  1207. trojan_panel_core_current_version="v2.1.0"
  1208. fi
  1209. version_210_211=("v2.1.0")
  1210. if [[ "${version_210_211[*]}" =~ "${trojan_panel_core_current_version}" ]]; then
  1211. docker cp trojan-panel-core:${trojan_panel_core_config_path} ${trojan_panel_core_config_path} &&
  1212. trojan_panel_core_current_version="v2.1.1" &&
  1213. echo '[server]
  1214. port=8082' >>${trojan_panel_core_config_path}
  1215. fi
  1216. echo_content skyBlue "---> Trojan Panel Core database structure update completed"
  1217. }
  1218. # Update Trojan Panel Frontend
  1219. update_trojan_panel_ui() {
  1220. if [[ -z $(docker ps -a -q -f "name=^trojan-panel-ui$") ]]; then
  1221. echo_content red "---> Please install the Trojan Panel Frontend first"
  1222. exit 0
  1223. fi
  1224. trojan_panel_ui_current_version=$(docker exec trojan-panel-ui cat ${TROJAN_PANEL_UI_DATA}version)
  1225. if [[ -z "${trojan_panel_ui_current_version}" || ! "${trojan_panel_ui_current_version}" =~ ^v.* ]]; then
  1226. echo_content red "---> The current version does not support online updates"
  1227. exit 0
  1228. fi
  1229. echo_content yellow "Tip: The current version of the Trojan Panel Frontend (trojan-panel-ui) is ${trojan_panel_ui_current_version} the latest version is ${trojan_panel_ui_latest_version}"
  1230. if [[ "${trojan_panel_ui_current_version}" != "${trojan_panel_ui_latest_version}" ]]; then
  1231. echo_content green "---> Update Trojan Panel Frontend"
  1232. docker rm -f trojan-panel-ui &&
  1233. docker rmi -f jonssonyan/trojan-panel-ui
  1234. docker pull jonssonyan/trojan-panel-ui &&
  1235. docker run -d --name trojan-panel-ui --restart always \
  1236. --network=host \
  1237. -v "${UI_NGINX_CONFIG}":"/etc/nginx/conf.d/default.conf" \
  1238. -v ${CERT_PATH}:${CERT_PATH} \
  1239. jonssonyan/trojan-panel-ui
  1240. if [[ -n $(docker ps -q -f "name=^trojan-panel-ui$" -f "status=running") ]]; then
  1241. echo_content skyBlue "---> Trojan Panel Frontend update completed"
  1242. else
  1243. echo_content red "---> Trojan Panel Frontend update fails or runs abnormally, please try to repair or uninstall and reinstall"
  1244. fi
  1245. else
  1246. echo_content skyBlue "---> You have installed the latest version of the Trojan Panel Frontend"
  1247. fi
  1248. }
  1249. # Update Trojan Panel Backend
  1250. update_trojan_panel() {
  1251. if [[ -z $(docker ps -a -q -f "name=^trojan-panel$") ]]; then
  1252. echo_content red "---> Please install the Trojan Panel Backend first"
  1253. exit 0
  1254. fi
  1255. trojan_panel_current_version=$(docker exec trojan-panel ./trojan-panel -version)
  1256. if [[ -z "${trojan_panel_current_version}" || ! "${trojan_panel_current_version}" =~ ^v.* ]]; then
  1257. echo_content red "---> The current version does not support online updates"
  1258. exit 0
  1259. fi
  1260. echo_content yellow "Tip: The current version of the Trojan Panel Backend (trojan-panel) is ${trojan_panel_current_version} The latest version is ${trojan_panel_latest_version}"
  1261. if [[ "${trojan_panel_current_version}" != "${trojan_panel_latest_version}" ]]; then
  1262. echo_content green "---> Update Trojan Panel Backend"
  1263. mariadb_ip=$(get_ini_value ${trojan_panel_config_path} mysql.host)
  1264. mariadb_port=$(get_ini_value ${trojan_panel_config_path} mysql.port)
  1265. mariadb_user=$(get_ini_value ${trojan_panel_config_path} mysql.user)
  1266. mariadb_pas=$(get_ini_value ${trojan_panel_config_path} mysql.password)
  1267. redis_host=$(get_ini_value ${trojan_panel_config_path} redis.host)
  1268. redis_port=$(get_ini_value ${trojan_panel_config_path} redis.port)
  1269. redis_pass=$(get_ini_value ${trojan_panel_config_path} redis.password)
  1270. trojan_panel_port=$(get_ini_value ${trojan_panel_config_path} server.port)
  1271. update_trojan_panel_database
  1272. docker exec trojan-panel-redis redis-cli -h "${redis_host}" -p "${redis_port}" -a "${redis_pass}" -e "flushall" &>/dev/null
  1273. docker rm -f trojan-panel &&
  1274. docker rmi -f jonssonyan/trojan-panel
  1275. docker pull jonssonyan/trojan-panel &&
  1276. docker run -d --name trojan-panel --restart always \
  1277. --network=host \
  1278. -v ${WEB_PATH}:${TROJAN_PANEL_WEBFILE} \
  1279. -v ${TROJAN_PANEL_LOGS}:${TROJAN_PANEL_LOGS} \
  1280. -v ${TROJAN_PANEL_CONFIG}:${TROJAN_PANEL_CONFIG} \
  1281. -v /etc/localtime:/etc/localtime \
  1282. -e GIN_MODE=release \
  1283. -e "mariadb_ip=${mariadb_ip}" \
  1284. -e "mariadb_port=${mariadb_port}" \
  1285. -e "mariadb_user=${mariadb_user}" \
  1286. -e "mariadb_pas=${mariadb_pas}" \
  1287. -e "redis_host=${redis_host}" \
  1288. -e "redis_port=${redis_port}" \
  1289. -e "redis_pass=${redis_pass}" \
  1290. -e "server_port=${trojan_panel_port}" \
  1291. jonssonyan/trojan-panel
  1292. if [[ -n $(docker ps -q -f "name=^trojan-panel$" -f "status=running") ]]; then
  1293. echo_content skyBlue "---> Trojan Panel backend update completed"
  1294. else
  1295. echo_content red "---> Trojan Panel Backend update fails or runs abnormally, please try to repair or uninstall and reinstall"
  1296. fi
  1297. else
  1298. echo_content skyBlue "---> You have installed the latest version of the Trojan Panel Backend"
  1299. fi
  1300. }
  1301. # Update Trojan Panel Core
  1302. update_trojan_panel_core() {
  1303. if [[ -z $(docker ps -a -q -f "name=^trojan-panel-core$") ]]; then
  1304. echo_content red "---> Please install the Trojan Panel Core first"
  1305. exit 0
  1306. fi
  1307. trojan_panel_core_current_version=$(docker exec trojan-panel-core ./trojan-panel-core -version)
  1308. if [[ -z "${trojan_panel_core_current_version}" || ! "${trojan_panel_core_current_version}" =~ ^v.* ]]; then
  1309. echo_content red "---> The current version does not support online updates"
  1310. exit 0
  1311. fi
  1312. echo_content yellow "Tip: The current version of the Trojan Panel Core (trojan-panel-core) is ${trojan_panel_core_current_version} The latest version is ${trojan_panel_core_latest_version}"
  1313. if [[ "${trojan_panel_core_current_version}" != "${trojan_panel_core_latest_version}" ]]; then
  1314. echo_content green "---> Update Trojan Panel Core"
  1315. mariadb_ip=$(get_ini_value ${trojan_panel_core_config_path} mysql.host)
  1316. mariadb_port=$(get_ini_value ${trojan_panel_core_config_path} mysql.port)
  1317. mariadb_user=$(get_ini_value ${trojan_panel_core_config_path} mysql.user)
  1318. mariadb_pas=$(get_ini_value ${trojan_panel_core_config_path} mysql.password)
  1319. redis_host=$(get_ini_value ${trojan_panel_core_config_path} redis.host)
  1320. redis_port=$(get_ini_value ${trojan_panel_core_config_path} redis.port)
  1321. redis_pass=$(get_ini_value ${trojan_panel_core_config_path} redis.password)
  1322. grpc_port=$(get_ini_value ${trojan_panel_core_config_path} grpc.port)
  1323. trojan_panel_core_port=$(get_ini_value ${trojan_panel_core_config_path} server.port)
  1324. update_trojan_panel_core_database
  1325. docker exec trojan-panel-redis redis-cli -h "${redis_host}" -p "${redis_port}" -a "${redis_pass}" -e "flushall" &>/dev/null
  1326. docker rm -f trojan-panel-core &&
  1327. docker rmi -f jonssonyan/trojan-panel-core
  1328. domain=$(cat "${DOMAIN_FILE}")
  1329. docker pull jonssonyan/trojan-panel-core &&
  1330. docker run -d --name trojan-panel-core --restart always \
  1331. --network=host \
  1332. -v ${TROJAN_PANEL_CORE_DATA}bin/xray/config:${TROJAN_PANEL_CORE_DATA}bin/xray/config \
  1333. -v ${TROJAN_PANEL_CORE_DATA}bin/trojango/config:${TROJAN_PANEL_CORE_DATA}bin/trojango/config \
  1334. -v ${TROJAN_PANEL_CORE_DATA}bin/hysteria/config:${TROJAN_PANEL_CORE_DATA}bin/hysteria/config \
  1335. -v ${TROJAN_PANEL_CORE_DATA}bin/naiveproxy/config:${TROJAN_PANEL_CORE_DATA}bin/naiveproxy/config \
  1336. -v ${TROJAN_PANEL_CORE_LOGS}:${TROJAN_PANEL_CORE_LOGS} \
  1337. -v ${TROJAN_PANEL_CORE_CONFIG}:${TROJAN_PANEL_CORE_CONFIG} \
  1338. -v ${CERT_PATH}:${CERT_PATH} \
  1339. -v ${WEB_PATH}:${WEB_PATH} \
  1340. -v /etc/localtime:/etc/localtime \
  1341. -e GIN_MODE=release \
  1342. -e "mariadb_ip=${mariadb_ip}" \
  1343. -e "mariadb_port=${mariadb_port}" \
  1344. -e "mariadb_user=${mariadb_user}" \
  1345. -e "mariadb_pas=${mariadb_pas}" \
  1346. -e "database=${database}" \
  1347. -e "account-table=${account_table}" \
  1348. -e "redis_host=${redis_host}" \
  1349. -e "redis_port=${redis_port}" \
  1350. -e "redis_pass=${redis_pass}" \
  1351. -e "crt_path=${CERT_PATH}${domain}.crt" \
  1352. -e "key_path=${CERT_PATH}${domain}.key" \
  1353. -e "grpc_port=${grpc_port}" \
  1354. -e "server_port=${trojan_panel_core_port}" \
  1355. jonssonyan/trojan-panel-core
  1356. if [[ -n $(docker ps -q -f "name=^trojan-panel-core$" -f "status=running") ]]; then
  1357. echo_content skyBlue "---> Trojan Panel Core update completed"
  1358. else
  1359. echo_content red "---> Trojan Panel Core update fails or runs abnormally, please try to repair or uninstall and reinstall"
  1360. fi
  1361. else
  1362. echo_content skyBlue "---> You have installed the latest version of the Trojan Panel Core"
  1363. fi
  1364. }
  1365. # Uninstall Caddy2+https
  1366. uninstall_caddy2() {
  1367. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-caddy$") ]]; then
  1368. echo_content green "---> Uninstall Caddy2+https"
  1369. docker rm -f trojan-panel-caddy &&
  1370. rm -rf ${CADDY_DATA}
  1371. echo_content skyBlue "---> Caddy2+https uninstallation completed"
  1372. else
  1373. echo_content red "---> Please install Caddy2+https first"
  1374. fi
  1375. }
  1376. # Uninstall Nginx
  1377. uninstall_nginx() {
  1378. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-nginx") ]]; then
  1379. echo_content green "---> Uninstall Nginx"
  1380. docker rm -f trojan-panel-nginx &&
  1381. rm -rf ${NGINX_DATA}
  1382. echo_content skyBlue "---> Nginx uninstallation completed"
  1383. else
  1384. echo_content red "---> Please install Nginx first"
  1385. fi
  1386. }
  1387. # Uninstall MariaDB
  1388. uninstall_mariadb() {
  1389. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-mariadb$") ]]; then
  1390. echo_content green "---> Uninstall MariaDB"
  1391. docker rm -f trojan-panel-mariadb &&
  1392. rm -rf ${MARIA_DATA}
  1393. echo_content skyBlue "---> MariaDB uninstall completed"
  1394. else
  1395. echo_content red "---> Please install MariaDB first"
  1396. fi
  1397. }
  1398. # Uninstall Redis
  1399. uninstall_redis() {
  1400. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-redis$") ]]; then
  1401. echo_content green "---> Uninstall Redis"
  1402. docker rm -f trojan-panel-redis &&
  1403. rm -rf ${REDIS_DATA}
  1404. echo_content skyBlue "---> Redis uninstall completed"
  1405. else
  1406. echo_content red "---> Please install Redis first"
  1407. fi
  1408. }
  1409. # Uninstall Trojan Panel Frontend
  1410. uninstall_trojan_panel_ui() {
  1411. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-ui$") ]]; then
  1412. echo_content green "---> Uninstall Trojan Panel Frontend"
  1413. docker rm -f trojan-panel-ui &&
  1414. docker rmi -f jonssonyan/trojan-panel-ui &&
  1415. rm -rf ${TROJAN_PANEL_UI_DATA}
  1416. echo_content skyBlue "---> Trojan Panel Frontend uninstallation completed"
  1417. else
  1418. echo_content red "---> Please install the Trojan Panel Frontend first"
  1419. fi
  1420. }
  1421. # Uninstall Trojan Panel Backend
  1422. uninstall_trojan_panel() {
  1423. if [[ -n $(docker ps -a -q -f "name=^trojan-panel$") ]]; then
  1424. echo_content green "---> Uninstall Trojan Panel Backend"
  1425. docker rm -f trojan-panel &&
  1426. docker rmi -f jonssonyan/trojan-panel &&
  1427. rm -rf ${TROJAN_PANEL_DATA}
  1428. echo_content skyBlue "---> Trojan Panel Backend uninstallation completed"
  1429. else
  1430. echo_content red "---> Please install the Trojan Panel Backend first"
  1431. fi
  1432. }
  1433. # Uninstall Trojan Panel Core
  1434. uninstall_trojan_panel_core() {
  1435. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-core$") ]]; then
  1436. echo_content green "---> Uninstall Trojan Panel Core"
  1437. docker rm -f trojan-panel-core &&
  1438. docker rmi -f jonssonyan/trojan-panel-core &&
  1439. rm -rf ${TROJAN_PANEL_CORE_DATA}
  1440. echo_content skyBlue "---> Trojan Panel Core uninstallation completed"
  1441. else
  1442. echo_content red "---> Please install the Trojan Panel Core first"
  1443. fi
  1444. }
  1445. # Uninstall all Trojan Panel related containers
  1446. uninstall_all() {
  1447. echo_content green "---> Uninstall all Trojan Panel related containers"
  1448. docker rm -f $(docker ps -a -q -f "name=^trojan-panel")
  1449. docker rmi -f $(docker images | grep "^jonssonyan/trojan-panel" | awk '{print $3}')
  1450. rm -rf ${TP_DATA}
  1451. echo_content skyBlue "---> Uninstall all Trojan Panel related containers completed"
  1452. }
  1453. # Modify Trojan Panel Frontend port
  1454. update_trojan_panel_ui_port() {
  1455. if [[ -n $(docker ps -q -f "name=^trojan-panel-ui$" -f "status=running") ]]; then
  1456. echo_content green "---> Modify Trojan Panel Frontend port"
  1457. trojan_panel_ui_port=$(grep 'listen.*ssl' ${UI_NGINX_CONFIG} | awk '{print $2}')
  1458. if [[ -z "${trojan_panel_ui_port}" ]]; then
  1459. ui_https=0
  1460. trojan_panel_ui_port=$(grep -oP 'listen\s+\K\d+' ${UI_NGINX_CONFIG} | awk 'NR==1')
  1461. fi
  1462. if [[ -z "${trojan_panel_ui_port}" ]]; then
  1463. echo_content red "---> Trojan Panel Frontend port not queried"
  1464. exit 0
  1465. fi
  1466. echo_content yellow "Tip: The current port of the Trojan Panel Frontend (trojan-panel-ui) is ${trojan_panel_ui_port}"
  1467. read -r -p "Please enter the new port of the Trojan Panel Frontend (default: 8888): " trojan_panel_ui_port
  1468. [[ -z "${trojan_panel_ui_port}" ]] && trojan_panel_ui_port="8888"
  1469. if [[ ${ui_https} == 0 ]]; then
  1470. # http
  1471. sed -i "s/listen.*;/listen ${trojan_panel_ui_port};/g" ${UI_NGINX_CONFIG} &&
  1472. sed -i "s/http:\/\/\$host:.*\$request_uri;/http:\/\/\$host:${trojan_panel_ui_port}\$request_uri;/g" ${UI_NGINX_CONFIG} &&
  1473. docker restart trojan-panel-ui
  1474. else
  1475. # https
  1476. sed -i "s/listen.*ssl;/listen ${trojan_panel_ui_port} ssl;/g" ${UI_NGINX_CONFIG} &&
  1477. sed -i "s/https:\/\/\$host:.*\$request_uri;/https:\/\/\$host:${trojan_panel_ui_port}\$request_uri;/g" ${UI_NGINX_CONFIG} &&
  1478. docker restart trojan-panel-ui
  1479. fi
  1480. if [[ "$?" == "0" ]]; then
  1481. echo_content skyBlue "---> Trojan Panel Frontend port modification completed"
  1482. else
  1483. echo_content red "---> Trojan Panel Frontend port modification failed"
  1484. fi
  1485. else
  1486. echo_content red "---> The Trojan Panel Frontend is not installed or is running abnormally, please repair or uninstall and reinstall and try again"
  1487. fi
  1488. }
  1489. # Refresh Redis cache
  1490. redis_flush_all() {
  1491. if [[ -z $(docker ps -a -q -f "name=^trojan-panel-redis$") ]]; then
  1492. echo_content red "---> Please install Redis first"
  1493. exit 0
  1494. fi
  1495. if [[ -z $(docker ps -q -f "name=^trojan-panel-redis$" -f "status=running") ]]; then
  1496. echo_content red "---> Redis is running abnormally"
  1497. exit 0
  1498. fi
  1499. echo_content green "---> Refresh Redis cache"
  1500. read -r -p "Please enter the IP address of Redis (default: local host): " redis_host
  1501. [[ -z "${redis_host}" ]] && redis_host="127.0.0.1"
  1502. read -r -p "Please enter the port of Redis (default: 6378): " redis_port
  1503. [[ -z "${redis_port}" ]] && redis_port=6378
  1504. while read -r -p "Please enter the Redis password (required): " redis_pass; do
  1505. if [[ -z "${redis_pass}" ]]; then
  1506. echo_content red "Password can not be empty"
  1507. else
  1508. break
  1509. fi
  1510. done
  1511. docker exec trojan-panel-redis redis-cli -h "${redis_host}" -p "${redis_port}" -a "${redis_pass}" -e "flushall" &>/dev/null
  1512. echo_content skyBlue "---> Redis cache refresh completed"
  1513. }
  1514. # Replace certificate
  1515. change_cert() {
  1516. domain_1=$(cat "${DOMAIN_FILE}")
  1517. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-caddy$") ]]; then
  1518. docker rm -f trojan-panel-caddy &&
  1519. rm -rf ${CADDY_LOG}* &&
  1520. echo "" >${CADDY_CONFIG} &&
  1521. rm -rf ${WEB_PATH}*
  1522. fi
  1523. rm -rf ${CERT_PATH}* &&
  1524. echo "" >${DOMAIN_FILE}
  1525. install_reverse_proxy
  1526. install_cert
  1527. domain_2=$(cat "${DOMAIN_FILE}")
  1528. if [[ -n "${domain_1}" && -n "${domain_2}" ]]; then
  1529. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-nginx$") ]]; then
  1530. sed -i "s/${domain_1}/${domain_2}/g" ${NGINX_CONFIG} &&
  1531. docker restart trojan-panel-nginx
  1532. fi
  1533. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-ui$") ]]; then
  1534. sed -i "s/${domain_1}/${domain_2}/g" ${UI_NGINX_DATA} &&
  1535. docker restart trojan-panel-ui
  1536. fi
  1537. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-core$") ]]; then
  1538. find /tpdata/trojan-panel-core/bin/ -type f -exec sed -i "s/${domain_1}/${domain_2}/g" {} + &&
  1539. sed -i "s/${domain_1}/${domain_2}/g" ${trojan_panel_core_config_path} &&
  1540. docker restart trojan-panel-core
  1541. fi
  1542. fi
  1543. }
  1544. # Forgot sysadmin password
  1545. forget_pass() {
  1546. while :; do
  1547. echo_content yellow "1. Query MariaDB password"
  1548. echo_content yellow "2. Query Redis password"
  1549. echo_content yellow "3. Reset the username and password of the admin panel system administrator"
  1550. echo_content yellow "4. Quit"
  1551. read -r -p "Please choose (default: 4): " forget_pass_option
  1552. [[ -z "${forget_pass_option}" ]] && forget_pass_option=4
  1553. case ${forget_pass_option} in
  1554. 1)
  1555. if [[ -n $(docker ps -a -q -f "name=^trojan-panel$") ]]; then
  1556. mariadb_user=$(get_ini_value ${trojan_panel_config_path} mysql.user)
  1557. mariadb_pas=$(get_ini_value ${trojan_panel_config_path} mysql.password)
  1558. echo_content red "\n=============================================================="
  1559. echo_content yellow "MariaDB ${mariadb_user} password (please keep it safe): ${mariadb_pas}"
  1560. echo_content red "\n=============================================================="
  1561. else
  1562. echo_content red "---> Please install the Trojan Panel Backend first"
  1563. fi
  1564. ;;
  1565. 2)
  1566. if [[ -n $(docker ps -a -q -f "name=^trojan-panel$") ]]; then
  1567. redis_pass=$(get_ini_value ${trojan_panel_config_path} redis.password)
  1568. echo_content red "\n=============================================================="
  1569. echo_content yellow "Redis password (please keep it safe): ${redis_pass}"
  1570. echo_content red "\n=============================================================="
  1571. else
  1572. echo_content red "---> Please install the Trojan Panel Backend first"
  1573. fi
  1574. ;;
  1575. 3)
  1576. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-mariadb$") ]]; then
  1577. read -r -p "Please enter the IP address of MariaDB (default: local host): " mariadb_ip
  1578. [[ -z "${mariadb_ip}" ]] && mariadb_ip="127.0.0.1"
  1579. read -r -p "Please enter the port of MariaDB (default: 9507): " mariadb_port
  1580. [[ -z "${mariadb_port}" ]] && mariadb_port=9507
  1581. read -r -p "Please enter the username of MariaDB (default: root): " mariadb_user
  1582. [[ -z "${mariadb_user}" ]] && mariadb_user="root"
  1583. while read -r -p "Please enter the password of MariaDB (required): " mariadb_pas; do
  1584. if [[ -z "${mariadb_pas}" ]]; then
  1585. echo_content red "Password can not be empty"
  1586. else
  1587. break
  1588. fi
  1589. done
  1590. docker exec trojan-panel-mariadb mysql -h"${mariadb_ip}" -P"${mariadb_port}" -u"${mariadb_user}" -p"${mariadb_pas}" -Dtrojan_panel_db -e "update account set username = 'sysadmin',pass = 'tFjD2X1F6i9FfWp2GDU5Vbi1conuaChDKIYbw9zMFrqvMoSz',hash='4366294571b8b267d9cf15b56660f0a70659568a86fc270a52fdc9e5' where id = 1 limit 1"
  1591. if [[ "$?" == "0" ]]; then
  1592. echo_content red "\n=============================================================="
  1593. echo_content yellow "System administrator Default username: sysadmin Default password: 123456 Please log in to the management panel to change the password in time"
  1594. echo_content red "\n=============================================================="
  1595. else
  1596. echo_content red "Admin panel sysadmin username and password reset failed"
  1597. fi
  1598. else
  1599. echo_content red "---> Please install the MariaDB first"
  1600. fi
  1601. ;;
  1602. 4)
  1603. break
  1604. ;;
  1605. *)
  1606. echo_content red "No such option"
  1607. continue
  1608. ;;
  1609. esac
  1610. done
  1611. }
  1612. # Fault detection
  1613. failure_testing() {
  1614. echo_content green "---> Start troubleshooting"
  1615. if [[ ! $(docker -v 2>/dev/null) ]]; then
  1616. echo_content red "---> Docker is running abnormally"
  1617. else
  1618. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-caddy$") ]]; then
  1619. if [[ -z $(docker ps -q -f "name=^trojan-panel-caddy$" -f "status=running") ]]; then
  1620. echo_content red "---> Caddy2 is running abnormally and the running log is as follows:"
  1621. docker logs trojan-panel-caddy
  1622. fi
  1623. domain=$(cat "${DOMAIN_FILE}")
  1624. if [[ -n ${domain} && ! -f "${CERT_PATH}${domain}.crt" ]]; then
  1625. echo_content red "---> The certificate application is abnormal, please try 1. Change the sub-domain name to re-build 2. Restart the server to re-apply for the certificate 3. Re-build and select the custom certificate option"
  1626. if [[ -f ${CADDY_LOG}error.log ]]; then
  1627. echo_content red "Caddy2 error log is as follows:"
  1628. tail -n 20 ${CADDY_LOG}error.log | grep error
  1629. fi
  1630. fi
  1631. fi
  1632. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-mariadb$") && -z $(docker ps -q -f "name=^trojan-panel-mariadb$" -f "status=running") ]]; then
  1633. echo_content red "---> The MariaDB is running abnormally and the running log is as follows:"
  1634. docker logs trojan-panel-mariadb
  1635. fi
  1636. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-redis$") && -z $(docker ps -q -f "name=^trojan-panel-redis$" -f "status=running") ]]; then
  1637. echo_content red "---> The Redis is running abnormally and the running log is as follows:"
  1638. docker logs trojan-panel-redis
  1639. fi
  1640. if [[ -n $(docker ps -a -q -f "name=^trojan-panel$") && -z $(docker ps -q -f "name=^trojan-panel$" -f "status=running") ]]; then
  1641. echo_content red "---> The Trojan Panel Backend is running abnormally and the running log is as follows:"
  1642. if [[ -f ${TROJAN_PANEL_LOGS}trojan-panel.log ]]; then
  1643. tail -n 20 ${TROJAN_PANEL_LOGS}trojan-panel.log | grep error
  1644. else
  1645. docker logs trojan-panel
  1646. fi
  1647. fi
  1648. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-ui$") && -z $(docker ps -q -f "name=^trojan-panel-ui$" -f "status=running") ]]; then
  1649. echo_content red "---> The Trojan Panel Frontend is running abnormally and the running log is as follows:"
  1650. docker logs trojan-panel-ui
  1651. fi
  1652. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-core$") && -z $(docker ps -q -f "name=^trojan-panel-core$" -f "status=running") ]]; then
  1653. echo_content red "---> The Trojan Panel Core is running abnormally and the running log is as follows:"
  1654. if [[ -f ${TROJAN_PANEL_CORE_LOGS}trojan-panel.log ]]; then
  1655. tail -n 20 ${TROJAN_PANEL_CORE_LOGS}trojan-panel.log | grep error
  1656. else
  1657. docker logs trojan-panel-core
  1658. fi
  1659. fi
  1660. fi
  1661. echo_content green "---> Troubleshooting ended"
  1662. }
  1663. log_query() {
  1664. while :; do
  1665. echo_content skyBlue "Applications that can query logs are as follows:"
  1666. echo_content yellow "1. Trojan Panel Backend"
  1667. echo_content yellow "2. Trojan Panel Frontend"
  1668. echo_content yellow "3. Quit"
  1669. read -r -p "Please select an application (default: 1): " select_log_query_type
  1670. [[ -z "${select_log_query_type}" ]] && select_log_query_type=1
  1671. case ${select_log_query_type} in
  1672. 1)
  1673. log_file_path=${TROJAN_PANEL_LOGS}trojan-panel.log
  1674. ;;
  1675. 2)
  1676. log_file_path=${TROJAN_PANEL_CORE_LOGS}trojan-panel-core.log
  1677. ;;
  1678. 3)
  1679. break
  1680. ;;
  1681. *)
  1682. echo_content red "No such option"
  1683. continue
  1684. ;;
  1685. esac
  1686. read -r -p "Please enter the number of rows to query (default: 20): " select_log_query_line_type
  1687. [[ -z "${select_log_query_line_type}" ]] && select_log_query_line_type=20
  1688. if [[ -f ${log_file_path} ]]; then
  1689. echo_content skyBlue "The log is as follows:"
  1690. tail -n ${select_log_query_line_type} ${log_file_path}
  1691. else
  1692. echo_content red "No log file exists"
  1693. fi
  1694. done
  1695. }
  1696. version_query() {
  1697. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-ui$") && -n $(docker ps -q -f "name=^trojan-panel-ui$" -f "status=running") ]]; then
  1698. trojan_panel_ui_current_version=$(docker exec trojan-panel-ui cat ${TROJAN_PANEL_UI_DATA}version)
  1699. echo_content yellow "The current version of Trojan Panel Frontend(trojan-panel-ui) is ${trojan_panel_ui_current_version} the latest version is ${trojan_panel_ui_latest_version}"
  1700. fi
  1701. if [[ -n $(docker ps -a -q -f "name=^trojan-panel$") && -n $(docker ps -q -f "name=^trojan-panel$" -f "status=running") ]]; then
  1702. trojan_panel_current_version=$(docker exec trojan-panel ./trojan-panel -version)
  1703. echo_content yellow "The current version of Trojan Panel Backend(trojan-panel) is ${trojan_panel_current_version} the latest version is ${trojan_panel_latest_version}"
  1704. fi
  1705. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-core$") && -n $(docker ps -q -f "name=^trojan-panel-core$" -f "status=running") ]]; then
  1706. trojan_panel_core_current_version=$(docker exec trojan-panel-core ./trojan-panel-core -version)
  1707. echo_content yellow "The current version of Trojan Panel Core(trojan-panel-core) is ${trojan_panel_core_current_version} the latest version is ${trojan_panel_core_latest_version}"
  1708. fi
  1709. }
  1710. main() {
  1711. cd "$HOME" || exit 0
  1712. init_var
  1713. mkdir_tools
  1714. check_sys
  1715. depend_install
  1716. clear
  1717. echo_content red "\n=============================================================="
  1718. echo_content skyBlue "System Required: CentOS 7+/Ubuntu 18+/Debian 10+"
  1719. echo_content skyBlue "Version: v2.2.0"
  1720. echo_content skyBlue "Description: One click Install Trojan Panel server"
  1721. echo_content skyBlue "Author: jonssonyan <https://jonssonyan.com>"
  1722. echo_content skyBlue "Github: https://github.com/trojanpanel"
  1723. echo_content skyBlue "Docs: https://trojanpanel.github.io"
  1724. echo_content red "\n=============================================================="
  1725. echo_content yellow "1. Install Trojan Panel Frontend"
  1726. echo_content yellow "2. Install Trojan Panel Backend"
  1727. echo_content yellow "3. Install Trojan Panel Core"
  1728. echo_content yellow "4. Install Caddy2+https"
  1729. echo_content yellow "5. Install Nginx"
  1730. echo_content yellow "6. Install MariaDB"
  1731. echo_content yellow "7. Install Redis"
  1732. echo_content green "\n=============================================================="
  1733. echo_content yellow "8. Update Trojan Panel Frontend"
  1734. echo_content yellow "9. Update Trojan Panel Backend"
  1735. echo_content yellow "10. Update Trojan Panel Core"
  1736. echo_content green "\n=============================================================="
  1737. echo_content yellow "11. Uninstall Trojan Panel Frontend"
  1738. echo_content yellow "12. Uninstall Trojan Panel Backend"
  1739. echo_content yellow "13. Uninstall Trojan Panel Core"
  1740. echo_content yellow "14. Uninstall Caddy2+https"
  1741. echo_content yellow "15. Uninstall Nginx"
  1742. echo_content yellow "16. Uninstall MariaDB"
  1743. echo_content yellow "17. Uninstall Redis"
  1744. echo_content yellow "18. Uninstall all Trojan Panel related containers"
  1745. echo_content green "\n=============================================================="
  1746. echo_content yellow "19. Modify Trojan Panel Frontend port"
  1747. echo_content yellow "20. Refresh Redis cache"
  1748. echo_content yellow "21. Replace certificate"
  1749. echo_content yellow "22. Forgot sysadmin password"
  1750. echo_content green "\n=============================================================="
  1751. echo_content yellow "23. Fault detection"
  1752. echo_content yellow "24. Log query"
  1753. echo_content yellow "25. Version query"
  1754. read -r -p "Please choose: " selectInstall_type
  1755. case ${selectInstall_type} in
  1756. 1)
  1757. install_docker
  1758. install_reverse_proxy
  1759. install_cert
  1760. install_trojan_panel_ui
  1761. ;;
  1762. 2)
  1763. install_docker
  1764. install_mariadb
  1765. install_redis
  1766. install_trojan_panel
  1767. ;;
  1768. 3)
  1769. install_docker
  1770. install_reverse_proxy
  1771. install_cert
  1772. install_trojan_panel_core
  1773. ;;
  1774. 4)
  1775. install_docker
  1776. install_caddy2
  1777. ;;
  1778. 5)
  1779. install_docker
  1780. install_nginx
  1781. ;;
  1782. 6)
  1783. install_docker
  1784. install_mariadb
  1785. ;;
  1786. 7)
  1787. install_docker
  1788. install_redis
  1789. ;;
  1790. 8)
  1791. update_trojan_panel_ui
  1792. ;;
  1793. 9)
  1794. update_trojan_panel
  1795. ;;
  1796. 10)
  1797. update_trojan_panel_core
  1798. ;;
  1799. 11)
  1800. uninstall_trojan_panel_ui
  1801. ;;
  1802. 12)
  1803. uninstall_trojan_panel
  1804. ;;
  1805. 13)
  1806. uninstall_trojan_panel_core
  1807. ;;
  1808. 14)
  1809. uninstall_caddy2
  1810. ;;
  1811. 15)
  1812. uninstall_nginx
  1813. ;;
  1814. 16)
  1815. uninstall_mariadb
  1816. ;;
  1817. 17)
  1818. uninstall_redis
  1819. ;;
  1820. 18)
  1821. uninstall_all
  1822. ;;
  1823. 19)
  1824. update_trojan_panel_ui_port
  1825. ;;
  1826. 20)
  1827. redis_flush_all
  1828. ;;
  1829. 21)
  1830. change_cert
  1831. ;;
  1832. 22)
  1833. forget_pass
  1834. ;;
  1835. 23)
  1836. failure_testing
  1837. ;;
  1838. 24)
  1839. log_query
  1840. ;;
  1841. 25)
  1842. version_query
  1843. ;;
  1844. *)
  1845. echo_content red "No such option"
  1846. ;;
  1847. esac
  1848. }
  1849. main