install_script.sh 78 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064
  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 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 MariaDB 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 MariaDB 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_reverse_proxy
  1760. install_cert
  1761. install_trojan_panel_ui
  1762. ;;
  1763. 2)
  1764. install_docker
  1765. install_mariadb
  1766. install_redis
  1767. install_trojan_panel
  1768. ;;
  1769. 3)
  1770. install_docker
  1771. install_reverse_proxy
  1772. install_cert
  1773. install_trojan_panel_core
  1774. ;;
  1775. 4)
  1776. install_docker
  1777. install_caddy2
  1778. ;;
  1779. 5)
  1780. install_docker
  1781. install_nginx
  1782. ;;
  1783. 6)
  1784. install_docker
  1785. install_mariadb
  1786. ;;
  1787. 7)
  1788. install_docker
  1789. install_redis
  1790. ;;
  1791. 8)
  1792. update_trojan_panel_ui
  1793. ;;
  1794. 9)
  1795. update_trojan_panel
  1796. ;;
  1797. 10)
  1798. update_trojan_panel_core
  1799. ;;
  1800. 11)
  1801. uninstall_trojan_panel_ui
  1802. ;;
  1803. 12)
  1804. uninstall_trojan_panel
  1805. ;;
  1806. 13)
  1807. uninstall_trojan_panel_core
  1808. ;;
  1809. 14)
  1810. uninstall_caddy2
  1811. ;;
  1812. 15)
  1813. uninstall_nginx
  1814. ;;
  1815. 16)
  1816. uninstall_mariadb
  1817. ;;
  1818. 17)
  1819. uninstall_redis
  1820. ;;
  1821. 18)
  1822. uninstall_all
  1823. ;;
  1824. 19)
  1825. update_trojan_panel_ui_port
  1826. ;;
  1827. 20)
  1828. redis_flush_all
  1829. ;;
  1830. 21)
  1831. change_cert
  1832. ;;
  1833. 22)
  1834. forget_pass
  1835. ;;
  1836. 23)
  1837. failure_testing
  1838. ;;
  1839. 24)
  1840. log_query
  1841. ;;
  1842. 25)
  1843. version_query
  1844. ;;
  1845. *)
  1846. echo_content red "No such option"
  1847. ;;
  1848. esac
  1849. }
  1850. main