install_script.sh 78 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062
  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. domain=$(cat "${DOMAIN_FILE}")
  284. if [[ -z "${domain}" ]]; then
  285. while read -r -p "Please enter the file path of the .crt certificate (required): " crt_path; do
  286. if [[ -z "${crt_path}" ]]; then
  287. echo_content red "Path cannot be empty"
  288. else
  289. if [[ ! -f "${crt_path}" ]]; then
  290. echo_content red "The file path for the .crt certificate does not exist"
  291. else
  292. cp "${crt_path}" "${CERT_PATH}$1.crt"
  293. break
  294. fi
  295. fi
  296. done
  297. while read -r -p "Please enter the file path of the .key certificate (required): " key_path; do
  298. if [[ -z "${key_path}" ]]; then
  299. echo_content red "Path cannot be empty"
  300. else
  301. if [[ ! -f "${key_path}" ]]; then
  302. echo_content red "The file path for the .key certificate does not exist"
  303. else
  304. cp "${key_path}" "${CERT_PATH}$1.key"
  305. break
  306. fi
  307. fi
  308. done
  309. cat >${DOMAIN_FILE} <<EOF
  310. $1
  311. EOF
  312. echo_content red "\n=============================================================="
  313. echo_content skyBlue "---> Custom settings certificate installation completed"
  314. echo_content yellow "Certificate Directory: ${CERT_PATH}"
  315. echo_content red "\n=============================================================="
  316. fi
  317. }
  318. # Caddy2 https custom settings certificate configuration file
  319. caddy2_https_config() {
  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. cat >${CADDY_CONFIG} <<EOF
  453. {
  454. "admin":{
  455. "disabled":true
  456. },
  457. "logging":{
  458. "logs":{
  459. "default":{
  460. "writer":{
  461. "output":"file",
  462. "filename":"${CADDY_LOG}error.log"
  463. },
  464. "level":"ERROR"
  465. }
  466. }
  467. },
  468. "storage":{
  469. "module":"file_system",
  470. "root":"${CERT_PATH}"
  471. },
  472. "apps":{
  473. "http":{
  474. "http_port": ${caddy_port},
  475. "servers":{
  476. "srv0":{
  477. "listen":[
  478. ":${caddy_port}"
  479. ],
  480. "routes":[
  481. {
  482. "match":[
  483. {
  484. "host":[
  485. "${domain}"
  486. ]
  487. }
  488. ],
  489. "handle":[
  490. {
  491. "handler":"static_response",
  492. "headers":{
  493. "Location":[
  494. "https://{http.request.host}:${caddy_remote_port}{http.request.uri}"
  495. ]
  496. },
  497. "status_code":301
  498. }
  499. ]
  500. }
  501. ]
  502. },
  503. "srv1":{
  504. "listen":[
  505. ":${caddy_remote_port}"
  506. ],
  507. "routes":[
  508. {
  509. "handle":[
  510. {
  511. "handler":"subroute",
  512. "routes":[
  513. {
  514. "match":[
  515. {
  516. "host":[
  517. "${domain}"
  518. ]
  519. }
  520. ],
  521. "handle":[
  522. {
  523. "handler":"file_server",
  524. "root":"${WEB_PATH}",
  525. "index_names":[
  526. "index.html",
  527. "index.htm"
  528. ]
  529. }
  530. ],
  531. "terminal":true
  532. }
  533. ]
  534. }
  535. ]
  536. }
  537. ],
  538. "tls_connection_policies":[
  539. {
  540. "match":{
  541. "sni":[
  542. "${domain}"
  543. ]
  544. }
  545. }
  546. ],
  547. "automatic_https":{
  548. "disable":true
  549. }
  550. }
  551. }
  552. },
  553. "tls":{
  554. "certificates":{
  555. "automate":[
  556. "${domain}"
  557. ]
  558. },
  559. "automation":{
  560. "policies":[
  561. {
  562. "issuers":[
  563. {
  564. "module":"${ssl_module}",
  565. "email":"${your_email}"
  566. }
  567. ]
  568. }
  569. ]
  570. }
  571. }
  572. }
  573. }
  574. EOF
  575. }
  576. # Install Caddy2
  577. install_caddy2() {
  578. if [[ -z $(docker ps -a -q -f "name=^trojan-panel-caddy$") ]]; then
  579. echo_content green "---> Install Caddy2"
  580. wget --no-check-certificate -O ${WEB_PATH}html.tar.gz -N ${STATIC_HTML} &&
  581. tar -zxvf ${WEB_PATH}html.tar.gz -k -C ${WEB_PATH}
  582. read -r -p "Please enter the port of Caddy2 (default: 80): " caddy_port
  583. [[ -z "${caddy_port}" ]] && caddy_port=80
  584. read -r -p "Please enter the forwarding port of Caddy2 (default: 8863): " caddy_remote_port
  585. [[ -z "${caddy_remote_port}" ]] && caddy_remote_port=8863
  586. echo_content yellow "Tip: Please confirm that the domain name has been resolved to this machine, otherwise the installation may fail"
  587. while read -r -p "Please enter your domain name (required): " domain; do
  588. if [[ -z "${domain}" ]]; then
  589. echo_content red "Domain name cannot be empty"
  590. else
  591. break
  592. fi
  593. done
  594. read -r -p "Please enter your email (optional): " your_email
  595. 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
  596. if [[ -z ${ssl_option} || ${ssl_option} == 1 ]]; then
  597. while read -r -p "Please choose the way to apply for the certificate (1/acme 2/zerossl default: 1: " ssl_module_type; do
  598. if [[ -z "${ssl_module_type}" || ${ssl_module_type} == 1 ]]; then
  599. ssl_module="acme"
  600. CADDY_CERT_DIR="${CERT_PATH}certificates/acme-v02.api.letsencrypt.org-directory/"
  601. break
  602. elif [[ ${ssl_module_type} == 2 ]]; then
  603. ssl_module="zerossl"
  604. CADDY_CERT_DIR="${CERT_PATH}certificates/acme.zerossl.com-v2-dv90/"
  605. break
  606. else
  607. echo_content red "Cannot enter other characters except 1 and 2"
  608. fi
  609. done
  610. caddy2_https_auto_config
  611. break
  612. elif [[ ${ssl_option} == 2 ]]; then
  613. install_custom_cert "${domain}"
  614. caddy2_https_config
  615. break
  616. else
  617. echo_content red "Cannot enter other characters except 1 and 2"
  618. fi
  619. done
  620. # Caddy2 temporary listening port for automatic certificate application
  621. if [[ -n $(lsof -i:${caddy_port},${caddy_remote_port} -t) ]]; then
  622. kill -9 "$(lsof -i:${caddy_port},${caddy_remote_port} -t)"
  623. fi
  624. docker pull caddy:2.6.2 &&
  625. docker run -d --name trojan-panel-caddy --restart always \
  626. --network=host \
  627. -v "${CADDY_CONFIG}":"${CADDY_CONFIG}" \
  628. -v ${CERT_PATH}:"${CADDY_CERT_DIR}${domain}/" \
  629. -v ${WEB_PATH}:${WEB_PATH} \
  630. -v ${CADDY_LOG}:${CADDY_LOG} \
  631. caddy:2.6.2 caddy run --config ${CADDY_CONFIG}
  632. if [[ -n $(docker ps -q -f "name=^trojan-panel-caddy$" -f "status=running") ]]; then
  633. cat >${DOMAIN_FILE} <<EOF
  634. ${domain}
  635. EOF
  636. echo_content red "\n=============================================================="
  637. echo_content skyBlue "---> Caddy2 installation completed"
  638. echo_content yellow "Certificate Directory: ${CERT_PATH}"
  639. echo_content red "\n=============================================================="
  640. else
  641. echo_content red "---> Caddy2 installation fails or runs abnormally, please try to repair or uninstall and reinstall"
  642. exit 0
  643. fi
  644. else
  645. echo_content skyBlue "---> You have installed Caddy2"
  646. fi
  647. }
  648. # Nginx http configuration file
  649. nginx_http_config() {
  650. cat >${NGINX_CONFIG} <<-EOF
  651. server {
  652. listen ${nginx_port};
  653. server_name localhost;
  654. location / {
  655. root ${WEB_PATH};
  656. index index.html index.htm;
  657. }
  658. error_page 497 http://\$host:${nginx_port}\$request_uri;
  659. error_page 500 502 503 504 /50x.html;
  660. location = /50x.html {
  661. root /usr/share/nginx/html;
  662. }
  663. }
  664. EOF
  665. }
  666. # Nginx https configuration file
  667. nginx_https_config() {
  668. cat >${NGINX_CONFIG} <<-EOF
  669. server {
  670. listen ${nginx_port};
  671. server_name localhost;
  672. return 301 http://\$host:${nginx_remote_port}\$request_uri;
  673. }
  674. server {
  675. listen ${nginx_remote_port} ssl;
  676. server_name localhost;
  677. # force ssl
  678. ssl on;
  679. ssl_certificate ${CERT_PATH}${domain}.crt;
  680. ssl_certificate_key ${CERT_PATH}${domain}.key;
  681. # cache validity period
  682. ssl_session_timeout 5m;
  683. # secure link optional encryption protocol
  684. ssl_protocols TLSv1.3;
  685. # encryption algorithm
  686. ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
  687. # use server-side preferred algorithm
  688. ssl_prefer_server_ciphers on;
  689. #access_log /var/log/nginx/host.access.log main;
  690. location / {
  691. root ${WEB_PATH};
  692. index index.html index.htm;
  693. }
  694. #error_page 404 /404.html;
  695. #497 http->https
  696. error_page 497 https://\$host:${nginx_remote_port}\$request_uri;
  697. # redirect server error pages to the static page /50x.html
  698. #
  699. error_page 500 502 503 504 /50x.html;
  700. location = /50x.html {
  701. root /usr/share/nginx/html;
  702. }
  703. }
  704. EOF
  705. }
  706. # Install Nginx
  707. install_nginx() {
  708. if [[ -z $(docker ps -a -q -f "name=^trojan-panel-nginx$") ]]; then
  709. echo_content green "---> Install Nginx"
  710. wget --no-check-certificate -O ${WEB_PATH}html.tar.gz -N ${STATIC_HTML} &&
  711. tar -zxvf ${WEB_PATH}html.tar.gz -k -C ${WEB_PATH}
  712. read -r -p "Please enter the port of Nginx (default: 80): " nginx_port
  713. [[ -z "${nginx_port}" ]] && nginx_port=80
  714. read -r -p "Please enter the forwarding port of Nginx (default: 8863): " nginx_remote_port
  715. [[ -z "${nginx_remote_port}" ]] && nginx_remote_port=8863
  716. while read -r -p "Please choose whether to enable https in Nginx? (0/off 1/on default: 1): " nginx_https; do
  717. if [[ -z ${nginx_https} || ${nginx_https} == 1 ]]; then
  718. install_custom_cert "custom_cert"
  719. domain=$(cat "${DOMAIN_FILE}")
  720. nginx_https_config
  721. break
  722. elif [[ ${nginx_https} == 0 ]]; then
  723. nginx_http_config
  724. break
  725. else
  726. echo_content red "Cannot enter other characters except 1 and 2"
  727. fi
  728. done
  729. docker pull nginx:1.20-alpine &&
  730. docker run -d --name trojan-panel-nginx --restart always \
  731. --network=host \
  732. -v "${NGINX_CONFIG}":"/etc/nginx/conf.d/default.conf" \
  733. -v ${CERT_PATH}:${CERT_PATH} \
  734. -v ${WEB_PATH}:${WEB_PATH} \
  735. nginx:1.20-alpine
  736. if [[ -n $(docker ps -q -f "name=^trojan-panel-nginx$" -f "status=running") ]]; then
  737. echo_content skyBlue "---> Nginx installation completed"
  738. else
  739. echo_content red "---> Nginx installation fails or runs abnormally, please try to repair or uninstall and reinstall"
  740. exit 0
  741. fi
  742. else
  743. echo_content skyBlue "---> You have installed Nginx"
  744. fi
  745. }
  746. # Install a web server
  747. install_reverse_proxy() {
  748. if [[ -z $(docker ps -a -q -f "name=^trojan-panel-caddy$|^trojan-panel-nginx$") ]]; then
  749. echo_content green "---> Install a web server"
  750. while :; do
  751. echo_content yellow "1. Install Caddy2+https (recommend)"
  752. echo_content yellow "2. Install Nginx"
  753. echo_content yellow "3. Not install"
  754. read -r -p "Please select (default: 1): " whether_install_reverse_proxy
  755. [[ -z "${whether_install_reverse_proxy}" ]] && whether_install_reverse_proxy=1
  756. case ${whether_install_reverse_proxy} in
  757. 1)
  758. install_caddy2
  759. break
  760. ;;
  761. 2)
  762. install_nginx
  763. break
  764. ;;
  765. 3)
  766. break
  767. ;;
  768. *)
  769. echo_content red "No such option"
  770. continue
  771. ;;
  772. esac
  773. done
  774. echo_content skyBlue "---> Web server installation completed"
  775. fi
  776. }
  777. # Set certificate
  778. install_cert() {
  779. domain=$(cat "${DOMAIN_FILE}")
  780. if [[ -z "${domain}" ]]; 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 the database (default: 9507): " mariadb_port
  809. [[ -z "${mariadb_port}" ]] && mariadb_port=9507
  810. read -r -p "Please enter the username of the database (default: root): " mariadb_user
  811. [[ -z "${mariadb_user}" ]] && mariadb_user="root"
  812. while read -r -p "Please enter the database password (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 database password of MariaDB root (please keep it safe): ${mariadb_pas}"
  847. if [[ "${mariadb_user}" != "root" ]]; then
  848. echo_content yellow "---> MariaDB ${mariadb_user} database password (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 database 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 installation 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 the database (default: local host): " mariadb_ip
  998. [[ -z "${mariadb_ip}" ]] && mariadb_ip="127.0.0.1"
  999. read -r -p "Please enter the port of the database (default: 9507): " mariadb_port
  1000. [[ -z "${mariadb_port}" ]] && mariadb_port=9507
  1001. read -r -p "Please enter the username of the database (default: root): " mariadb_user
  1002. [[ -z "${mariadb_user}" ]] && mariadb_user="root"
  1003. while read -r -p "Please enter the database password (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 installation 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 the database (default: local host): " mariadb_ip
  1063. [[ -z "${mariadb_ip}" ]] && mariadb_ip="127.0.0.1"
  1064. read -r -p "Please enter the port of the database (default: 9507): " mariadb_port
  1065. [[ -z "${mariadb_port}" ]] && mariadb_port=9507
  1066. read -r -p "Please enter the username of the database (default: root): " mariadb_user
  1067. [[ -z "${mariadb_user}" ]] && mariadb_user="root"
  1068. while read -r -p "Please enter the database password (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. domain=$(cat "${DOMAIN_FILE}")
  1150. if [[ -z "${domain}" ]]; 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. domain=$(cat "${DOMAIN_FILE}")
  1200. if [[ -z "${domain}" ]]; then
  1201. docker rm -f trojan-panel-caddy
  1202. rm -rf /tpdata/caddy/srv/
  1203. rm -rf /tpdata/caddy/cert/
  1204. rm -f /tpdata/caddy/domain.lock
  1205. install_reverse_proxy
  1206. cp /tpdata/nginx/default.conf ${UI_NGINX_CONFIG} &&
  1207. sed -i "s#/tpdata/caddy/cert/#${CERT_PATH}#g" ${UI_NGINX_CONFIG}
  1208. fi
  1209. trojan_panel_core_current_version="v2.1.0"
  1210. fi
  1211. version_210_211=("v2.1.0")
  1212. if [[ "${version_210_211[*]}" =~ "${trojan_panel_core_current_version}" ]]; then
  1213. docker cp trojan-panel-core:${trojan_panel_core_config_path} ${trojan_panel_core_config_path} &&
  1214. trojan_panel_core_current_version="v2.1.1" &&
  1215. echo '[server]
  1216. port=8082' >>${trojan_panel_core_config_path}
  1217. fi
  1218. echo_content skyBlue "---> Trojan Panel Core database structure update completed"
  1219. }
  1220. # Update Trojan Panel Frontend
  1221. update_trojan_panel_ui() {
  1222. if [[ -z $(docker ps -a -q -f "name=^trojan-panel-ui$") ]]; then
  1223. echo_content red "---> Please install the Trojan Panel Frontend first"
  1224. exit 0
  1225. fi
  1226. trojan_panel_ui_current_version=$(docker exec trojan-panel-ui cat ${TROJAN_PANEL_UI_DATA}version)
  1227. if [[ -z "${trojan_panel_ui_current_version}" || ! "${trojan_panel_ui_current_version}" =~ ^v.* ]]; then
  1228. echo_content red "---> The current version does not support online updates"
  1229. exit 0
  1230. fi
  1231. 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}"
  1232. if [[ "${trojan_panel_ui_current_version}" != "${trojan_panel_ui_latest_version}" ]]; then
  1233. echo_content green "---> Update Trojan Panel Frontend"
  1234. docker rm -f trojan-panel-ui &&
  1235. docker rmi -f jonssonyan/trojan-panel-ui
  1236. docker pull jonssonyan/trojan-panel-ui &&
  1237. docker run -d --name trojan-panel-ui --restart always \
  1238. --network=host \
  1239. -v "${UI_NGINX_CONFIG}":"/etc/nginx/conf.d/default.conf" \
  1240. -v ${CERT_PATH}:${CERT_PATH} \
  1241. jonssonyan/trojan-panel-ui
  1242. if [[ -n $(docker ps -q -f "name=^trojan-panel-ui$" -f "status=running") ]]; then
  1243. echo_content skyBlue "---> Trojan Panel Frontend update completed"
  1244. else
  1245. echo_content red "---> Trojan Panel Frontend update fails or runs abnormally, please try to repair or uninstall and reinstall"
  1246. fi
  1247. else
  1248. echo_content skyBlue "---> You have installed the latest version of the Trojan Panel Frontend"
  1249. fi
  1250. }
  1251. # Update Trojan Panel Backend
  1252. update_trojan_panel() {
  1253. if [[ -z $(docker ps -a -q -f "name=^trojan-panel$") ]]; then
  1254. echo_content red "---> Please install the Trojan Panel Backend first"
  1255. exit 0
  1256. fi
  1257. trojan_panel_current_version=$(docker exec trojan-panel ./trojan-panel -version)
  1258. if [[ -z "${trojan_panel_current_version}" || ! "${trojan_panel_current_version}" =~ ^v.* ]]; then
  1259. echo_content red "---> The current version does not support online updates"
  1260. exit 0
  1261. fi
  1262. 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}"
  1263. if [[ "${trojan_panel_current_version}" != "${trojan_panel_latest_version}" ]]; then
  1264. echo_content green "---> Update Trojan Panel Backend"
  1265. mariadb_ip=$(get_ini_value ${trojan_panel_config_path} mysql.host)
  1266. mariadb_port=$(get_ini_value ${trojan_panel_config_path} mysql.port)
  1267. mariadb_user=$(get_ini_value ${trojan_panel_config_path} mysql.user)
  1268. mariadb_pas=$(get_ini_value ${trojan_panel_config_path} mysql.password)
  1269. redis_host=$(get_ini_value ${trojan_panel_config_path} redis.host)
  1270. redis_port=$(get_ini_value ${trojan_panel_config_path} redis.port)
  1271. redis_pass=$(get_ini_value ${trojan_panel_config_path} redis.password)
  1272. trojan_panel_port=$(get_ini_value ${trojan_panel_config_path} server.port)
  1273. update_trojan_panel_database
  1274. docker exec trojan-panel-redis redis-cli -h "${redis_host}" -p "${redis_port}" -a "${redis_pass}" -e "flushall" &>/dev/null
  1275. docker rm -f trojan-panel &&
  1276. docker rmi -f jonssonyan/trojan-panel
  1277. docker pull jonssonyan/trojan-panel &&
  1278. docker run -d --name trojan-panel --restart always \
  1279. --network=host \
  1280. -v ${WEB_PATH}:${TROJAN_PANEL_WEBFILE} \
  1281. -v ${TROJAN_PANEL_LOGS}:${TROJAN_PANEL_LOGS} \
  1282. -v ${TROJAN_PANEL_CONFIG}:${TROJAN_PANEL_CONFIG} \
  1283. -v /etc/localtime:/etc/localtime \
  1284. -e GIN_MODE=release \
  1285. -e "mariadb_ip=${mariadb_ip}" \
  1286. -e "mariadb_port=${mariadb_port}" \
  1287. -e "mariadb_user=${mariadb_user}" \
  1288. -e "mariadb_pas=${mariadb_pas}" \
  1289. -e "redis_host=${redis_host}" \
  1290. -e "redis_port=${redis_port}" \
  1291. -e "redis_pass=${redis_pass}" \
  1292. -e "server_port=${trojan_panel_port}" \
  1293. jonssonyan/trojan-panel
  1294. if [[ -n $(docker ps -q -f "name=^trojan-panel$" -f "status=running") ]]; then
  1295. echo_content skyBlue "---> Trojan Panel backend update completed"
  1296. else
  1297. echo_content red "---> Trojan Panel Backend update fails or runs abnormally, please try to repair or uninstall and reinstall"
  1298. fi
  1299. else
  1300. echo_content skyBlue "---> You have installed the latest version of the Trojan Panel Backend"
  1301. fi
  1302. }
  1303. # Update Trojan Panel Core
  1304. update_trojan_panel_core() {
  1305. if [[ -z $(docker ps -a -q -f "name=^trojan-panel-core$") ]]; then
  1306. echo_content red "---> Please install the Trojan Panel Core first"
  1307. exit 0
  1308. fi
  1309. trojan_panel_core_current_version=$(docker exec trojan-panel-core ./trojan-panel-core -version)
  1310. if [[ -z "${trojan_panel_core_current_version}" || ! "${trojan_panel_core_current_version}" =~ ^v.* ]]; then
  1311. echo_content red "---> The current version does not support online updates"
  1312. exit 0
  1313. fi
  1314. 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}"
  1315. if [[ "${trojan_panel_core_current_version}" != "${trojan_panel_core_latest_version}" ]]; then
  1316. echo_content green "---> Update Trojan Panel Core"
  1317. mariadb_ip=$(get_ini_value ${trojan_panel_core_config_path} mysql.host)
  1318. mariadb_port=$(get_ini_value ${trojan_panel_core_config_path} mysql.port)
  1319. mariadb_user=$(get_ini_value ${trojan_panel_core_config_path} mysql.user)
  1320. mariadb_pas=$(get_ini_value ${trojan_panel_core_config_path} mysql.password)
  1321. redis_host=$(get_ini_value ${trojan_panel_core_config_path} redis.host)
  1322. redis_port=$(get_ini_value ${trojan_panel_core_config_path} redis.port)
  1323. redis_pass=$(get_ini_value ${trojan_panel_core_config_path} redis.password)
  1324. grpc_port=$(get_ini_value ${trojan_panel_core_config_path} grpc.port)
  1325. trojan_panel_core_port=$(get_ini_value ${trojan_panel_core_config_path} server.port)
  1326. update_trojan_panel_core_database
  1327. docker exec trojan-panel-redis redis-cli -h "${redis_host}" -p "${redis_port}" -a "${redis_pass}" -e "flushall" &>/dev/null
  1328. docker rm -f trojan-panel-core &&
  1329. docker rmi -f jonssonyan/trojan-panel-core
  1330. domain=$(cat "${DOMAIN_FILE}")
  1331. docker pull jonssonyan/trojan-panel-core &&
  1332. docker run -d --name trojan-panel-core --restart always \
  1333. --network=host \
  1334. -v ${TROJAN_PANEL_CORE_DATA}bin/xray/config:${TROJAN_PANEL_CORE_DATA}bin/xray/config \
  1335. -v ${TROJAN_PANEL_CORE_DATA}bin/trojango/config:${TROJAN_PANEL_CORE_DATA}bin/trojango/config \
  1336. -v ${TROJAN_PANEL_CORE_DATA}bin/hysteria/config:${TROJAN_PANEL_CORE_DATA}bin/hysteria/config \
  1337. -v ${TROJAN_PANEL_CORE_DATA}bin/naiveproxy/config:${TROJAN_PANEL_CORE_DATA}bin/naiveproxy/config \
  1338. -v ${TROJAN_PANEL_CORE_LOGS}:${TROJAN_PANEL_CORE_LOGS} \
  1339. -v ${TROJAN_PANEL_CORE_CONFIG}:${TROJAN_PANEL_CORE_CONFIG} \
  1340. -v ${CERT_PATH}:${CERT_PATH} \
  1341. -v ${WEB_PATH}:${WEB_PATH} \
  1342. -v /etc/localtime:/etc/localtime \
  1343. -e GIN_MODE=release \
  1344. -e "mariadb_ip=${mariadb_ip}" \
  1345. -e "mariadb_port=${mariadb_port}" \
  1346. -e "mariadb_user=${mariadb_user}" \
  1347. -e "mariadb_pas=${mariadb_pas}" \
  1348. -e "database=${database}" \
  1349. -e "account-table=${account_table}" \
  1350. -e "redis_host=${redis_host}" \
  1351. -e "redis_port=${redis_port}" \
  1352. -e "redis_pass=${redis_pass}" \
  1353. -e "crt_path=${CERT_PATH}${domain}.crt" \
  1354. -e "key_path=${CERT_PATH}${domain}.key" \
  1355. -e "grpc_port=${grpc_port}" \
  1356. -e "server_port=${trojan_panel_core_port}" \
  1357. jonssonyan/trojan-panel-core
  1358. if [[ -n $(docker ps -q -f "name=^trojan-panel-core$" -f "status=running") ]]; then
  1359. echo_content skyBlue "---> Trojan Panel Core update completed"
  1360. else
  1361. echo_content red "---> Trojan Panel Core update fails or runs abnormally, please try to repair or uninstall and reinstall"
  1362. fi
  1363. else
  1364. echo_content skyBlue "---> You have installed the latest version of the Trojan Panel Core"
  1365. fi
  1366. }
  1367. # Uninstall Caddy2
  1368. uninstall_caddy2() {
  1369. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-caddy$") ]]; then
  1370. echo_content green "---> Uninstall Caddy2"
  1371. docker rm -f trojan-panel-caddy &&
  1372. rm -rf ${CADDY_DATA}
  1373. echo_content skyBlue "---> Caddy2 uninstallation completed"
  1374. else
  1375. echo_content red "---> Please install Caddy2 first"
  1376. fi
  1377. }
  1378. # Uninstall Nginx
  1379. uninstall_nginx() {
  1380. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-nginx") ]]; then
  1381. echo_content green "---> Uninstall Nginx"
  1382. docker rm -f trojan-panel-nginx &&
  1383. rm -rf ${NGINX_DATA}
  1384. echo_content skyBlue "---> Nginx uninstallation completed"
  1385. else
  1386. echo_content red "---> Please install Nginx first"
  1387. fi
  1388. }
  1389. # Uninstall MariaDB
  1390. uninstall_mariadb() {
  1391. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-mariadb$") ]]; then
  1392. echo_content green "---> Uninstall MariaDB"
  1393. docker rm -f trojan-panel-mariadb &&
  1394. rm -rf ${MARIA_DATA}
  1395. echo_content skyBlue "---> MariaDB uninstall completed"
  1396. else
  1397. echo_content red "---> Please install MariaDB first"
  1398. fi
  1399. }
  1400. # Uninstall Redis
  1401. uninstall_redis() {
  1402. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-redis$") ]]; then
  1403. echo_content green "---> Uninstall Redis"
  1404. docker rm -f trojan-panel-redis &&
  1405. rm -rf ${REDIS_DATA}
  1406. echo_content skyBlue "---> Redis uninstall completed"
  1407. else
  1408. echo_content red "---> Please install Redis first"
  1409. fi
  1410. }
  1411. # Uninstall Trojan Panel Frontend
  1412. uninstall_trojan_panel_ui() {
  1413. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-ui$") ]]; then
  1414. echo_content green "---> Uninstall Trojan Panel Frontend"
  1415. docker rm -f trojan-panel-ui &&
  1416. docker rmi -f jonssonyan/trojan-panel-ui &&
  1417. rm -rf ${TROJAN_PANEL_UI_DATA}
  1418. echo_content skyBlue "---> Trojan Panel Frontend uninstallation completed"
  1419. else
  1420. echo_content red "---> Please install the Trojan Panel Frontend first"
  1421. fi
  1422. }
  1423. # Uninstall Trojan Panel Backend
  1424. uninstall_trojan_panel() {
  1425. if [[ -n $(docker ps -a -q -f "name=^trojan-panel$") ]]; then
  1426. echo_content green "---> Uninstall Trojan Panel Backend"
  1427. docker rm -f trojan-panel &&
  1428. docker rmi -f jonssonyan/trojan-panel &&
  1429. rm -rf ${TROJAN_PANEL_DATA}
  1430. echo_content skyBlue "---> Trojan Panel Backend uninstallation completed"
  1431. else
  1432. echo_content red "---> Please install the Trojan Panel Backend first"
  1433. fi
  1434. }
  1435. # Uninstall Trojan Panel Core
  1436. uninstall_trojan_panel_core() {
  1437. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-core$") ]]; then
  1438. echo_content green "---> Uninstall Trojan Panel Core"
  1439. docker rm -f trojan-panel-core &&
  1440. docker rmi -f jonssonyan/trojan-panel-core &&
  1441. rm -rf ${TROJAN_PANEL_CORE_DATA}
  1442. echo_content skyBlue "---> Trojan Panel Core uninstallation completed"
  1443. else
  1444. echo_content red "---> Please install the Trojan Panel Core first"
  1445. fi
  1446. }
  1447. # Uninstall all Trojan Panel related containers
  1448. uninstall_all() {
  1449. echo_content green "---> Uninstall all Trojan Panel related containers"
  1450. docker rm -f $(docker ps -a -q -f "name=^trojan-panel")
  1451. docker rmi -f $(docker images | grep "^jonssonyan/trojan-panel" | awk '{print $3}')
  1452. rm -rf ${TP_DATA}
  1453. echo_content skyBlue "---> Uninstall all Trojan Panel related containers completed"
  1454. }
  1455. # Modify Trojan Panel Frontend port
  1456. update_trojan_panel_ui_port() {
  1457. if [[ -n $(docker ps -q -f "name=^trojan-panel-ui$" -f "status=running") ]]; then
  1458. echo_content green "---> Modify Trojan Panel Frontend port"
  1459. trojan_panel_ui_port=$(grep 'listen.*ssl' ${UI_NGINX_CONFIG} | awk '{print $2}')
  1460. if [[ -z "${trojan_panel_ui_port}" ]]; then
  1461. ui_https=0
  1462. trojan_panel_ui_port=$(grep -oP 'listen\s+\K\d+' ${UI_NGINX_CONFIG} | awk 'NR==1')
  1463. fi
  1464. if [[ -z "${trojan_panel_ui_port}" ]]; then
  1465. echo_content red "---> Trojan Panel Frontend port not queried"
  1466. exit 0
  1467. fi
  1468. echo_content yellow "Tip: The current port of the Trojan Panel Frontend (trojan-panel-ui) is ${trojan_panel_ui_port}"
  1469. read -r -p "Please enter the new port of the Trojan Panel Frontend (default: 8888): " trojan_panel_ui_port
  1470. [[ -z "${trojan_panel_ui_port}" ]] && trojan_panel_ui_port="8888"
  1471. if [[ ${ui_https} == 0 ]]; then
  1472. # http
  1473. sed -i "s/listen.*;/listen ${trojan_panel_ui_port};/g" ${UI_NGINX_CONFIG} &&
  1474. sed -i "s/http:\/\/\$host:.*\$request_uri;/http:\/\/\$host:${trojan_panel_ui_port}\$request_uri;/g" ${UI_NGINX_CONFIG} &&
  1475. docker restart trojan-panel-ui
  1476. else
  1477. # https
  1478. sed -i "s/listen.*ssl;/listen ${trojan_panel_ui_port} ssl;/g" ${UI_NGINX_CONFIG} &&
  1479. sed -i "s/https:\/\/\$host:.*\$request_uri;/https:\/\/\$host:${trojan_panel_ui_port}\$request_uri;/g" ${UI_NGINX_CONFIG} &&
  1480. docker restart trojan-panel-ui
  1481. fi
  1482. if [[ "$?" == "0" ]]; then
  1483. echo_content skyBlue "---> Trojan Panel Frontend port modification completed"
  1484. else
  1485. echo_content red "---> Trojan Panel Frontend port modification failed"
  1486. fi
  1487. else
  1488. echo_content red "---> The Trojan Panel Frontend is not installed or is running abnormally, please repair or uninstall and reinstall and try again"
  1489. fi
  1490. }
  1491. # Refresh Redis cache
  1492. redis_flush_all() {
  1493. if [[ -z $(docker ps -a -q -f "name=^trojan-panel-redis$") ]]; then
  1494. echo_content red "---> Please install Redis first"
  1495. exit 0
  1496. fi
  1497. if [[ -z $(docker ps -q -f "name=^trojan-panel-redis$" -f "status=running") ]]; then
  1498. echo_content red "---> Redis is running abnormally"
  1499. exit 0
  1500. fi
  1501. echo_content green "---> Refresh Redis cache"
  1502. read -r -p "Please enter the IP address of Redis (default: local host): " redis_host
  1503. [[ -z "${redis_host}" ]] && redis_host="127.0.0.1"
  1504. read -r -p "Please enter the port of Redis (default: 6378): " redis_port
  1505. [[ -z "${redis_port}" ]] && redis_port=6378
  1506. while read -r -p "Please enter the Redis password (required): " redis_pass; do
  1507. if [[ -z "${redis_pass}" ]]; then
  1508. echo_content red "password can not be empty"
  1509. else
  1510. break
  1511. fi
  1512. done
  1513. docker exec trojan-panel-redis redis-cli -h "${redis_host}" -p "${redis_port}" -a "${redis_pass}" -e "flushall" &>/dev/null
  1514. echo_content skyBlue "---> Redis cache refresh completed"
  1515. }
  1516. # Replace certificate
  1517. change_cert() {
  1518. domain_1=$(cat "${DOMAIN_FILE}")
  1519. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-caddy$") ]]; then
  1520. docker rm -f trojan-panel-caddy &&
  1521. rm -rf ${CADDY_LOG}* &&
  1522. echo "" >${CADDY_CONFIG} &&
  1523. rm -rf ${WEB_PATH}*
  1524. fi
  1525. rm -rf ${CERT_PATH}* &&
  1526. echo "" >${DOMAIN_FILE}
  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 database 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 the database (default: local host): " mariadb_ip
  1579. [[ -z "${mariadb_ip}" ]] && mariadb_ip="127.0.0.1"
  1580. read -r -p "Please enter the port of the database (default: 9507): " mariadb_port
  1581. [[ -z "${mariadb_port}" ]] && mariadb_port=9507
  1582. read -r -p "Please enter the username of the database (default: root): " mariadb_user
  1583. [[ -z "${mariadb_user}" ]] && mariadb_user="root"
  1584. while read -r -p "Please enter the database password (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 Please log in to the management panel to change the password in time"
  1595. echo_content red "\n=============================================================="
  1596. else
  1597. echo_content red "Admin panel sysadmin username and password reset failed"
  1598. fi
  1599. else
  1600. echo_content red "---> Please install the database first"
  1601. fi
  1602. ;;
  1603. 4)
  1604. break
  1605. ;;
  1606. *)
  1607. echo_content red "No such option"
  1608. continue
  1609. ;;
  1610. esac
  1611. done
  1612. }
  1613. # Fault detection
  1614. failure_testing() {
  1615. echo_content green "---> Start troubleshooting"
  1616. if [[ ! $(docker -v 2>/dev/null) ]]; then
  1617. echo_content red "---> Docker is running abnormally"
  1618. else
  1619. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-caddy$") ]]; then
  1620. if [[ -z $(docker ps -q -f "name=^trojan-panel-caddy$" -f "status=running") ]]; then
  1621. echo_content red "---> Caddy2 is running abnormally and the running log is as follows:"
  1622. docker logs trojan-panel-caddy
  1623. fi
  1624. domain=$(cat "${DOMAIN_FILE}")
  1625. if [[ -n ${domain} && ! -f "${CERT_PATH}${domain}.crt" ]]; then
  1626. 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"
  1627. if [[ -f ${CADDY_LOG}error.log ]]; then
  1628. echo_content red "Caddy2 error log is as follows:"
  1629. tail -n 20 ${CADDY_LOG}error.log | grep error
  1630. fi
  1631. fi
  1632. fi
  1633. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-mariadb$") && -z $(docker ps -q -f "name=^trojan-panel-mariadb$" -f "status=running") ]]; then
  1634. echo_content red "---> The database is running abnormally and the running log is as follows:"
  1635. docker logs trojan-panel-mariadb
  1636. fi
  1637. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-redis$") && -z $(docker ps -q -f "name=^trojan-panel-redis$" -f "status=running") ]]; then
  1638. echo_content red "---> The Redis is running abnormally and the running log is as follows:"
  1639. docker logs trojan-panel-redis
  1640. fi
  1641. if [[ -n $(docker ps -a -q -f "name=^trojan-panel$") && -z $(docker ps -q -f "name=^trojan-panel$" -f "status=running") ]]; then
  1642. echo_content red "---> The Trojan Panel Backend is running abnormally and the running log is as follows:"
  1643. if [[ -f ${TROJAN_PANEL_LOGS}trojan-panel.log ]]; then
  1644. tail -n 20 ${TROJAN_PANEL_LOGS}trojan-panel.log | grep error
  1645. else
  1646. docker logs trojan-panel
  1647. fi
  1648. fi
  1649. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-ui$") && -z $(docker ps -q -f "name=^trojan-panel-ui$" -f "status=running") ]]; then
  1650. echo_content red "---> The Trojan Panel Frontend is running abnormally and the running log is as follows:"
  1651. docker logs trojan-panel-ui
  1652. fi
  1653. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-core$") && -z $(docker ps -q -f "name=^trojan-panel-core$" -f "status=running") ]]; then
  1654. echo_content red "---> The Trojan Panel Core is running abnormally and the running log is as follows:"
  1655. if [[ -f ${TROJAN_PANEL_CORE_LOGS}trojan-panel.log ]]; then
  1656. tail -n 20 ${TROJAN_PANEL_CORE_LOGS}trojan-panel.log | grep error
  1657. else
  1658. docker logs trojan-panel-core
  1659. fi
  1660. fi
  1661. fi
  1662. echo_content green "---> Troubleshooting ended"
  1663. }
  1664. log_query() {
  1665. while :; do
  1666. echo_content skyBlue "Applications that can query logs are as follows:"
  1667. echo_content yellow "1. Trojan Panel Backend"
  1668. echo_content yellow "2. Trojan Panel Frontend"
  1669. echo_content yellow "3. Quit"
  1670. read -r -p "Please select an application (default: 1): " select_log_query_type
  1671. [[ -z "${select_log_query_type}" ]] && select_log_query_type=1
  1672. case ${select_log_query_type} in
  1673. 1)
  1674. log_file_path=${TROJAN_PANEL_LOGS}trojan-panel.log
  1675. ;;
  1676. 2)
  1677. log_file_path=${TROJAN_PANEL_CORE_LOGS}trojan-panel-core.log
  1678. ;;
  1679. 3)
  1680. break
  1681. ;;
  1682. *)
  1683. echo_content red "No such option"
  1684. continue
  1685. ;;
  1686. esac
  1687. read -r -p "Please enter the number of rows to query (default: 20): " select_log_query_line_type
  1688. [[ -z "${select_log_query_line_type}" ]] && select_log_query_line_type=20
  1689. if [[ -f ${log_file_path} ]]; then
  1690. echo_content skyBlue "The log is as follows:"
  1691. tail -n ${select_log_query_line_type} ${log_file_path}
  1692. else
  1693. echo_content red "No log file exists"
  1694. fi
  1695. done
  1696. }
  1697. version_query() {
  1698. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-ui$") && -n $(docker ps -q -f "name=^trojan-panel-ui$" -f "status=running") ]]; then
  1699. trojan_panel_ui_current_version=$(docker exec trojan-panel-ui cat ${TROJAN_PANEL_UI_DATA}version)
  1700. 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}"
  1701. fi
  1702. if [[ -n $(docker ps -a -q -f "name=^trojan-panel$") && -n $(docker ps -q -f "name=^trojan-panel$" -f "status=running") ]]; then
  1703. trojan_panel_current_version=$(docker exec trojan-panel ./trojan-panel -version)
  1704. 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}"
  1705. fi
  1706. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-core$") && -n $(docker ps -q -f "name=^trojan-panel-core$" -f "status=running") ]]; then
  1707. trojan_panel_core_current_version=$(docker exec trojan-panel-core ./trojan-panel-core -version)
  1708. 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}"
  1709. fi
  1710. }
  1711. main() {
  1712. cd "$HOME" || exit 0
  1713. init_var
  1714. mkdir_tools
  1715. check_sys
  1716. depend_install
  1717. clear
  1718. echo_content red "\n=============================================================="
  1719. echo_content skyBlue "System Required: CentOS 7+/Ubuntu 18+/Debian 10+"
  1720. echo_content skyBlue "Version: v2.2.0"
  1721. echo_content skyBlue "Description: One click Install Trojan Panel server"
  1722. echo_content skyBlue "Author: jonssonyan <https://jonssonyan.com>"
  1723. echo_content skyBlue "Github: https://github.com/trojanpanel"
  1724. echo_content skyBlue "Docs: https://trojanpanel.github.io"
  1725. echo_content red "\n=============================================================="
  1726. echo_content yellow "1. Install Trojan Panel Frontend"
  1727. echo_content yellow "2. Install Trojan Panel Backend"
  1728. echo_content yellow "3. Install Trojan Panel Core"
  1729. echo_content yellow "4. Install Caddy2+https"
  1730. echo_content yellow "5. Install Nginx"
  1731. echo_content yellow "6. Install MariaDB"
  1732. echo_content yellow "7. Install Redis"
  1733. echo_content green "\n=============================================================="
  1734. echo_content yellow "8. Update Trojan Panel Frontend"
  1735. echo_content yellow "9. Update Trojan Panel Backend"
  1736. echo_content yellow "10. Update Trojan Panel Core"
  1737. echo_content green "\n=============================================================="
  1738. echo_content yellow "11. Uninstall Trojan Panel Frontend"
  1739. echo_content yellow "12. Uninstall Trojan Panel Backend"
  1740. echo_content yellow "13. Uninstall Trojan Panel Core"
  1741. echo_content yellow "14. Uninstall Caddy2+https"
  1742. echo_content yellow "15. Uninstall Nginx"
  1743. echo_content yellow "16. Uninstall MariaDB"
  1744. echo_content yellow "17. Uninstall Redis"
  1745. echo_content yellow "18. Uninstall all Trojan Panel related containers"
  1746. echo_content green "\n=============================================================="
  1747. echo_content yellow "19. Modify Trojan Panel Frontend port"
  1748. echo_content yellow "20. Refresh Redis cache"
  1749. echo_content yellow "21. Replace certificate"
  1750. echo_content yellow "22. Forgot sysadmin password"
  1751. echo_content green "\n=============================================================="
  1752. echo_content yellow "23. Fault detection"
  1753. echo_content yellow "24. Log query"
  1754. echo_content yellow "25. Version query"
  1755. read -r -p "Please choose:" selectInstall_type
  1756. case ${selectInstall_type} in
  1757. 1)
  1758. install_docker
  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