install_script.sh 78 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065
  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"
  1047. echo_content yellow "Please log in to the management panel to change the password in time"
  1048. echo_content red "\n=============================================================="
  1049. else
  1050. echo_content red "---> Trojan Panel Backend installation fails or runs abnormally, please try to repair or uninstall and reinstall"
  1051. exit 0
  1052. fi
  1053. else
  1054. echo_content skyBlue "---> You have installed the Trojan Panel Backend"
  1055. fi
  1056. }
  1057. # Install Trojan Panel Core
  1058. install_trojan_panel_core() {
  1059. if [[ -z $(docker ps -a -q -f "name=^trojan-panel-core$") ]]; then
  1060. echo_content green "---> Install Trojan Panel Core"
  1061. read -r -p "Please enter the service port of the Trojan Panel Core (default: 8082): " trojan_panel_core_port
  1062. [[ -z "${trojan_panel_core_port}" ]] && trojan_panel_core_port=8082
  1063. read -r -p "Please enter the IP address of MariaDB (default: local host): " mariadb_ip
  1064. [[ -z "${mariadb_ip}" ]] && mariadb_ip="127.0.0.1"
  1065. read -r -p "Please enter the port of MariaDB (default: 9507): " mariadb_port
  1066. [[ -z "${mariadb_port}" ]] && mariadb_port=9507
  1067. read -r -p "Please enter the username of MariaDB (default: root): " mariadb_user
  1068. [[ -z "${mariadb_user}" ]] && mariadb_user="root"
  1069. while read -r -p "Please enter the password of MariaDB (required): " mariadb_pas; do
  1070. if [[ -z "${mariadb_pas}" ]]; then
  1071. echo_content red "Password can not be empty"
  1072. else
  1073. break
  1074. fi
  1075. done
  1076. read -r -p "Please enter the database name (default: trojan_panel_db): " database
  1077. [[ -z "${database}" ]] && database="trojan_panel_db"
  1078. read -r -p "Please enter the user table name of the database (default: account): " account_table
  1079. [[ -z "${account_table}" ]] && account_table="account"
  1080. read -r -p "Please enter the IP address of Redis (default: local host): " redis_host
  1081. [[ -z "${redis_host}" ]] && redis_host="127.0.0.1"
  1082. read -r -p "Please enter the port of Redis (default: 6378): " redis_port
  1083. [[ -z "${redis_port}" ]] && redis_port=6378
  1084. while read -r -p "Please enter the Redis password (required): " redis_pass; do
  1085. if [[ -z "${redis_pass}" ]]; then
  1086. echo_content red "Password can not be empty"
  1087. else
  1088. break
  1089. fi
  1090. done
  1091. read -r -p "Please enter the API port (default: 8100): " grpc_port
  1092. [[ -z "${grpc_port}" ]] && grpc_port=8100
  1093. domain=$(cat "${DOMAIN_FILE}")
  1094. docker pull jonssonyan/trojan-panel-core &&
  1095. docker run -d --name trojan-panel-core --restart always \
  1096. --network=host \
  1097. -v ${TROJAN_PANEL_CORE_DATA}bin/xray/config:${TROJAN_PANEL_CORE_DATA}bin/xray/config \
  1098. -v ${TROJAN_PANEL_CORE_DATA}bin/trojango/config:${TROJAN_PANEL_CORE_DATA}bin/trojango/config \
  1099. -v ${TROJAN_PANEL_CORE_DATA}bin/hysteria/config:${TROJAN_PANEL_CORE_DATA}bin/hysteria/config \
  1100. -v ${TROJAN_PANEL_CORE_DATA}bin/naiveproxy/config:${TROJAN_PANEL_CORE_DATA}bin/naiveproxy/config \
  1101. -v ${TROJAN_PANEL_CORE_LOGS}:${TROJAN_PANEL_CORE_LOGS} \
  1102. -v ${TROJAN_PANEL_CORE_CONFIG}:${TROJAN_PANEL_CORE_CONFIG} \
  1103. -v ${CERT_PATH}:${CERT_PATH} \
  1104. -v ${WEB_PATH}:${WEB_PATH} \
  1105. -v /etc/localtime:/etc/localtime \
  1106. -e GIN_MODE=release \
  1107. -e "mariadb_ip=${mariadb_ip}" \
  1108. -e "mariadb_port=${mariadb_port}" \
  1109. -e "mariadb_user=${mariadb_user}" \
  1110. -e "mariadb_pas=${mariadb_pas}" \
  1111. -e "database=${database}" \
  1112. -e "account-table=${account_table}" \
  1113. -e "redis_host=${redis_host}" \
  1114. -e "redis_port=${redis_port}" \
  1115. -e "redis_pass=${redis_pass}" \
  1116. -e "crt_path=${CERT_PATH}${domain}.crt" \
  1117. -e "key_path=${CERT_PATH}${domain}.key" \
  1118. -e "grpc_port=${grpc_port}" \
  1119. -e "server_port=${trojan_panel_core_port}" \
  1120. jonssonyan/trojan-panel-core
  1121. if [[ -n $(docker ps -q -f "name=^trojan-panel-core$" -f "status=running") ]]; then
  1122. echo_content skyBlue "---> Trojan Panel Core installation completed"
  1123. else
  1124. echo_content red "---> Trojan Panel Core installation fails or runs abnormally, please try to repair or uninstall and reinstall"
  1125. exit 0
  1126. fi
  1127. else
  1128. echo_content skyBlue "---> You have installed the Trojan Panel Core"
  1129. fi
  1130. }
  1131. # Update Trojan Panel database structure
  1132. update_trojan_panel_database() {
  1133. echo_content skyBlue "---> Update Trojan Panel database structure"
  1134. if [[ "${trojan_panel_current_version}" == "v1.3.1" ]]; then
  1135. 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 &&
  1136. trojan_panel_current_version="v2.0.0"
  1137. fi
  1138. version_200_203=("v2.0.0" "v2.0.1" "v2.0.2")
  1139. if [[ "${version_200_203[*]}" =~ "${trojan_panel_current_version}" ]]; then
  1140. 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 &&
  1141. trojan_panel_current_version="v2.0.3"
  1142. fi
  1143. version_203_205=("v2.0.3" "v2.0.4")
  1144. if [[ "${version_203_205[*]}" =~ "${trojan_panel_current_version}" ]]; then
  1145. 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 &&
  1146. trojan_panel_current_version="v2.0.5"
  1147. fi
  1148. version_205_210=("v2.0.5")
  1149. if [[ "${version_205_210[*]}" =~ "${trojan_panel_current_version}" ]]; then
  1150. if [[ -z "$(cat "${DOMAIN_FILE}")" ]]; then
  1151. docker rm -f trojan-panel-caddy
  1152. rm -rf /tpdata/caddy/srv/
  1153. rm -rf /tpdata/caddy/cert/
  1154. rm -f /tpdata/caddy/domain.lock
  1155. install_reverse_proxy
  1156. cp /tpdata/nginx/default.conf ${UI_NGINX_CONFIG} &&
  1157. sed -i "s#/tpdata/caddy/cert/#${CERT_PATH}#g" ${UI_NGINX_CONFIG}
  1158. fi
  1159. 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 &&
  1160. trojan_panel_current_version="v2.1.0"
  1161. fi
  1162. version_210_211=("v2.1.0")
  1163. if [[ "${version_210_211[*]}" =~ "${trojan_panel_current_version}" ]]; then
  1164. 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 &&
  1165. trojan_panel_current_version="v2.1.1"
  1166. fi
  1167. version_211_212=("v2.1.1")
  1168. if [[ "${version_211_212[*]}" =~ "${trojan_panel_current_version}" ]]; then
  1169. 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 &&
  1170. trojan_panel_current_version="v2.1.2"
  1171. fi
  1172. version_212_214=("v2.1.2" "v2.1.3")
  1173. if [[ "${version_212_214[*]}" =~ "${trojan_panel_current_version}" ]]; then
  1174. docker cp trojan-panel:${trojan_panel_config_path} ${trojan_panel_config_path} &&
  1175. trojan_panel_current_version="v2.1.4" &&
  1176. echo '[server]
  1177. port=8081' >>${trojan_panel_config_path}
  1178. docker rm -f trojan-panel-ui &&
  1179. docker rmi -f jonssonyan/trojan-panel-ui
  1180. docker pull jonssonyan/trojan-panel-ui &&
  1181. docker run -d --name trojan-panel-ui --restart always \
  1182. --network=host \
  1183. -v "${UI_NGINX_CONFIG}":"/etc/nginx/conf.d/default.conf" \
  1184. -v ${CERT_PATH}:${CERT_PATH} \
  1185. jonssonyan/trojan-panel-ui
  1186. fi
  1187. version_214_215=("v2.1.4")
  1188. if [[ "${version_214_215[*]}" =~ "${trojan_panel_current_version}" ]]; then
  1189. 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 &&
  1190. trojan_panel_current_version="v2.1.5"
  1191. fi
  1192. echo_content skyBlue "---> Trojan Panel database structure update completed"
  1193. }
  1194. # Update Trojan Panel Core database structure
  1195. update_trojan_panel_core_database() {
  1196. echo_content skyBlue "---> Update Trojan Panel Core database structure"
  1197. version_204_210=("v2.0.4")
  1198. if [[ "${version_204_210[*]}" =~ "${trojan_panel_core_current_version}" ]]; then
  1199. if [[ -z "$(cat "${DOMAIN_FILE}")" ]]; then
  1200. docker rm -f trojan-panel-caddy
  1201. rm -rf /tpdata/caddy/srv/
  1202. rm -rf /tpdata/caddy/cert/
  1203. rm -f /tpdata/caddy/domain.lock
  1204. install_reverse_proxy
  1205. cp /tpdata/nginx/default.conf ${UI_NGINX_CONFIG} &&
  1206. sed -i "s#/tpdata/caddy/cert/#${CERT_PATH}#g" ${UI_NGINX_CONFIG}
  1207. fi
  1208. trojan_panel_core_current_version="v2.1.0"
  1209. fi
  1210. version_210_211=("v2.1.0")
  1211. if [[ "${version_210_211[*]}" =~ "${trojan_panel_core_current_version}" ]]; then
  1212. docker cp trojan-panel-core:${trojan_panel_core_config_path} ${trojan_panel_core_config_path} &&
  1213. trojan_panel_core_current_version="v2.1.1" &&
  1214. echo '[server]
  1215. port=8082' >>${trojan_panel_core_config_path}
  1216. fi
  1217. echo_content skyBlue "---> Trojan Panel Core database structure update completed"
  1218. }
  1219. # Update Trojan Panel Frontend
  1220. update_trojan_panel_ui() {
  1221. if [[ -z $(docker ps -a -q -f "name=^trojan-panel-ui$") ]]; then
  1222. echo_content red "---> Please install the Trojan Panel Frontend first"
  1223. exit 0
  1224. fi
  1225. trojan_panel_ui_current_version=$(docker exec trojan-panel-ui cat ${TROJAN_PANEL_UI_DATA}version)
  1226. if [[ -z "${trojan_panel_ui_current_version}" || ! "${trojan_panel_ui_current_version}" =~ ^v.* ]]; then
  1227. echo_content red "---> The current version does not support online updates"
  1228. exit 0
  1229. fi
  1230. 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}"
  1231. if [[ "${trojan_panel_ui_current_version}" != "${trojan_panel_ui_latest_version}" ]]; then
  1232. echo_content green "---> Update Trojan Panel Frontend"
  1233. docker rm -f trojan-panel-ui &&
  1234. docker rmi -f jonssonyan/trojan-panel-ui
  1235. docker pull jonssonyan/trojan-panel-ui &&
  1236. docker run -d --name trojan-panel-ui --restart always \
  1237. --network=host \
  1238. -v "${UI_NGINX_CONFIG}":"/etc/nginx/conf.d/default.conf" \
  1239. -v ${CERT_PATH}:${CERT_PATH} \
  1240. jonssonyan/trojan-panel-ui
  1241. if [[ -n $(docker ps -q -f "name=^trojan-panel-ui$" -f "status=running") ]]; then
  1242. echo_content skyBlue "---> Trojan Panel Frontend update completed"
  1243. else
  1244. echo_content red "---> Trojan Panel Frontend update fails or runs abnormally, please try to repair or uninstall and reinstall"
  1245. fi
  1246. else
  1247. echo_content skyBlue "---> You have installed the latest version of the Trojan Panel Frontend"
  1248. fi
  1249. }
  1250. # Update Trojan Panel Backend
  1251. update_trojan_panel() {
  1252. if [[ -z $(docker ps -a -q -f "name=^trojan-panel$") ]]; then
  1253. echo_content red "---> Please install the Trojan Panel Backend first"
  1254. exit 0
  1255. fi
  1256. trojan_panel_current_version=$(docker exec trojan-panel ./trojan-panel -version)
  1257. if [[ -z "${trojan_panel_current_version}" || ! "${trojan_panel_current_version}" =~ ^v.* ]]; then
  1258. echo_content red "---> The current version does not support online updates"
  1259. exit 0
  1260. fi
  1261. 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}"
  1262. if [[ "${trojan_panel_current_version}" != "${trojan_panel_latest_version}" ]]; then
  1263. echo_content green "---> Update Trojan Panel Backend"
  1264. mariadb_ip=$(get_ini_value ${trojan_panel_config_path} mysql.host)
  1265. mariadb_port=$(get_ini_value ${trojan_panel_config_path} mysql.port)
  1266. mariadb_user=$(get_ini_value ${trojan_panel_config_path} mysql.user)
  1267. mariadb_pas=$(get_ini_value ${trojan_panel_config_path} mysql.password)
  1268. redis_host=$(get_ini_value ${trojan_panel_config_path} redis.host)
  1269. redis_port=$(get_ini_value ${trojan_panel_config_path} redis.port)
  1270. redis_pass=$(get_ini_value ${trojan_panel_config_path} redis.password)
  1271. trojan_panel_port=$(get_ini_value ${trojan_panel_config_path} server.port)
  1272. update_trojan_panel_database
  1273. docker exec trojan-panel-redis redis-cli -h "${redis_host}" -p "${redis_port}" -a "${redis_pass}" -e "flushall" &>/dev/null
  1274. docker rm -f trojan-panel &&
  1275. docker rmi -f jonssonyan/trojan-panel
  1276. docker pull jonssonyan/trojan-panel &&
  1277. docker run -d --name trojan-panel --restart always \
  1278. --network=host \
  1279. -v ${WEB_PATH}:${TROJAN_PANEL_WEBFILE} \
  1280. -v ${TROJAN_PANEL_LOGS}:${TROJAN_PANEL_LOGS} \
  1281. -v ${TROJAN_PANEL_CONFIG}:${TROJAN_PANEL_CONFIG} \
  1282. -v /etc/localtime:/etc/localtime \
  1283. -e GIN_MODE=release \
  1284. -e "mariadb_ip=${mariadb_ip}" \
  1285. -e "mariadb_port=${mariadb_port}" \
  1286. -e "mariadb_user=${mariadb_user}" \
  1287. -e "mariadb_pas=${mariadb_pas}" \
  1288. -e "redis_host=${redis_host}" \
  1289. -e "redis_port=${redis_port}" \
  1290. -e "redis_pass=${redis_pass}" \
  1291. -e "server_port=${trojan_panel_port}" \
  1292. jonssonyan/trojan-panel
  1293. if [[ -n $(docker ps -q -f "name=^trojan-panel$" -f "status=running") ]]; then
  1294. echo_content skyBlue "---> Trojan Panel backend update completed"
  1295. else
  1296. echo_content red "---> Trojan Panel Backend update fails or runs abnormally, please try to repair or uninstall and reinstall"
  1297. fi
  1298. else
  1299. echo_content skyBlue "---> You have installed the latest version of the Trojan Panel Backend"
  1300. fi
  1301. }
  1302. # Update Trojan Panel Core
  1303. update_trojan_panel_core() {
  1304. if [[ -z $(docker ps -a -q -f "name=^trojan-panel-core$") ]]; then
  1305. echo_content red "---> Please install the Trojan Panel Core first"
  1306. exit 0
  1307. fi
  1308. trojan_panel_core_current_version=$(docker exec trojan-panel-core ./trojan-panel-core -version)
  1309. if [[ -z "${trojan_panel_core_current_version}" || ! "${trojan_panel_core_current_version}" =~ ^v.* ]]; then
  1310. echo_content red "---> The current version does not support online updates"
  1311. exit 0
  1312. fi
  1313. 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}"
  1314. if [[ "${trojan_panel_core_current_version}" != "${trojan_panel_core_latest_version}" ]]; then
  1315. echo_content green "---> Update Trojan Panel Core"
  1316. mariadb_ip=$(get_ini_value ${trojan_panel_core_config_path} mysql.host)
  1317. mariadb_port=$(get_ini_value ${trojan_panel_core_config_path} mysql.port)
  1318. mariadb_user=$(get_ini_value ${trojan_panel_core_config_path} mysql.user)
  1319. mariadb_pas=$(get_ini_value ${trojan_panel_core_config_path} mysql.password)
  1320. redis_host=$(get_ini_value ${trojan_panel_core_config_path} redis.host)
  1321. redis_port=$(get_ini_value ${trojan_panel_core_config_path} redis.port)
  1322. redis_pass=$(get_ini_value ${trojan_panel_core_config_path} redis.password)
  1323. grpc_port=$(get_ini_value ${trojan_panel_core_config_path} grpc.port)
  1324. trojan_panel_core_port=$(get_ini_value ${trojan_panel_core_config_path} server.port)
  1325. update_trojan_panel_core_database
  1326. docker exec trojan-panel-redis redis-cli -h "${redis_host}" -p "${redis_port}" -a "${redis_pass}" -e "flushall" &>/dev/null
  1327. docker rm -f trojan-panel-core &&
  1328. docker rmi -f jonssonyan/trojan-panel-core
  1329. domain=$(cat "${DOMAIN_FILE}")
  1330. docker pull jonssonyan/trojan-panel-core &&
  1331. docker run -d --name trojan-panel-core --restart always \
  1332. --network=host \
  1333. -v ${TROJAN_PANEL_CORE_DATA}bin/xray/config:${TROJAN_PANEL_CORE_DATA}bin/xray/config \
  1334. -v ${TROJAN_PANEL_CORE_DATA}bin/trojango/config:${TROJAN_PANEL_CORE_DATA}bin/trojango/config \
  1335. -v ${TROJAN_PANEL_CORE_DATA}bin/hysteria/config:${TROJAN_PANEL_CORE_DATA}bin/hysteria/config \
  1336. -v ${TROJAN_PANEL_CORE_DATA}bin/naiveproxy/config:${TROJAN_PANEL_CORE_DATA}bin/naiveproxy/config \
  1337. -v ${TROJAN_PANEL_CORE_LOGS}:${TROJAN_PANEL_CORE_LOGS} \
  1338. -v ${TROJAN_PANEL_CORE_CONFIG}:${TROJAN_PANEL_CORE_CONFIG} \
  1339. -v ${CERT_PATH}:${CERT_PATH} \
  1340. -v ${WEB_PATH}:${WEB_PATH} \
  1341. -v /etc/localtime:/etc/localtime \
  1342. -e GIN_MODE=release \
  1343. -e "mariadb_ip=${mariadb_ip}" \
  1344. -e "mariadb_port=${mariadb_port}" \
  1345. -e "mariadb_user=${mariadb_user}" \
  1346. -e "mariadb_pas=${mariadb_pas}" \
  1347. -e "database=${database}" \
  1348. -e "account-table=${account_table}" \
  1349. -e "redis_host=${redis_host}" \
  1350. -e "redis_port=${redis_port}" \
  1351. -e "redis_pass=${redis_pass}" \
  1352. -e "crt_path=${CERT_PATH}${domain}.crt" \
  1353. -e "key_path=${CERT_PATH}${domain}.key" \
  1354. -e "grpc_port=${grpc_port}" \
  1355. -e "server_port=${trojan_panel_core_port}" \
  1356. jonssonyan/trojan-panel-core
  1357. if [[ -n $(docker ps -q -f "name=^trojan-panel-core$" -f "status=running") ]]; then
  1358. echo_content skyBlue "---> Trojan Panel Core update completed"
  1359. else
  1360. echo_content red "---> Trojan Panel Core update fails or runs abnormally, please try to repair or uninstall and reinstall"
  1361. fi
  1362. else
  1363. echo_content skyBlue "---> You have installed the latest version of the Trojan Panel Core"
  1364. fi
  1365. }
  1366. # Uninstall Caddy2+https
  1367. uninstall_caddy2() {
  1368. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-caddy$") ]]; then
  1369. echo_content green "---> Uninstall Caddy2+https"
  1370. docker rm -f trojan-panel-caddy &&
  1371. rm -rf ${CADDY_DATA}
  1372. echo_content skyBlue "---> Caddy2+https uninstallation completed"
  1373. else
  1374. echo_content red "---> Please install Caddy2+https first"
  1375. fi
  1376. }
  1377. # Uninstall Nginx
  1378. uninstall_nginx() {
  1379. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-nginx") ]]; then
  1380. echo_content green "---> Uninstall Nginx"
  1381. docker rm -f trojan-panel-nginx &&
  1382. rm -rf ${NGINX_DATA}
  1383. echo_content skyBlue "---> Nginx uninstallation completed"
  1384. else
  1385. echo_content red "---> Please install Nginx first"
  1386. fi
  1387. }
  1388. # Uninstall MariaDB
  1389. uninstall_mariadb() {
  1390. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-mariadb$") ]]; then
  1391. echo_content green "---> Uninstall MariaDB"
  1392. docker rm -f trojan-panel-mariadb &&
  1393. rm -rf ${MARIA_DATA}
  1394. echo_content skyBlue "---> MariaDB uninstall completed"
  1395. else
  1396. echo_content red "---> Please install MariaDB first"
  1397. fi
  1398. }
  1399. # Uninstall Redis
  1400. uninstall_redis() {
  1401. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-redis$") ]]; then
  1402. echo_content green "---> Uninstall Redis"
  1403. docker rm -f trojan-panel-redis &&
  1404. rm -rf ${REDIS_DATA}
  1405. echo_content skyBlue "---> Redis uninstall completed"
  1406. else
  1407. echo_content red "---> Please install Redis first"
  1408. fi
  1409. }
  1410. # Uninstall Trojan Panel Frontend
  1411. uninstall_trojan_panel_ui() {
  1412. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-ui$") ]]; then
  1413. echo_content green "---> Uninstall Trojan Panel Frontend"
  1414. docker rm -f trojan-panel-ui &&
  1415. docker rmi -f jonssonyan/trojan-panel-ui &&
  1416. rm -rf ${TROJAN_PANEL_UI_DATA}
  1417. echo_content skyBlue "---> Trojan Panel Frontend uninstallation completed"
  1418. else
  1419. echo_content red "---> Please install the Trojan Panel Frontend first"
  1420. fi
  1421. }
  1422. # Uninstall Trojan Panel Backend
  1423. uninstall_trojan_panel() {
  1424. if [[ -n $(docker ps -a -q -f "name=^trojan-panel$") ]]; then
  1425. echo_content green "---> Uninstall Trojan Panel Backend"
  1426. docker rm -f trojan-panel &&
  1427. docker rmi -f jonssonyan/trojan-panel &&
  1428. rm -rf ${TROJAN_PANEL_DATA}
  1429. echo_content skyBlue "---> Trojan Panel Backend uninstallation completed"
  1430. else
  1431. echo_content red "---> Please install the Trojan Panel Backend first"
  1432. fi
  1433. }
  1434. # Uninstall Trojan Panel Core
  1435. uninstall_trojan_panel_core() {
  1436. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-core$") ]]; then
  1437. echo_content green "---> Uninstall Trojan Panel Core"
  1438. docker rm -f trojan-panel-core &&
  1439. docker rmi -f jonssonyan/trojan-panel-core &&
  1440. rm -rf ${TROJAN_PANEL_CORE_DATA}
  1441. echo_content skyBlue "---> Trojan Panel Core uninstallation completed"
  1442. else
  1443. echo_content red "---> Please install the Trojan Panel Core first"
  1444. fi
  1445. }
  1446. # Uninstall all Trojan Panel related containers
  1447. uninstall_all() {
  1448. echo_content green "---> Uninstall all Trojan Panel related containers"
  1449. docker rm -f $(docker ps -a -q -f "name=^trojan-panel")
  1450. docker rmi -f $(docker images | grep "^jonssonyan/trojan-panel" | awk '{print $3}')
  1451. rm -rf ${TP_DATA}
  1452. echo_content skyBlue "---> Uninstall all Trojan Panel related containers completed"
  1453. }
  1454. # Modify Trojan Panel Frontend port
  1455. update_trojan_panel_ui_port() {
  1456. if [[ -n $(docker ps -q -f "name=^trojan-panel-ui$" -f "status=running") ]]; then
  1457. echo_content green "---> Modify Trojan Panel Frontend port"
  1458. trojan_panel_ui_port=$(grep 'listen.*ssl' ${UI_NGINX_CONFIG} | awk '{print $2}')
  1459. if [[ -z "${trojan_panel_ui_port}" ]]; then
  1460. ui_https=0
  1461. trojan_panel_ui_port=$(grep -oP 'listen\s+\K\d+' ${UI_NGINX_CONFIG} | awk 'NR==1')
  1462. fi
  1463. if [[ -z "${trojan_panel_ui_port}" ]]; then
  1464. echo_content red "---> Trojan Panel Frontend port not queried"
  1465. exit 0
  1466. fi
  1467. echo_content yellow "Tip: The current port of the Trojan Panel Frontend (trojan-panel-ui) is ${trojan_panel_ui_port}"
  1468. read -r -p "Please enter the new port of the Trojan Panel Frontend (default: 8888): " trojan_panel_ui_port
  1469. [[ -z "${trojan_panel_ui_port}" ]] && trojan_panel_ui_port="8888"
  1470. if [[ ${ui_https} == 0 ]]; then
  1471. # http
  1472. sed -i "s/listen.*;/listen ${trojan_panel_ui_port};/g" ${UI_NGINX_CONFIG} &&
  1473. sed -i "s/http:\/\/\$host:.*\$request_uri;/http:\/\/\$host:${trojan_panel_ui_port}\$request_uri;/g" ${UI_NGINX_CONFIG} &&
  1474. docker restart trojan-panel-ui
  1475. else
  1476. # https
  1477. sed -i "s/listen.*ssl;/listen ${trojan_panel_ui_port} ssl;/g" ${UI_NGINX_CONFIG} &&
  1478. sed -i "s/https:\/\/\$host:.*\$request_uri;/https:\/\/\$host:${trojan_panel_ui_port}\$request_uri;/g" ${UI_NGINX_CONFIG} &&
  1479. docker restart trojan-panel-ui
  1480. fi
  1481. if [[ "$?" == "0" ]]; then
  1482. echo_content skyBlue "---> Trojan Panel Frontend port modification completed"
  1483. else
  1484. echo_content red "---> Trojan Panel Frontend port modification failed"
  1485. fi
  1486. else
  1487. echo_content red "---> The Trojan Panel Frontend is not installed or is running abnormally, please repair or uninstall and reinstall and try again"
  1488. fi
  1489. }
  1490. # Refresh Redis cache
  1491. redis_flush_all() {
  1492. if [[ -z $(docker ps -a -q -f "name=^trojan-panel-redis$") ]]; then
  1493. echo_content red "---> Please install Redis first"
  1494. exit 0
  1495. fi
  1496. if [[ -z $(docker ps -q -f "name=^trojan-panel-redis$" -f "status=running") ]]; then
  1497. echo_content red "---> Redis is running abnormally"
  1498. exit 0
  1499. fi
  1500. echo_content green "---> Refresh Redis cache"
  1501. read -r -p "Please enter the IP address of Redis (default: local host): " redis_host
  1502. [[ -z "${redis_host}" ]] && redis_host="127.0.0.1"
  1503. read -r -p "Please enter the port of Redis (default: 6378): " redis_port
  1504. [[ -z "${redis_port}" ]] && redis_port=6378
  1505. while read -r -p "Please enter the Redis password (required): " redis_pass; do
  1506. if [[ -z "${redis_pass}" ]]; then
  1507. echo_content red "Password can not be empty"
  1508. else
  1509. break
  1510. fi
  1511. done
  1512. docker exec trojan-panel-redis redis-cli -h "${redis_host}" -p "${redis_port}" -a "${redis_pass}" -e "flushall" &>/dev/null
  1513. echo_content skyBlue "---> Redis cache refresh completed"
  1514. }
  1515. # Replace certificate
  1516. change_cert() {
  1517. domain_1=$(cat "${DOMAIN_FILE}")
  1518. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-caddy$") ]]; then
  1519. docker rm -f trojan-panel-caddy &&
  1520. rm -rf ${CADDY_LOG}* &&
  1521. echo "" >${CADDY_CONFIG} &&
  1522. rm -rf ${WEB_PATH}*
  1523. fi
  1524. rm -rf ${CERT_PATH}* &&
  1525. echo "" >${DOMAIN_FILE}
  1526. install_reverse_proxy
  1527. install_cert
  1528. domain_2=$(cat "${DOMAIN_FILE}")
  1529. if [[ -n "${domain_1}" && -n "${domain_2}" ]]; then
  1530. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-nginx$") ]]; then
  1531. sed -i "s/${domain_1}/${domain_2}/g" ${NGINX_CONFIG} &&
  1532. docker restart trojan-panel-nginx
  1533. fi
  1534. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-ui$") ]]; then
  1535. sed -i "s/${domain_1}/${domain_2}/g" ${UI_NGINX_DATA} &&
  1536. docker restart trojan-panel-ui
  1537. fi
  1538. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-core$") ]]; then
  1539. find /tpdata/trojan-panel-core/bin/ -type f -exec sed -i "s/${domain_1}/${domain_2}/g" {} + &&
  1540. sed -i "s/${domain_1}/${domain_2}/g" ${trojan_panel_core_config_path} &&
  1541. docker restart trojan-panel-core
  1542. fi
  1543. fi
  1544. }
  1545. # Forgot sysadmin password
  1546. forget_pass() {
  1547. while :; do
  1548. echo_content yellow "1. Query MariaDB password"
  1549. echo_content yellow "2. Query Redis password"
  1550. echo_content yellow "3. Reset the username and password of the admin panel system administrator"
  1551. echo_content yellow "4. Quit"
  1552. read -r -p "Please choose (default: 4): " forget_pass_option
  1553. [[ -z "${forget_pass_option}" ]] && forget_pass_option=4
  1554. case ${forget_pass_option} in
  1555. 1)
  1556. if [[ -n $(docker ps -a -q -f "name=^trojan-panel$") ]]; then
  1557. mariadb_user=$(get_ini_value ${trojan_panel_config_path} mysql.user)
  1558. mariadb_pas=$(get_ini_value ${trojan_panel_config_path} mysql.password)
  1559. echo_content red "\n=============================================================="
  1560. echo_content yellow "MariaDB ${mariadb_user} password (please keep it safe): ${mariadb_pas}"
  1561. echo_content red "\n=============================================================="
  1562. else
  1563. echo_content red "---> Please install the Trojan Panel Backend first"
  1564. fi
  1565. ;;
  1566. 2)
  1567. if [[ -n $(docker ps -a -q -f "name=^trojan-panel$") ]]; then
  1568. redis_pass=$(get_ini_value ${trojan_panel_config_path} redis.password)
  1569. echo_content red "\n=============================================================="
  1570. echo_content yellow "Redis password (please keep it safe): ${redis_pass}"
  1571. echo_content red "\n=============================================================="
  1572. else
  1573. echo_content red "---> Please install the Trojan Panel Backend first"
  1574. fi
  1575. ;;
  1576. 3)
  1577. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-mariadb$") ]]; then
  1578. read -r -p "Please enter the IP address of MariaDB (default: local host): " mariadb_ip
  1579. [[ -z "${mariadb_ip}" ]] && mariadb_ip="127.0.0.1"
  1580. read -r -p "Please enter the port of MariaDB (default: 9507): " mariadb_port
  1581. [[ -z "${mariadb_port}" ]] && mariadb_port=9507
  1582. read -r -p "Please enter the username of MariaDB (default: root): " mariadb_user
  1583. [[ -z "${mariadb_user}" ]] && mariadb_user="root"
  1584. while read -r -p "Please enter the password of MariaDB (required): " mariadb_pas; do
  1585. if [[ -z "${mariadb_pas}" ]]; then
  1586. echo_content red "Password can not be empty"
  1587. else
  1588. break
  1589. fi
  1590. done
  1591. 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"
  1592. if [[ "$?" == "0" ]]; then
  1593. echo_content red "\n=============================================================="
  1594. echo_content yellow "System administrator Default username: sysadmin Default password: 123456"
  1595. echo_content yellow "Please log in to the management panel to change the password in time"
  1596. echo_content red "\n=============================================================="
  1597. else
  1598. echo_content red "Admin panel sysadmin username and password reset failed"
  1599. fi
  1600. else
  1601. echo_content red "---> Please install the MariaDB first"
  1602. fi
  1603. ;;
  1604. 4)
  1605. break
  1606. ;;
  1607. *)
  1608. echo_content red "No such option"
  1609. continue
  1610. ;;
  1611. esac
  1612. done
  1613. }
  1614. # Fault detection
  1615. failure_testing() {
  1616. echo_content green "---> Start troubleshooting"
  1617. if [[ ! $(docker -v 2>/dev/null) ]]; then
  1618. echo_content red "---> Docker is running abnormally"
  1619. else
  1620. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-caddy$") ]]; then
  1621. if [[ -z $(docker ps -q -f "name=^trojan-panel-caddy$" -f "status=running") ]]; then
  1622. echo_content red "---> Caddy2 is running abnormally and the running log is as follows:"
  1623. docker logs trojan-panel-caddy
  1624. fi
  1625. domain=$(cat "${DOMAIN_FILE}")
  1626. if [[ -n ${domain} && ! -f "${CERT_PATH}${domain}.crt" ]]; then
  1627. 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"
  1628. if [[ -f ${CADDY_LOG}error.log ]]; then
  1629. echo_content red "Caddy2 error log is as follows:"
  1630. tail -n 20 ${CADDY_LOG}error.log | grep error
  1631. fi
  1632. fi
  1633. fi
  1634. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-mariadb$") && -z $(docker ps -q -f "name=^trojan-panel-mariadb$" -f "status=running") ]]; then
  1635. echo_content red "---> The MariaDB is running abnormally and the running log is as follows:"
  1636. docker logs trojan-panel-mariadb
  1637. fi
  1638. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-redis$") && -z $(docker ps -q -f "name=^trojan-panel-redis$" -f "status=running") ]]; then
  1639. echo_content red "---> The Redis is running abnormally and the running log is as follows:"
  1640. docker logs trojan-panel-redis
  1641. fi
  1642. if [[ -n $(docker ps -a -q -f "name=^trojan-panel$") && -z $(docker ps -q -f "name=^trojan-panel$" -f "status=running") ]]; then
  1643. echo_content red "---> The Trojan Panel Backend is running abnormally and the running log is as follows:"
  1644. if [[ -f ${TROJAN_PANEL_LOGS}trojan-panel.log ]]; then
  1645. tail -n 20 ${TROJAN_PANEL_LOGS}trojan-panel.log | grep error
  1646. else
  1647. docker logs trojan-panel
  1648. fi
  1649. fi
  1650. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-ui$") && -z $(docker ps -q -f "name=^trojan-panel-ui$" -f "status=running") ]]; then
  1651. echo_content red "---> The Trojan Panel Frontend is running abnormally and the running log is as follows:"
  1652. docker logs trojan-panel-ui
  1653. fi
  1654. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-core$") && -z $(docker ps -q -f "name=^trojan-panel-core$" -f "status=running") ]]; then
  1655. echo_content red "---> The Trojan Panel Core is running abnormally and the running log is as follows:"
  1656. if [[ -f ${TROJAN_PANEL_CORE_LOGS}trojan-panel.log ]]; then
  1657. tail -n 20 ${TROJAN_PANEL_CORE_LOGS}trojan-panel.log | grep error
  1658. else
  1659. docker logs trojan-panel-core
  1660. fi
  1661. fi
  1662. fi
  1663. echo_content green "---> Troubleshooting ended"
  1664. }
  1665. log_query() {
  1666. while :; do
  1667. echo_content skyBlue "Applications that can query logs are as follows:"
  1668. echo_content yellow "1. Trojan Panel Backend"
  1669. echo_content yellow "2. Trojan Panel Frontend"
  1670. echo_content yellow "3. Quit"
  1671. read -r -p "Please select an application (default: 1): " select_log_query_type
  1672. [[ -z "${select_log_query_type}" ]] && select_log_query_type=1
  1673. case ${select_log_query_type} in
  1674. 1)
  1675. log_file_path=${TROJAN_PANEL_LOGS}trojan-panel.log
  1676. ;;
  1677. 2)
  1678. log_file_path=${TROJAN_PANEL_CORE_LOGS}trojan-panel-core.log
  1679. ;;
  1680. 3)
  1681. break
  1682. ;;
  1683. *)
  1684. echo_content red "No such option"
  1685. continue
  1686. ;;
  1687. esac
  1688. read -r -p "Please enter the number of rows to query (default: 20): " select_log_query_line_type
  1689. [[ -z "${select_log_query_line_type}" ]] && select_log_query_line_type=20
  1690. if [[ -f ${log_file_path} ]]; then
  1691. echo_content skyBlue "The log is as follows:"
  1692. tail -n ${select_log_query_line_type} ${log_file_path}
  1693. else
  1694. echo_content red "No log file exists"
  1695. fi
  1696. done
  1697. }
  1698. version_query() {
  1699. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-ui$") && -n $(docker ps -q -f "name=^trojan-panel-ui$" -f "status=running") ]]; then
  1700. trojan_panel_ui_current_version=$(docker exec trojan-panel-ui cat ${TROJAN_PANEL_UI_DATA}version)
  1701. 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}"
  1702. fi
  1703. if [[ -n $(docker ps -a -q -f "name=^trojan-panel$") && -n $(docker ps -q -f "name=^trojan-panel$" -f "status=running") ]]; then
  1704. trojan_panel_current_version=$(docker exec trojan-panel ./trojan-panel -version)
  1705. 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}"
  1706. fi
  1707. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-core$") && -n $(docker ps -q -f "name=^trojan-panel-core$" -f "status=running") ]]; then
  1708. trojan_panel_core_current_version=$(docker exec trojan-panel-core ./trojan-panel-core -version)
  1709. 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}"
  1710. fi
  1711. }
  1712. main() {
  1713. cd "$HOME" || exit 0
  1714. init_var
  1715. mkdir_tools
  1716. check_sys
  1717. depend_install
  1718. clear
  1719. echo_content red "\n=============================================================="
  1720. echo_content skyBlue "System Required: CentOS 7+/Ubuntu 18+/Debian 10+"
  1721. echo_content skyBlue "Version: v2.2.0"
  1722. echo_content skyBlue "Description: One click Install Trojan Panel server"
  1723. echo_content skyBlue "Author: jonssonyan <https://jonssonyan.com>"
  1724. echo_content skyBlue "Github: https://github.com/trojanpanel"
  1725. echo_content skyBlue "Docs: https://trojanpanel.github.io"
  1726. echo_content red "\n=============================================================="
  1727. echo_content yellow "1. Install Trojan Panel Frontend"
  1728. echo_content yellow "2. Install Trojan Panel Backend"
  1729. echo_content yellow "3. Install Trojan Panel Core"
  1730. echo_content yellow "4. Install Caddy2+https"
  1731. echo_content yellow "5. Install Nginx"
  1732. echo_content yellow "6. Install MariaDB"
  1733. echo_content yellow "7. Install Redis"
  1734. echo_content green "\n=============================================================="
  1735. echo_content yellow "8. Update Trojan Panel Frontend"
  1736. echo_content yellow "9. Update Trojan Panel Backend"
  1737. echo_content yellow "10. Update Trojan Panel Core"
  1738. echo_content green "\n=============================================================="
  1739. echo_content yellow "11. Uninstall Trojan Panel Frontend"
  1740. echo_content yellow "12. Uninstall Trojan Panel Backend"
  1741. echo_content yellow "13. Uninstall Trojan Panel Core"
  1742. echo_content yellow "14. Uninstall Caddy2+https"
  1743. echo_content yellow "15. Uninstall Nginx"
  1744. echo_content yellow "16. Uninstall MariaDB"
  1745. echo_content yellow "17. Uninstall Redis"
  1746. echo_content yellow "18. Uninstall all Trojan Panel related containers"
  1747. echo_content green "\n=============================================================="
  1748. echo_content yellow "19. Modify Trojan Panel Frontend port"
  1749. echo_content yellow "20. Refresh Redis cache"
  1750. echo_content yellow "21. Replace certificate"
  1751. echo_content yellow "22. Forgot sysadmin password"
  1752. echo_content green "\n=============================================================="
  1753. echo_content yellow "23. Fault detection"
  1754. echo_content yellow "24. Log query"
  1755. echo_content yellow "25. Version query"
  1756. read -r -p "Please choose: " selectInstall_type
  1757. case ${selectInstall_type} in
  1758. 1)
  1759. install_docker
  1760. install_reverse_proxy
  1761. install_cert
  1762. install_trojan_panel_ui
  1763. ;;
  1764. 2)
  1765. install_docker
  1766. install_mariadb
  1767. install_redis
  1768. install_trojan_panel
  1769. ;;
  1770. 3)
  1771. install_docker
  1772. install_reverse_proxy
  1773. install_cert
  1774. install_trojan_panel_core
  1775. ;;
  1776. 4)
  1777. install_docker
  1778. install_caddy2
  1779. ;;
  1780. 5)
  1781. install_docker
  1782. install_nginx
  1783. ;;
  1784. 6)
  1785. install_docker
  1786. install_mariadb
  1787. ;;
  1788. 7)
  1789. install_docker
  1790. install_redis
  1791. ;;
  1792. 8)
  1793. update_trojan_panel_ui
  1794. ;;
  1795. 9)
  1796. update_trojan_panel
  1797. ;;
  1798. 10)
  1799. update_trojan_panel_core
  1800. ;;
  1801. 11)
  1802. uninstall_trojan_panel_ui
  1803. ;;
  1804. 12)
  1805. uninstall_trojan_panel
  1806. ;;
  1807. 13)
  1808. uninstall_trojan_panel_core
  1809. ;;
  1810. 14)
  1811. uninstall_caddy2
  1812. ;;
  1813. 15)
  1814. uninstall_nginx
  1815. ;;
  1816. 16)
  1817. uninstall_mariadb
  1818. ;;
  1819. 17)
  1820. uninstall_redis
  1821. ;;
  1822. 18)
  1823. uninstall_all
  1824. ;;
  1825. 19)
  1826. update_trojan_panel_ui_port
  1827. ;;
  1828. 20)
  1829. redis_flush_all
  1830. ;;
  1831. 21)
  1832. change_cert
  1833. ;;
  1834. 22)
  1835. forget_pass
  1836. ;;
  1837. 23)
  1838. failure_testing
  1839. ;;
  1840. 24)
  1841. log_query
  1842. ;;
  1843. 25)
  1844. version_query
  1845. ;;
  1846. *)
  1847. echo_content red "No such option"
  1848. ;;
  1849. esac
  1850. }
  1851. main