install_script.sh 78 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067
  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. domain=$1
  321. cat >${CADDY_CONFIG} <<EOF
  322. {
  323. "admin":{
  324. "disabled":true
  325. },
  326. "logging":{
  327. "logs":{
  328. "default":{
  329. "writer":{
  330. "output":"file",
  331. "filename":"${CADDY_LOG}error.log"
  332. },
  333. "level":"ERROR"
  334. }
  335. }
  336. },
  337. "storage":{
  338. "module":"file_system",
  339. "root":"${CERT_PATH}"
  340. },
  341. "apps":{
  342. "http":{
  343. "http_port": ${caddy_port},
  344. "servers":{
  345. "srv0":{
  346. "listen":[
  347. ":${caddy_port}"
  348. ],
  349. "routes":[
  350. {
  351. "match":[
  352. {
  353. "host":[
  354. "${domain}"
  355. ]
  356. }
  357. ],
  358. "handle":[
  359. {
  360. "handler":"static_response",
  361. "headers":{
  362. "Location":[
  363. "https://{http.request.host}:${caddy_remote_port}{http.request.uri}"
  364. ]
  365. },
  366. "status_code":301
  367. }
  368. ]
  369. }
  370. ]
  371. },
  372. "srv1":{
  373. "listen":[
  374. ":${caddy_remote_port}"
  375. ],
  376. "routes":[
  377. {
  378. "handle":[
  379. {
  380. "handler":"subroute",
  381. "routes":[
  382. {
  383. "match":[
  384. {
  385. "host":[
  386. "${domain}"
  387. ]
  388. }
  389. ],
  390. "handle":[
  391. {
  392. "handler":"file_server",
  393. "root":"${WEB_PATH}",
  394. "index_names":[
  395. "index.html",
  396. "index.htm"
  397. ]
  398. }
  399. ],
  400. "terminal":true
  401. }
  402. ]
  403. }
  404. ]
  405. }
  406. ],
  407. "tls_connection_policies":[
  408. {
  409. "match":{
  410. "sni":[
  411. "${domain}"
  412. ]
  413. }
  414. }
  415. ],
  416. "automatic_https":{
  417. "disable":true
  418. }
  419. }
  420. }
  421. },
  422. "tls":{
  423. "certificates":{
  424. "automate":[
  425. "${domain}"
  426. ],
  427. "load_files":[
  428. {
  429. "certificate":"${CADDY_CERT_DIR}${domain}/${domain}.crt",
  430. "key":"${CADDY_CERT_DIR}${domain}/${domain}.key"
  431. }
  432. ]
  433. },
  434. "automation":{
  435. "policies":[
  436. {
  437. "issuers":[
  438. {
  439. "module":"${ssl_module}",
  440. "email":"${your_email}"
  441. }
  442. ]
  443. }
  444. ]
  445. }
  446. }
  447. }
  448. }
  449. EOF
  450. }
  451. # Caddy2 https automatic application and renewal certificate configuration file
  452. caddy2_https_auto_config() {
  453. domain=$1
  454. cat >${CADDY_CONFIG} <<EOF
  455. {
  456. "admin":{
  457. "disabled":true
  458. },
  459. "logging":{
  460. "logs":{
  461. "default":{
  462. "writer":{
  463. "output":"file",
  464. "filename":"${CADDY_LOG}error.log"
  465. },
  466. "level":"ERROR"
  467. }
  468. }
  469. },
  470. "storage":{
  471. "module":"file_system",
  472. "root":"${CERT_PATH}"
  473. },
  474. "apps":{
  475. "http":{
  476. "http_port": ${caddy_port},
  477. "servers":{
  478. "srv0":{
  479. "listen":[
  480. ":${caddy_port}"
  481. ],
  482. "routes":[
  483. {
  484. "match":[
  485. {
  486. "host":[
  487. "${domain}"
  488. ]
  489. }
  490. ],
  491. "handle":[
  492. {
  493. "handler":"static_response",
  494. "headers":{
  495. "Location":[
  496. "https://{http.request.host}:${caddy_remote_port}{http.request.uri}"
  497. ]
  498. },
  499. "status_code":301
  500. }
  501. ]
  502. }
  503. ]
  504. },
  505. "srv1":{
  506. "listen":[
  507. ":${caddy_remote_port}"
  508. ],
  509. "routes":[
  510. {
  511. "handle":[
  512. {
  513. "handler":"subroute",
  514. "routes":[
  515. {
  516. "match":[
  517. {
  518. "host":[
  519. "${domain}"
  520. ]
  521. }
  522. ],
  523. "handle":[
  524. {
  525. "handler":"file_server",
  526. "root":"${WEB_PATH}",
  527. "index_names":[
  528. "index.html",
  529. "index.htm"
  530. ]
  531. }
  532. ],
  533. "terminal":true
  534. }
  535. ]
  536. }
  537. ]
  538. }
  539. ],
  540. "tls_connection_policies":[
  541. {
  542. "match":{
  543. "sni":[
  544. "${domain}"
  545. ]
  546. }
  547. }
  548. ],
  549. "automatic_https":{
  550. "disable":true
  551. }
  552. }
  553. }
  554. },
  555. "tls":{
  556. "certificates":{
  557. "automate":[
  558. "${domain}"
  559. ]
  560. },
  561. "automation":{
  562. "policies":[
  563. {
  564. "issuers":[
  565. {
  566. "module":"${ssl_module}",
  567. "email":"${your_email}"
  568. }
  569. ]
  570. }
  571. ]
  572. }
  573. }
  574. }
  575. }
  576. EOF
  577. }
  578. # Install Caddy2
  579. install_caddy2() {
  580. if [[ -z $(docker ps -a -q -f "name=^trojan-panel-caddy$") ]]; then
  581. echo_content green "---> Install Caddy2+https"
  582. wget --no-check-certificate -O ${WEB_PATH}html.tar.gz -N ${STATIC_HTML} &&
  583. tar -zxvf ${WEB_PATH}html.tar.gz -k -C ${WEB_PATH}
  584. read -r -p "Please enter the port of Caddy2 (default: 80): " caddy_port
  585. [[ -z "${caddy_port}" ]] && caddy_port=80
  586. read -r -p "Please enter the forwarding port of Caddy2 (default: 8863): " caddy_remote_port
  587. [[ -z "${caddy_remote_port}" ]] && caddy_remote_port=8863
  588. echo_content yellow "Tip: Please confirm that the domain name has been resolved to this machine, otherwise the installation may fail"
  589. while read -r -p "Please enter your domain name (required): " domain; do
  590. if [[ -z "${domain}" ]]; then
  591. echo_content red "Domain name cannot be empty"
  592. else
  593. break
  594. fi
  595. done
  596. read -r -p "Please enter your email (optional): " your_email
  597. 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
  598. if [[ -z ${ssl_option} || ${ssl_option} == 1 ]]; then
  599. while read -r -p "Please choose the way to apply for the certificate (1/acme 2/zerossl default: 1: " ssl_module_type; do
  600. if [[ -z "${ssl_module_type}" || ${ssl_module_type} == 1 ]]; then
  601. ssl_module="acme"
  602. CADDY_CERT_DIR="${CERT_PATH}certificates/acme-v02.api.letsencrypt.org-directory/"
  603. break
  604. elif [[ ${ssl_module_type} == 2 ]]; then
  605. ssl_module="zerossl"
  606. CADDY_CERT_DIR="${CERT_PATH}certificates/acme.zerossl.com-v2-dv90/"
  607. break
  608. else
  609. echo_content red "Cannot enter other characters except 1 and 2"
  610. fi
  611. done
  612. caddy2_https_auto_config "${domain}"
  613. break
  614. elif [[ ${ssl_option} == 2 ]]; then
  615. install_custom_cert "${domain}"
  616. caddy2_https_config "${domain}"
  617. break
  618. else
  619. echo_content red "Cannot enter other characters except 1 and 2"
  620. fi
  621. done
  622. # Caddy2 temporary listening port for automatic certificate application
  623. if [[ -n $(lsof -i:${caddy_port},${caddy_remote_port} -t) ]]; then
  624. kill -9 "$(lsof -i:${caddy_port},${caddy_remote_port} -t)"
  625. fi
  626. docker pull caddy:2.6.2 &&
  627. docker run -d --name trojan-panel-caddy --restart always \
  628. --network=host \
  629. -v "${CADDY_CONFIG}":"${CADDY_CONFIG}" \
  630. -v ${CERT_PATH}:"${CADDY_CERT_DIR}${domain}/" \
  631. -v ${WEB_PATH}:${WEB_PATH} \
  632. -v ${CADDY_LOG}:${CADDY_LOG} \
  633. caddy:2.6.2 caddy run --config ${CADDY_CONFIG}
  634. cat >${DOMAIN_FILE} <<EOF
  635. ${domain}
  636. EOF
  637. if [[ -n $(docker ps -q -f "name=^trojan-panel-caddy$" -f "status=running") ]]; then
  638. echo_content red "\n=============================================================="
  639. echo_content skyBlue "---> Caddy2+https installation completed"
  640. echo_content yellow "Certificate Directory: ${CERT_PATH}"
  641. echo_content red "\n=============================================================="
  642. else
  643. echo_content red "---> Caddy2+https installation fails or runs abnormally, please try to repair or uninstall and reinstall"
  644. exit 0
  645. fi
  646. else
  647. echo_content skyBlue "---> You have installed Caddy2+https"
  648. fi
  649. }
  650. # Nginx http configuration file
  651. nginx_http_config() {
  652. cat >${NGINX_CONFIG} <<-EOF
  653. server {
  654. listen ${nginx_port};
  655. server_name localhost;
  656. location / {
  657. root ${WEB_PATH};
  658. index index.html index.htm;
  659. }
  660. error_page 497 http://\$host:${nginx_port}\$request_uri;
  661. error_page 500 502 503 504 /50x.html;
  662. location = /50x.html {
  663. root /usr/share/nginx/html;
  664. }
  665. }
  666. EOF
  667. }
  668. # Nginx https configuration file
  669. nginx_https_config() {
  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. domain=$(cat "${DOMAIN_FILE}")
  722. nginx_https_config
  723. break
  724. elif [[ ${nginx_https} == 0 ]]; then
  725. nginx_http_config
  726. break
  727. else
  728. echo_content red "Cannot enter other characters except 1 and 2"
  729. fi
  730. done
  731. docker pull nginx:1.20-alpine &&
  732. docker run -d --name trojan-panel-nginx --restart always \
  733. --network=host \
  734. -v "${NGINX_CONFIG}":"/etc/nginx/conf.d/default.conf" \
  735. -v ${CERT_PATH}:${CERT_PATH} \
  736. -v ${WEB_PATH}:${WEB_PATH} \
  737. nginx:1.20-alpine
  738. if [[ -n $(docker ps -q -f "name=^trojan-panel-nginx$" -f "status=running") ]]; then
  739. echo_content skyBlue "---> Nginx installation completed"
  740. else
  741. echo_content red "---> Nginx installation fails or runs abnormally, please try to repair or uninstall and reinstall"
  742. exit 0
  743. fi
  744. else
  745. echo_content skyBlue "---> You have installed Nginx"
  746. fi
  747. }
  748. # Install a web server
  749. install_reverse_proxy() {
  750. if [[ -z $(docker ps -a -q -f "name=^trojan-panel-caddy$|^trojan-panel-nginx$") ]]; then
  751. echo_content green "---> Install a web server"
  752. while :; do
  753. echo_content yellow "1. Install Caddy2+https (recommend)"
  754. echo_content yellow "2. Install Nginx"
  755. echo_content yellow "3. Not install"
  756. read -r -p "Please select (default: 1): " whether_install_reverse_proxy
  757. [[ -z "${whether_install_reverse_proxy}" ]] && whether_install_reverse_proxy=1
  758. case ${whether_install_reverse_proxy} in
  759. 1)
  760. install_caddy2
  761. break
  762. ;;
  763. 2)
  764. install_nginx
  765. break
  766. ;;
  767. 3)
  768. break
  769. ;;
  770. *)
  771. echo_content red "No such option"
  772. continue
  773. ;;
  774. esac
  775. done
  776. echo_content skyBlue "---> Web server installation completed"
  777. fi
  778. }
  779. # Set certificate
  780. install_cert() {
  781. domain=$(cat "${DOMAIN_FILE}")
  782. if [[ -z "${domain}" ]]; then
  783. echo_content green "---> Set certificate"
  784. while :; do
  785. echo_content yellow "1. Custom certificate"
  786. echo_content yellow "2. Not set"
  787. read -r -p "Please select (default: 1): " whether_install_cert
  788. [[ -z "${whether_install_cert}" ]] && whether_install_cert=1
  789. case ${whether_install_cert} in
  790. 1)
  791. install_custom_cert "custom_cert"
  792. break
  793. ;;
  794. 2)
  795. break
  796. ;;
  797. *)
  798. echo_content red "No such option"
  799. continue
  800. ;;
  801. esac
  802. done
  803. echo_content green "---> Certificate setup completed"
  804. fi
  805. }
  806. # Install MariaDB
  807. install_mariadb() {
  808. if [[ -z $(docker ps -a -q -f "name=^trojan-panel-mariadb$") ]]; then
  809. echo_content green "---> Install MariaDB"
  810. read -r -p "Please enter the port of MariaDB (default: 9507): " mariadb_port
  811. [[ -z "${mariadb_port}" ]] && mariadb_port=9507
  812. read -r -p "Please enter the username of MariaDB (default: root): " mariadb_user
  813. [[ -z "${mariadb_user}" ]] && mariadb_user="root"
  814. while read -r -p "Please enter the password of MariaDB (required): " mariadb_pas; do
  815. if [[ -z "${mariadb_pas}" ]]; then
  816. echo_content red "Password can not be empty"
  817. else
  818. break
  819. fi
  820. done
  821. if [[ "${mariadb_user}" == "root" ]]; then
  822. docker pull mariadb:10.7.3 &&
  823. docker run -d --name trojan-panel-mariadb --restart always \
  824. --network=host \
  825. -e MYSQL_DATABASE="trojan_panel_db" \
  826. -e MYSQL_ROOT_PASSWORD="${mariadb_pas}" \
  827. -e TZ=Asia/Shanghai \
  828. mariadb:10.7.3 \
  829. --port ${mariadb_port} \
  830. --character-set-server=utf8mb4 \
  831. --collation-server=utf8mb4_unicode_ci
  832. else
  833. docker pull mariadb:10.7.3 &&
  834. docker run -d --name trojan-panel-mariadb --restart always \
  835. --network=host \
  836. -e MYSQL_DATABASE="trojan_panel_db" \
  837. -e MYSQL_ROOT_PASSWORD="${mariadb_pas}" \
  838. -e MYSQL_USER="${mariadb_user}" \
  839. -e MYSQL_PASSWORD="${mariadb_pas}" \
  840. -e TZ=Asia/Shanghai \
  841. mariadb:10.7.3 \
  842. --port ${mariadb_port} \
  843. --character-set-server=utf8mb4 \
  844. --collation-server=utf8mb4_unicode_ci
  845. fi
  846. if [[ -n $(docker ps -q -f "name=^trojan-panel-mariadb$" -f "status=running") ]]; then
  847. echo_content skyBlue "---> MariaDB installation completed"
  848. echo_content yellow "---> The MariaDB password of root (please keep it safe): ${mariadb_pas}"
  849. if [[ "${mariadb_user}" != "root" ]]; then
  850. echo_content yellow "---> The MariaDB password of ${mariadb_user} (please keep it safe): ${mariadb_pas}"
  851. fi
  852. else
  853. echo_content red "---> MariaDB installation fails or runs abnormally, please try to repair or uninstall and reinstall"
  854. exit 0
  855. fi
  856. else
  857. echo_content skyBlue "---> You have installed MariaDB"
  858. fi
  859. }
  860. # Install Redis
  861. install_redis() {
  862. if [[ -z $(docker ps -a -q -f "name=^trojan-panel-redis$") ]]; then
  863. echo_content green "---> Install Redis"
  864. read -r -p "Please enter the port of Redis (default: 6378): " redis_port
  865. [[ -z "${redis_port}" ]] && redis_port=6378
  866. while read -r -p "Please enter the Redis password (required): " redis_pass; do
  867. if [[ -z "${redis_pass}" ]]; then
  868. echo_content red "Password can not be empty"
  869. else
  870. break
  871. fi
  872. done
  873. docker pull redis:6.2.7 &&
  874. docker run -d --name trojan-panel-redis --restart always \
  875. --network=host \
  876. redis:6.2.7 \
  877. redis-server --requirepass "${redis_pass}" --port "${redis_port}"
  878. if [[ -n $(docker ps -q -f "name=^trojan-panel-redis$" -f "status=running") ]]; then
  879. echo_content skyBlue "---> Redis installation completed"
  880. echo_content yellow "---> Redis password (please keep it safe): ${redis_pass}"
  881. else
  882. echo_content red "---> Redis installation fails or runs abnormally, please try to repair or uninstall and reinstall"
  883. exit 0
  884. fi
  885. else
  886. echo_content skyBlue "---> You have installed Redis"
  887. fi
  888. }
  889. # Trojan Panel Frontend Nginx http configuration file
  890. ui_http_config() {
  891. cat >${UI_NGINX_CONFIG} <<-EOF
  892. server {
  893. listen ${trojan_panel_ui_port};
  894. server_name localhost;
  895. location / {
  896. root ${TROJAN_PANEL_UI_DATA};
  897. index index.html index.htm;
  898. }
  899. location /api {
  900. proxy_pass http://${trojan_panel_ip}:${trojan_panel_server_port};
  901. }
  902. error_page 497 http://\$host:${trojan_panel_ui_port}\$request_uri;
  903. error_page 500 502 503 504 /50x.html;
  904. location = /50x.html {
  905. root /usr/share/nginx/html;
  906. }
  907. }
  908. EOF
  909. }
  910. # Trojan Panel Frontend Nginx https configuration file
  911. ui_https_config() {
  912. cat >${UI_NGINX_CONFIG} <<-EOF
  913. server {
  914. listen ${trojan_panel_ui_port} ssl;
  915. server_name localhost;
  916. # force ssl
  917. ssl on;
  918. ssl_certificate ${CERT_PATH}${domain}.crt;
  919. ssl_certificate_key ${CERT_PATH}${domain}.key;
  920. # cache validity period
  921. ssl_session_timeout 5m;
  922. # secure link optional encryption protocol
  923. ssl_protocols TLSv1.3;
  924. # encryption algorithm
  925. ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
  926. # use server-side preferred algorithm
  927. ssl_prefer_server_ciphers on;
  928. #access_log /var/log/nginx/host.access.log main;
  929. location / {
  930. root ${TROJAN_PANEL_UI_DATA};
  931. index index.html index.htm;
  932. }
  933. location /api {
  934. proxy_pass http://${trojan_panel_ip}:${trojan_panel_server_port};
  935. }
  936. #error_page 404 /404.html;
  937. #497 http->https
  938. error_page 497 https://\$host:${trojan_panel_ui_port}\$request_uri;
  939. # redirect server error pages to the static page /50x.html
  940. #
  941. error_page 500 502 503 504 /50x.html;
  942. location = /50x.html {
  943. root /usr/share/nginx/html;
  944. }
  945. }
  946. EOF
  947. }
  948. # Install Trojan Panel Frontend
  949. install_trojan_panel_ui() {
  950. if [[ -z $(docker ps -a -q -f "name=^trojan-panel-ui$") ]]; then
  951. echo_content green "---> Install Trojan Panel Frontend"
  952. read -r -p "Please enter the IP address of the Trojan Panel Backend (default: local host): " trojan_panel_ip
  953. [[ -z "${trojan_panel_ip}" ]] && trojan_panel_ip="127.0.0.1"
  954. read -r -p "Please enter the service port of the Trojan Panel Backend (default: 8081): " trojan_panel_server_port
  955. [[ -z "${trojan_panel_server_port}" ]] && trojan_panel_server_port=8081
  956. read -r -p "Please enter the port of the Trojan Panel Frontend (default: 8888): " trojan_panel_ui_port
  957. [[ -z "${trojan_panel_ui_port}" ]] && trojan_panel_ui_port="8888"
  958. while read -r -p "Please choose whether to enable https on the Trojan Panel Frontend? (0/off 1/on default: 1): " ui_https; do
  959. if [[ -z ${ui_https} || ${ui_https} == 1 ]]; then
  960. install_custom_cert "custom_cert"
  961. domain=$(cat "${DOMAIN_FILE}")
  962. ui_https_config
  963. break
  964. elif [[ ${ui_https} == 0 ]]; then
  965. ui_http_config
  966. break
  967. else
  968. echo_content red "Cannot enter other characters except 1 and 2"
  969. fi
  970. done
  971. docker pull jonssonyan/trojan-panel-ui &&
  972. docker run -d --name trojan-panel-ui --restart always \
  973. --network=host \
  974. -v "${UI_NGINX_CONFIG}":"/etc/nginx/conf.d/default.conf" \
  975. -v ${CERT_PATH}:${CERT_PATH} \
  976. jonssonyan/trojan-panel-ui
  977. if [[ -n $(docker ps -q -f "name=^trojan-panel-ui$" -f "status=running") ]]; then
  978. echo_content skyBlue "---> Trojan Panel Frontend installation completed"
  979. https_flag=$([[ -z ${ui_https} || ${ui_https} == 1 ]] && echo "https" || echo "http")
  980. domain_or_ip=$([[ -z ${domain} || "${domain}" == "custom_cert" ]] && echo "ip" || echo "${domain}")
  981. echo_content red "\n=============================================================="
  982. echo_content skyBlue "Trojan Panel Frontend installed successfully"
  983. echo_content yellow "Web management panel address: ${https_flag}://${domain_or_ip}:${trojan_panel_ui_port}"
  984. echo_content red "\n=============================================================="
  985. else
  986. echo_content red "---> Trojan Panel Frontend installation fails or runs abnormally, please try to repair or uninstall and reinstall"
  987. exit 0
  988. fi
  989. else
  990. echo_content skyBlue "---> You have installed the Trojan Panel Frontend"
  991. fi
  992. }
  993. # Install Trojan Panel Backend
  994. install_trojan_panel() {
  995. if [[ -z $(docker ps -a -q -f "name=^trojan-panel$") ]]; then
  996. echo_content green "---> Install Trojan Panel Backend"
  997. read -r -p "Please enter the service port of the Trojan Panel Backend (default: 8081): " trojan_panel_port
  998. [[ -z "${trojan_panel_port}" ]] && trojan_panel_port=8081
  999. read -r -p "Please enter the IP address of MariaDB (default: local host): " mariadb_ip
  1000. [[ -z "${mariadb_ip}" ]] && mariadb_ip="127.0.0.1"
  1001. read -r -p "Please enter the port of MariaDB (default: 9507): " mariadb_port
  1002. [[ -z "${mariadb_port}" ]] && mariadb_port=9507
  1003. read -r -p "Please enter the username of MariaDB (default: root): " mariadb_user
  1004. [[ -z "${mariadb_user}" ]] && mariadb_user="root"
  1005. while read -r -p "Please enter the password of MariaDB (required): " mariadb_pas; do
  1006. if [[ -z "${mariadb_pas}" ]]; then
  1007. echo_content red "Password can not be empty"
  1008. else
  1009. break
  1010. fi
  1011. done
  1012. 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
  1013. read -r -p "Please enter the IP address of Redis (default: local host): " redis_host
  1014. [[ -z "${redis_host}" ]] && redis_host="127.0.0.1"
  1015. read -r -p "Please enter the port of Redis (default: 6378): " redis_port
  1016. [[ -z "${redis_port}" ]] && redis_port=6378
  1017. while read -r -p "Please enter the Redis password (required): " redis_pass; do
  1018. if [[ -z "${redis_pass}" ]]; then
  1019. echo_content red "Password can not be empty"
  1020. else
  1021. break
  1022. fi
  1023. done
  1024. docker exec trojan-panel-redis redis-cli -h "${redis_host}" -p "${redis_port}" -a "${redis_pass}" -e "flushall" &>/dev/null
  1025. docker pull jonssonyan/trojan-panel &&
  1026. docker run -d --name trojan-panel --restart always \
  1027. --network=host \
  1028. -v ${WEB_PATH}:${TROJAN_PANEL_WEBFILE} \
  1029. -v ${TROJAN_PANEL_LOGS}:${TROJAN_PANEL_LOGS} \
  1030. -v ${TROJAN_PANEL_CONFIG}:${TROJAN_PANEL_CONFIG} \
  1031. -v /etc/localtime:/etc/localtime \
  1032. -e GIN_MODE=release \
  1033. -e "mariadb_ip=${mariadb_ip}" \
  1034. -e "mariadb_port=${mariadb_port}" \
  1035. -e "mariadb_user=${mariadb_user}" \
  1036. -e "mariadb_pas=${mariadb_pas}" \
  1037. -e "redis_host=${redis_host}" \
  1038. -e "redis_port=${redis_port}" \
  1039. -e "redis_pass=${redis_pass}" \
  1040. -e "server_port=${trojan_panel_port}" \
  1041. jonssonyan/trojan-panel
  1042. if [[ -n $(docker ps -q -f "name=^trojan-panel$" -f "status=running") ]]; then
  1043. echo_content skyBlue "---> Trojan Panel Backend installation completed"
  1044. echo_content red "\n=============================================================="
  1045. echo_content skyBlue "Trojan Panel Backend installed successfully"
  1046. echo_content yellow "MariaDB ${mariadb_user} password (please keep it safe): ${mariadb_pas}"
  1047. echo_content yellow "Redis password (please keep it safe): ${redis_pass}"
  1048. echo_content yellow "System administrator Default username: sysadmin Default password: 123456 Please log in to the management panel to change the password in time"
  1049. echo_content red "\n=============================================================="
  1050. else
  1051. echo_content red "---> Trojan Panel Backend installation fails or runs abnormally, please try to repair or uninstall and reinstall"
  1052. exit 0
  1053. fi
  1054. else
  1055. echo_content skyBlue "---> You have installed the Trojan Panel Backend"
  1056. fi
  1057. }
  1058. # Install Trojan Panel Core
  1059. install_trojan_panel_core() {
  1060. if [[ -z $(docker ps -a -q -f "name=^trojan-panel-core$") ]]; then
  1061. echo_content green "---> Install Trojan Panel Core"
  1062. read -r -p "Please enter the service port of the Trojan Panel Core (default: 8082): " trojan_panel_core_port
  1063. [[ -z "${trojan_panel_core_port}" ]] && trojan_panel_core_port=8082
  1064. read -r -p "Please enter the IP address of MariaDB (default: local host): " mariadb_ip
  1065. [[ -z "${mariadb_ip}" ]] && mariadb_ip="127.0.0.1"
  1066. read -r -p "Please enter the port of MariaDB (default: 9507): " mariadb_port
  1067. [[ -z "${mariadb_port}" ]] && mariadb_port=9507
  1068. read -r -p "Please enter the username of MariaDB (default: root): " mariadb_user
  1069. [[ -z "${mariadb_user}" ]] && mariadb_user="root"
  1070. while read -r -p "Please enter the password of MariaDB (required): " mariadb_pas; do
  1071. if [[ -z "${mariadb_pas}" ]]; then
  1072. echo_content red "Password can not be empty"
  1073. else
  1074. break
  1075. fi
  1076. done
  1077. read -r -p "Please enter the database name (default: trojan_panel_db): " database
  1078. [[ -z "${database}" ]] && database="trojan_panel_db"
  1079. read -r -p "Please enter the user table name of the database (default: account): " account_table
  1080. [[ -z "${account_table}" ]] && account_table="account"
  1081. read -r -p "Please enter the IP address of Redis (default: local host): " redis_host
  1082. [[ -z "${redis_host}" ]] && redis_host="127.0.0.1"
  1083. read -r -p "Please enter the port of Redis (default: 6378): " redis_port
  1084. [[ -z "${redis_port}" ]] && redis_port=6378
  1085. while read -r -p "Please enter the Redis password (required): " redis_pass; do
  1086. if [[ -z "${redis_pass}" ]]; then
  1087. echo_content red "Password can not be empty"
  1088. else
  1089. break
  1090. fi
  1091. done
  1092. read -r -p "Please enter the API port (default: 8100): " grpc_port
  1093. [[ -z "${grpc_port}" ]] && grpc_port=8100
  1094. domain=$(cat "${DOMAIN_FILE}")
  1095. docker pull jonssonyan/trojan-panel-core &&
  1096. docker run -d --name trojan-panel-core --restart always \
  1097. --network=host \
  1098. -v ${TROJAN_PANEL_CORE_DATA}bin/xray/config:${TROJAN_PANEL_CORE_DATA}bin/xray/config \
  1099. -v ${TROJAN_PANEL_CORE_DATA}bin/trojango/config:${TROJAN_PANEL_CORE_DATA}bin/trojango/config \
  1100. -v ${TROJAN_PANEL_CORE_DATA}bin/hysteria/config:${TROJAN_PANEL_CORE_DATA}bin/hysteria/config \
  1101. -v ${TROJAN_PANEL_CORE_DATA}bin/naiveproxy/config:${TROJAN_PANEL_CORE_DATA}bin/naiveproxy/config \
  1102. -v ${TROJAN_PANEL_CORE_LOGS}:${TROJAN_PANEL_CORE_LOGS} \
  1103. -v ${TROJAN_PANEL_CORE_CONFIG}:${TROJAN_PANEL_CORE_CONFIG} \
  1104. -v ${CERT_PATH}:${CERT_PATH} \
  1105. -v ${WEB_PATH}:${WEB_PATH} \
  1106. -v /etc/localtime:/etc/localtime \
  1107. -e GIN_MODE=release \
  1108. -e "mariadb_ip=${mariadb_ip}" \
  1109. -e "mariadb_port=${mariadb_port}" \
  1110. -e "mariadb_user=${mariadb_user}" \
  1111. -e "mariadb_pas=${mariadb_pas}" \
  1112. -e "database=${database}" \
  1113. -e "account-table=${account_table}" \
  1114. -e "redis_host=${redis_host}" \
  1115. -e "redis_port=${redis_port}" \
  1116. -e "redis_pass=${redis_pass}" \
  1117. -e "crt_path=${CERT_PATH}${domain}.crt" \
  1118. -e "key_path=${CERT_PATH}${domain}.key" \
  1119. -e "grpc_port=${grpc_port}" \
  1120. -e "server_port=${trojan_panel_core_port}" \
  1121. jonssonyan/trojan-panel-core
  1122. if [[ -n $(docker ps -q -f "name=^trojan-panel-core$" -f "status=running") ]]; then
  1123. echo_content skyBlue "---> Trojan Panel Core installation completed"
  1124. else
  1125. echo_content red "---> Trojan Panel Core installation fails or runs abnormally, please try to repair or uninstall and reinstall"
  1126. exit 0
  1127. fi
  1128. else
  1129. echo_content skyBlue "---> You have installed the Trojan Panel Core"
  1130. fi
  1131. }
  1132. # Update Trojan Panel database structure
  1133. update_trojan_panel_database() {
  1134. echo_content skyBlue "---> Update Trojan Panel database structure"
  1135. if [[ "${trojan_panel_current_version}" == "v1.3.1" ]]; then
  1136. 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 &&
  1137. trojan_panel_current_version="v2.0.0"
  1138. fi
  1139. version_200_203=("v2.0.0" "v2.0.1" "v2.0.2")
  1140. if [[ "${version_200_203[*]}" =~ "${trojan_panel_current_version}" ]]; then
  1141. 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 &&
  1142. trojan_panel_current_version="v2.0.3"
  1143. fi
  1144. version_203_205=("v2.0.3" "v2.0.4")
  1145. if [[ "${version_203_205[*]}" =~ "${trojan_panel_current_version}" ]]; then
  1146. 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 &&
  1147. trojan_panel_current_version="v2.0.5"
  1148. fi
  1149. version_205_210=("v2.0.5")
  1150. if [[ "${version_205_210[*]}" =~ "${trojan_panel_current_version}" ]]; then
  1151. domain=$(cat "${DOMAIN_FILE}")
  1152. if [[ -z "${domain}" ]]; then
  1153. docker rm -f trojan-panel-caddy
  1154. rm -rf /tpdata/caddy/srv/
  1155. rm -rf /tpdata/caddy/cert/
  1156. rm -f /tpdata/caddy/domain.lock
  1157. install_reverse_proxy
  1158. cp /tpdata/nginx/default.conf ${UI_NGINX_CONFIG} &&
  1159. sed -i "s#/tpdata/caddy/cert/#${CERT_PATH}#g" ${UI_NGINX_CONFIG}
  1160. fi
  1161. 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 &&
  1162. trojan_panel_current_version="v2.1.0"
  1163. fi
  1164. version_210_211=("v2.1.0")
  1165. if [[ "${version_210_211[*]}" =~ "${trojan_panel_current_version}" ]]; then
  1166. 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 &&
  1167. trojan_panel_current_version="v2.1.1"
  1168. fi
  1169. version_211_212=("v2.1.1")
  1170. if [[ "${version_211_212[*]}" =~ "${trojan_panel_current_version}" ]]; then
  1171. 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 &&
  1172. trojan_panel_current_version="v2.1.2"
  1173. fi
  1174. version_212_214=("v2.1.2" "v2.1.3")
  1175. if [[ "${version_212_214[*]}" =~ "${trojan_panel_current_version}" ]]; then
  1176. docker cp trojan-panel:${trojan_panel_config_path} ${trojan_panel_config_path} &&
  1177. trojan_panel_current_version="v2.1.4" &&
  1178. echo '[server]
  1179. port=8081' >>${trojan_panel_config_path}
  1180. docker rm -f trojan-panel-ui &&
  1181. docker rmi -f jonssonyan/trojan-panel-ui
  1182. docker pull jonssonyan/trojan-panel-ui &&
  1183. docker run -d --name trojan-panel-ui --restart always \
  1184. --network=host \
  1185. -v "${UI_NGINX_CONFIG}":"/etc/nginx/conf.d/default.conf" \
  1186. -v ${CERT_PATH}:${CERT_PATH} \
  1187. jonssonyan/trojan-panel-ui
  1188. fi
  1189. version_214_215=("v2.1.4")
  1190. if [[ "${version_214_215[*]}" =~ "${trojan_panel_current_version}" ]]; then
  1191. 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 &&
  1192. trojan_panel_current_version="v2.1.5"
  1193. fi
  1194. echo_content skyBlue "---> Trojan Panel database structure update completed"
  1195. }
  1196. # Update Trojan Panel Core database structure
  1197. update_trojan_panel_core_database() {
  1198. echo_content skyBlue "---> Update Trojan Panel Core database structure"
  1199. version_204_210=("v2.0.4")
  1200. if [[ "${version_204_210[*]}" =~ "${trojan_panel_core_current_version}" ]]; then
  1201. domain=$(cat "${DOMAIN_FILE}")
  1202. if [[ -z "${domain}" ]]; then
  1203. docker rm -f trojan-panel-caddy
  1204. rm -rf /tpdata/caddy/srv/
  1205. rm -rf /tpdata/caddy/cert/
  1206. rm -f /tpdata/caddy/domain.lock
  1207. install_reverse_proxy
  1208. cp /tpdata/nginx/default.conf ${UI_NGINX_CONFIG} &&
  1209. sed -i "s#/tpdata/caddy/cert/#${CERT_PATH}#g" ${UI_NGINX_CONFIG}
  1210. fi
  1211. trojan_panel_core_current_version="v2.1.0"
  1212. fi
  1213. version_210_211=("v2.1.0")
  1214. if [[ "${version_210_211[*]}" =~ "${trojan_panel_core_current_version}" ]]; then
  1215. docker cp trojan-panel-core:${trojan_panel_core_config_path} ${trojan_panel_core_config_path} &&
  1216. trojan_panel_core_current_version="v2.1.1" &&
  1217. echo '[server]
  1218. port=8082' >>${trojan_panel_core_config_path}
  1219. fi
  1220. echo_content skyBlue "---> Trojan Panel Core database structure update completed"
  1221. }
  1222. # Update Trojan Panel Frontend
  1223. update_trojan_panel_ui() {
  1224. if [[ -z $(docker ps -a -q -f "name=^trojan-panel-ui$") ]]; then
  1225. echo_content red "---> Please install the Trojan Panel Frontend first"
  1226. exit 0
  1227. fi
  1228. trojan_panel_ui_current_version=$(docker exec trojan-panel-ui cat ${TROJAN_PANEL_UI_DATA}version)
  1229. if [[ -z "${trojan_panel_ui_current_version}" || ! "${trojan_panel_ui_current_version}" =~ ^v.* ]]; then
  1230. echo_content red "---> The current version does not support online updates"
  1231. exit 0
  1232. fi
  1233. 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}"
  1234. if [[ "${trojan_panel_ui_current_version}" != "${trojan_panel_ui_latest_version}" ]]; then
  1235. echo_content green "---> Update Trojan Panel Frontend"
  1236. docker rm -f trojan-panel-ui &&
  1237. docker rmi -f jonssonyan/trojan-panel-ui
  1238. docker pull jonssonyan/trojan-panel-ui &&
  1239. docker run -d --name trojan-panel-ui --restart always \
  1240. --network=host \
  1241. -v "${UI_NGINX_CONFIG}":"/etc/nginx/conf.d/default.conf" \
  1242. -v ${CERT_PATH}:${CERT_PATH} \
  1243. jonssonyan/trojan-panel-ui
  1244. if [[ -n $(docker ps -q -f "name=^trojan-panel-ui$" -f "status=running") ]]; then
  1245. echo_content skyBlue "---> Trojan Panel Frontend update completed"
  1246. else
  1247. echo_content red "---> Trojan Panel Frontend update fails or runs abnormally, please try to repair or uninstall and reinstall"
  1248. fi
  1249. else
  1250. echo_content skyBlue "---> You have installed the latest version of the Trojan Panel Frontend"
  1251. fi
  1252. }
  1253. # Update Trojan Panel Backend
  1254. update_trojan_panel() {
  1255. if [[ -z $(docker ps -a -q -f "name=^trojan-panel$") ]]; then
  1256. echo_content red "---> Please install the Trojan Panel Backend first"
  1257. exit 0
  1258. fi
  1259. trojan_panel_current_version=$(docker exec trojan-panel ./trojan-panel -version)
  1260. if [[ -z "${trojan_panel_current_version}" || ! "${trojan_panel_current_version}" =~ ^v.* ]]; then
  1261. echo_content red "---> The current version does not support online updates"
  1262. exit 0
  1263. fi
  1264. 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}"
  1265. if [[ "${trojan_panel_current_version}" != "${trojan_panel_latest_version}" ]]; then
  1266. echo_content green "---> Update Trojan Panel Backend"
  1267. mariadb_ip=$(get_ini_value ${trojan_panel_config_path} mysql.host)
  1268. mariadb_port=$(get_ini_value ${trojan_panel_config_path} mysql.port)
  1269. mariadb_user=$(get_ini_value ${trojan_panel_config_path} mysql.user)
  1270. mariadb_pas=$(get_ini_value ${trojan_panel_config_path} mysql.password)
  1271. redis_host=$(get_ini_value ${trojan_panel_config_path} redis.host)
  1272. redis_port=$(get_ini_value ${trojan_panel_config_path} redis.port)
  1273. redis_pass=$(get_ini_value ${trojan_panel_config_path} redis.password)
  1274. trojan_panel_port=$(get_ini_value ${trojan_panel_config_path} server.port)
  1275. update_trojan_panel_database
  1276. docker exec trojan-panel-redis redis-cli -h "${redis_host}" -p "${redis_port}" -a "${redis_pass}" -e "flushall" &>/dev/null
  1277. docker rm -f trojan-panel &&
  1278. docker rmi -f jonssonyan/trojan-panel
  1279. docker pull jonssonyan/trojan-panel &&
  1280. docker run -d --name trojan-panel --restart always \
  1281. --network=host \
  1282. -v ${WEB_PATH}:${TROJAN_PANEL_WEBFILE} \
  1283. -v ${TROJAN_PANEL_LOGS}:${TROJAN_PANEL_LOGS} \
  1284. -v ${TROJAN_PANEL_CONFIG}:${TROJAN_PANEL_CONFIG} \
  1285. -v /etc/localtime:/etc/localtime \
  1286. -e GIN_MODE=release \
  1287. -e "mariadb_ip=${mariadb_ip}" \
  1288. -e "mariadb_port=${mariadb_port}" \
  1289. -e "mariadb_user=${mariadb_user}" \
  1290. -e "mariadb_pas=${mariadb_pas}" \
  1291. -e "redis_host=${redis_host}" \
  1292. -e "redis_port=${redis_port}" \
  1293. -e "redis_pass=${redis_pass}" \
  1294. -e "server_port=${trojan_panel_port}" \
  1295. jonssonyan/trojan-panel
  1296. if [[ -n $(docker ps -q -f "name=^trojan-panel$" -f "status=running") ]]; then
  1297. echo_content skyBlue "---> Trojan Panel backend update completed"
  1298. else
  1299. echo_content red "---> Trojan Panel Backend update fails or runs abnormally, please try to repair or uninstall and reinstall"
  1300. fi
  1301. else
  1302. echo_content skyBlue "---> You have installed the latest version of the Trojan Panel Backend"
  1303. fi
  1304. }
  1305. # Update Trojan Panel Core
  1306. update_trojan_panel_core() {
  1307. if [[ -z $(docker ps -a -q -f "name=^trojan-panel-core$") ]]; then
  1308. echo_content red "---> Please install the Trojan Panel Core first"
  1309. exit 0
  1310. fi
  1311. trojan_panel_core_current_version=$(docker exec trojan-panel-core ./trojan-panel-core -version)
  1312. if [[ -z "${trojan_panel_core_current_version}" || ! "${trojan_panel_core_current_version}" =~ ^v.* ]]; then
  1313. echo_content red "---> The current version does not support online updates"
  1314. exit 0
  1315. fi
  1316. 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}"
  1317. if [[ "${trojan_panel_core_current_version}" != "${trojan_panel_core_latest_version}" ]]; then
  1318. echo_content green "---> Update Trojan Panel Core"
  1319. mariadb_ip=$(get_ini_value ${trojan_panel_core_config_path} mysql.host)
  1320. mariadb_port=$(get_ini_value ${trojan_panel_core_config_path} mysql.port)
  1321. mariadb_user=$(get_ini_value ${trojan_panel_core_config_path} mysql.user)
  1322. mariadb_pas=$(get_ini_value ${trojan_panel_core_config_path} mysql.password)
  1323. redis_host=$(get_ini_value ${trojan_panel_core_config_path} redis.host)
  1324. redis_port=$(get_ini_value ${trojan_panel_core_config_path} redis.port)
  1325. redis_pass=$(get_ini_value ${trojan_panel_core_config_path} redis.password)
  1326. grpc_port=$(get_ini_value ${trojan_panel_core_config_path} grpc.port)
  1327. trojan_panel_core_port=$(get_ini_value ${trojan_panel_core_config_path} server.port)
  1328. update_trojan_panel_core_database
  1329. docker exec trojan-panel-redis redis-cli -h "${redis_host}" -p "${redis_port}" -a "${redis_pass}" -e "flushall" &>/dev/null
  1330. docker rm -f trojan-panel-core &&
  1331. docker rmi -f jonssonyan/trojan-panel-core
  1332. domain=$(cat "${DOMAIN_FILE}")
  1333. docker pull jonssonyan/trojan-panel-core &&
  1334. docker run -d --name trojan-panel-core --restart always \
  1335. --network=host \
  1336. -v ${TROJAN_PANEL_CORE_DATA}bin/xray/config:${TROJAN_PANEL_CORE_DATA}bin/xray/config \
  1337. -v ${TROJAN_PANEL_CORE_DATA}bin/trojango/config:${TROJAN_PANEL_CORE_DATA}bin/trojango/config \
  1338. -v ${TROJAN_PANEL_CORE_DATA}bin/hysteria/config:${TROJAN_PANEL_CORE_DATA}bin/hysteria/config \
  1339. -v ${TROJAN_PANEL_CORE_DATA}bin/naiveproxy/config:${TROJAN_PANEL_CORE_DATA}bin/naiveproxy/config \
  1340. -v ${TROJAN_PANEL_CORE_LOGS}:${TROJAN_PANEL_CORE_LOGS} \
  1341. -v ${TROJAN_PANEL_CORE_CONFIG}:${TROJAN_PANEL_CORE_CONFIG} \
  1342. -v ${CERT_PATH}:${CERT_PATH} \
  1343. -v ${WEB_PATH}:${WEB_PATH} \
  1344. -v /etc/localtime:/etc/localtime \
  1345. -e GIN_MODE=release \
  1346. -e "mariadb_ip=${mariadb_ip}" \
  1347. -e "mariadb_port=${mariadb_port}" \
  1348. -e "mariadb_user=${mariadb_user}" \
  1349. -e "mariadb_pas=${mariadb_pas}" \
  1350. -e "database=${database}" \
  1351. -e "account-table=${account_table}" \
  1352. -e "redis_host=${redis_host}" \
  1353. -e "redis_port=${redis_port}" \
  1354. -e "redis_pass=${redis_pass}" \
  1355. -e "crt_path=${CERT_PATH}${domain}.crt" \
  1356. -e "key_path=${CERT_PATH}${domain}.key" \
  1357. -e "grpc_port=${grpc_port}" \
  1358. -e "server_port=${trojan_panel_core_port}" \
  1359. jonssonyan/trojan-panel-core
  1360. if [[ -n $(docker ps -q -f "name=^trojan-panel-core$" -f "status=running") ]]; then
  1361. echo_content skyBlue "---> Trojan Panel Core update completed"
  1362. else
  1363. echo_content red "---> Trojan Panel Core update fails or runs abnormally, please try to repair or uninstall and reinstall"
  1364. fi
  1365. else
  1366. echo_content skyBlue "---> You have installed the latest version of the Trojan Panel Core"
  1367. fi
  1368. }
  1369. # Uninstall Caddy2+https
  1370. uninstall_caddy2() {
  1371. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-caddy$") ]]; then
  1372. echo_content green "---> Uninstall Caddy2+https"
  1373. docker rm -f trojan-panel-caddy &&
  1374. rm -rf ${CADDY_DATA}
  1375. echo_content skyBlue "---> Caddy2+https uninstallation completed"
  1376. else
  1377. echo_content red "---> Please install Caddy2+https first"
  1378. fi
  1379. }
  1380. # Uninstall Nginx
  1381. uninstall_nginx() {
  1382. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-nginx") ]]; then
  1383. echo_content green "---> Uninstall Nginx"
  1384. docker rm -f trojan-panel-nginx &&
  1385. rm -rf ${NGINX_DATA}
  1386. echo_content skyBlue "---> Nginx uninstallation completed"
  1387. else
  1388. echo_content red "---> Please install Nginx first"
  1389. fi
  1390. }
  1391. # Uninstall MariaDB
  1392. uninstall_mariadb() {
  1393. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-mariadb$") ]]; then
  1394. echo_content green "---> Uninstall MariaDB"
  1395. docker rm -f trojan-panel-mariadb &&
  1396. rm -rf ${MARIA_DATA}
  1397. echo_content skyBlue "---> MariaDB uninstall completed"
  1398. else
  1399. echo_content red "---> Please install MariaDB first"
  1400. fi
  1401. }
  1402. # Uninstall Redis
  1403. uninstall_redis() {
  1404. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-redis$") ]]; then
  1405. echo_content green "---> Uninstall Redis"
  1406. docker rm -f trojan-panel-redis &&
  1407. rm -rf ${REDIS_DATA}
  1408. echo_content skyBlue "---> Redis uninstall completed"
  1409. else
  1410. echo_content red "---> Please install Redis first"
  1411. fi
  1412. }
  1413. # Uninstall Trojan Panel Frontend
  1414. uninstall_trojan_panel_ui() {
  1415. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-ui$") ]]; then
  1416. echo_content green "---> Uninstall Trojan Panel Frontend"
  1417. docker rm -f trojan-panel-ui &&
  1418. docker rmi -f jonssonyan/trojan-panel-ui &&
  1419. rm -rf ${TROJAN_PANEL_UI_DATA}
  1420. echo_content skyBlue "---> Trojan Panel Frontend uninstallation completed"
  1421. else
  1422. echo_content red "---> Please install the Trojan Panel Frontend first"
  1423. fi
  1424. }
  1425. # Uninstall Trojan Panel Backend
  1426. uninstall_trojan_panel() {
  1427. if [[ -n $(docker ps -a -q -f "name=^trojan-panel$") ]]; then
  1428. echo_content green "---> Uninstall Trojan Panel Backend"
  1429. docker rm -f trojan-panel &&
  1430. docker rmi -f jonssonyan/trojan-panel &&
  1431. rm -rf ${TROJAN_PANEL_DATA}
  1432. echo_content skyBlue "---> Trojan Panel Backend uninstallation completed"
  1433. else
  1434. echo_content red "---> Please install the Trojan Panel Backend first"
  1435. fi
  1436. }
  1437. # Uninstall Trojan Panel Core
  1438. uninstall_trojan_panel_core() {
  1439. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-core$") ]]; then
  1440. echo_content green "---> Uninstall Trojan Panel Core"
  1441. docker rm -f trojan-panel-core &&
  1442. docker rmi -f jonssonyan/trojan-panel-core &&
  1443. rm -rf ${TROJAN_PANEL_CORE_DATA}
  1444. echo_content skyBlue "---> Trojan Panel Core uninstallation completed"
  1445. else
  1446. echo_content red "---> Please install the Trojan Panel Core first"
  1447. fi
  1448. }
  1449. # Uninstall all Trojan Panel related containers
  1450. uninstall_all() {
  1451. echo_content green "---> Uninstall all Trojan Panel related containers"
  1452. docker rm -f $(docker ps -a -q -f "name=^trojan-panel")
  1453. docker rmi -f $(docker images | grep "^jonssonyan/trojan-panel" | awk '{print $3}')
  1454. rm -rf ${TP_DATA}
  1455. echo_content skyBlue "---> Uninstall all Trojan Panel related containers completed"
  1456. }
  1457. # Modify Trojan Panel Frontend port
  1458. update_trojan_panel_ui_port() {
  1459. if [[ -n $(docker ps -q -f "name=^trojan-panel-ui$" -f "status=running") ]]; then
  1460. echo_content green "---> Modify Trojan Panel Frontend port"
  1461. trojan_panel_ui_port=$(grep 'listen.*ssl' ${UI_NGINX_CONFIG} | awk '{print $2}')
  1462. if [[ -z "${trojan_panel_ui_port}" ]]; then
  1463. ui_https=0
  1464. trojan_panel_ui_port=$(grep -oP 'listen\s+\K\d+' ${UI_NGINX_CONFIG} | awk 'NR==1')
  1465. fi
  1466. if [[ -z "${trojan_panel_ui_port}" ]]; then
  1467. echo_content red "---> Trojan Panel Frontend port not queried"
  1468. exit 0
  1469. fi
  1470. echo_content yellow "Tip: The current port of the Trojan Panel Frontend (trojan-panel-ui) is ${trojan_panel_ui_port}"
  1471. read -r -p "Please enter the new port of the Trojan Panel Frontend (default: 8888): " trojan_panel_ui_port
  1472. [[ -z "${trojan_panel_ui_port}" ]] && trojan_panel_ui_port="8888"
  1473. if [[ ${ui_https} == 0 ]]; then
  1474. # http
  1475. sed -i "s/listen.*;/listen ${trojan_panel_ui_port};/g" ${UI_NGINX_CONFIG} &&
  1476. sed -i "s/http:\/\/\$host:.*\$request_uri;/http:\/\/\$host:${trojan_panel_ui_port}\$request_uri;/g" ${UI_NGINX_CONFIG} &&
  1477. docker restart trojan-panel-ui
  1478. else
  1479. # https
  1480. sed -i "s/listen.*ssl;/listen ${trojan_panel_ui_port} ssl;/g" ${UI_NGINX_CONFIG} &&
  1481. sed -i "s/https:\/\/\$host:.*\$request_uri;/https:\/\/\$host:${trojan_panel_ui_port}\$request_uri;/g" ${UI_NGINX_CONFIG} &&
  1482. docker restart trojan-panel-ui
  1483. fi
  1484. if [[ "$?" == "0" ]]; then
  1485. echo_content skyBlue "---> Trojan Panel Frontend port modification completed"
  1486. else
  1487. echo_content red "---> Trojan Panel Frontend port modification failed"
  1488. fi
  1489. else
  1490. echo_content red "---> The Trojan Panel Frontend is not installed or is running abnormally, please repair or uninstall and reinstall and try again"
  1491. fi
  1492. }
  1493. # Refresh Redis cache
  1494. redis_flush_all() {
  1495. if [[ -z $(docker ps -a -q -f "name=^trojan-panel-redis$") ]]; then
  1496. echo_content red "---> Please install Redis first"
  1497. exit 0
  1498. fi
  1499. if [[ -z $(docker ps -q -f "name=^trojan-panel-redis$" -f "status=running") ]]; then
  1500. echo_content red "---> Redis is running abnormally"
  1501. exit 0
  1502. fi
  1503. echo_content green "---> Refresh Redis cache"
  1504. read -r -p "Please enter the IP address of Redis (default: local host): " redis_host
  1505. [[ -z "${redis_host}" ]] && redis_host="127.0.0.1"
  1506. read -r -p "Please enter the port of Redis (default: 6378): " redis_port
  1507. [[ -z "${redis_port}" ]] && redis_port=6378
  1508. while read -r -p "Please enter the Redis password (required): " redis_pass; do
  1509. if [[ -z "${redis_pass}" ]]; then
  1510. echo_content red "Password can not be empty"
  1511. else
  1512. break
  1513. fi
  1514. done
  1515. docker exec trojan-panel-redis redis-cli -h "${redis_host}" -p "${redis_port}" -a "${redis_pass}" -e "flushall" &>/dev/null
  1516. echo_content skyBlue "---> Redis cache refresh completed"
  1517. }
  1518. # Replace certificate
  1519. change_cert() {
  1520. domain_1=$(cat "${DOMAIN_FILE}")
  1521. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-caddy$") ]]; then
  1522. docker rm -f trojan-panel-caddy &&
  1523. rm -rf ${CADDY_LOG}* &&
  1524. echo "" >${CADDY_CONFIG} &&
  1525. rm -rf ${WEB_PATH}*
  1526. fi
  1527. rm -rf ${CERT_PATH}* &&
  1528. echo "" >${DOMAIN_FILE}
  1529. install_reverse_proxy
  1530. install_cert
  1531. domain_2=$(cat "${DOMAIN_FILE}")
  1532. if [[ -n "${domain_1}" && -n "${domain_2}" ]]; then
  1533. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-nginx$") ]]; then
  1534. sed -i "s/${domain_1}/${domain_2}/g" ${NGINX_CONFIG} &&
  1535. docker restart trojan-panel-nginx
  1536. fi
  1537. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-ui$") ]]; then
  1538. sed -i "s/${domain_1}/${domain_2}/g" ${UI_NGINX_DATA} &&
  1539. docker restart trojan-panel-ui
  1540. fi
  1541. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-core$") ]]; then
  1542. find /tpdata/trojan-panel-core/bin/ -type f -exec sed -i "s/${domain_1}/${domain_2}/g" {} + &&
  1543. sed -i "s/${domain_1}/${domain_2}/g" ${trojan_panel_core_config_path} &&
  1544. docker restart trojan-panel-core
  1545. fi
  1546. fi
  1547. }
  1548. # Forgot sysadmin password
  1549. forget_pass() {
  1550. while :; do
  1551. echo_content yellow "1. Query MariaDB password"
  1552. echo_content yellow "2. Query Redis password"
  1553. echo_content yellow "3. Reset the username and password of the admin panel system administrator"
  1554. echo_content yellow "4. Quit"
  1555. read -r -p "Please choose (default: 4): " forget_pass_option
  1556. [[ -z "${forget_pass_option}" ]] && forget_pass_option=4
  1557. case ${forget_pass_option} in
  1558. 1)
  1559. if [[ -n $(docker ps -a -q -f "name=^trojan-panel$") ]]; then
  1560. mariadb_user=$(get_ini_value ${trojan_panel_config_path} mysql.user)
  1561. mariadb_pas=$(get_ini_value ${trojan_panel_config_path} mysql.password)
  1562. echo_content red "\n=============================================================="
  1563. echo_content yellow "MariaDB ${mariadb_user} password (please keep it safe): ${mariadb_pas}"
  1564. echo_content red "\n=============================================================="
  1565. else
  1566. echo_content red "---> Please install the Trojan Panel Backend first"
  1567. fi
  1568. ;;
  1569. 2)
  1570. if [[ -n $(docker ps -a -q -f "name=^trojan-panel$") ]]; then
  1571. redis_pass=$(get_ini_value ${trojan_panel_config_path} redis.password)
  1572. echo_content red "\n=============================================================="
  1573. echo_content yellow "Redis password (please keep it safe): ${redis_pass}"
  1574. echo_content red "\n=============================================================="
  1575. else
  1576. echo_content red "---> Please install the Trojan Panel Backend first"
  1577. fi
  1578. ;;
  1579. 3)
  1580. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-mariadb$") ]]; then
  1581. read -r -p "Please enter the IP address of MariaDB (default: local host): " mariadb_ip
  1582. [[ -z "${mariadb_ip}" ]] && mariadb_ip="127.0.0.1"
  1583. read -r -p "Please enter the port of MariaDB (default: 9507): " mariadb_port
  1584. [[ -z "${mariadb_port}" ]] && mariadb_port=9507
  1585. read -r -p "Please enter the username of MariaDB (default: root): " mariadb_user
  1586. [[ -z "${mariadb_user}" ]] && mariadb_user="root"
  1587. while read -r -p "Please enter the password of MariaDB (required): " mariadb_pas; do
  1588. if [[ -z "${mariadb_pas}" ]]; then
  1589. echo_content red "Password can not be empty"
  1590. else
  1591. break
  1592. fi
  1593. done
  1594. 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"
  1595. if [[ "$?" == "0" ]]; then
  1596. echo_content red "\n=============================================================="
  1597. echo_content yellow "System administrator Default username: sysadmin Default password: 123456 Please log in to the management panel to change the password in time"
  1598. echo_content red "\n=============================================================="
  1599. else
  1600. echo_content red "Admin panel sysadmin username and password reset failed"
  1601. fi
  1602. else
  1603. echo_content red "---> Please install the MariaDB first"
  1604. fi
  1605. ;;
  1606. 4)
  1607. break
  1608. ;;
  1609. *)
  1610. echo_content red "No such option"
  1611. continue
  1612. ;;
  1613. esac
  1614. done
  1615. }
  1616. # Fault detection
  1617. failure_testing() {
  1618. echo_content green "---> Start troubleshooting"
  1619. if [[ ! $(docker -v 2>/dev/null) ]]; then
  1620. echo_content red "---> Docker is running abnormally"
  1621. else
  1622. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-caddy$") ]]; then
  1623. if [[ -z $(docker ps -q -f "name=^trojan-panel-caddy$" -f "status=running") ]]; then
  1624. echo_content red "---> Caddy2 is running abnormally and the running log is as follows:"
  1625. docker logs trojan-panel-caddy
  1626. fi
  1627. domain=$(cat "${DOMAIN_FILE}")
  1628. if [[ -n ${domain} && ! -f "${CERT_PATH}${domain}.crt" ]]; then
  1629. 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"
  1630. if [[ -f ${CADDY_LOG}error.log ]]; then
  1631. echo_content red "Caddy2 error log is as follows:"
  1632. tail -n 20 ${CADDY_LOG}error.log | grep error
  1633. fi
  1634. fi
  1635. fi
  1636. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-mariadb$") && -z $(docker ps -q -f "name=^trojan-panel-mariadb$" -f "status=running") ]]; then
  1637. echo_content red "---> The MariaDB is running abnormally and the running log is as follows:"
  1638. docker logs trojan-panel-mariadb
  1639. fi
  1640. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-redis$") && -z $(docker ps -q -f "name=^trojan-panel-redis$" -f "status=running") ]]; then
  1641. echo_content red "---> The Redis is running abnormally and the running log is as follows:"
  1642. docker logs trojan-panel-redis
  1643. fi
  1644. if [[ -n $(docker ps -a -q -f "name=^trojan-panel$") && -z $(docker ps -q -f "name=^trojan-panel$" -f "status=running") ]]; then
  1645. echo_content red "---> The Trojan Panel Backend is running abnormally and the running log is as follows:"
  1646. if [[ -f ${TROJAN_PANEL_LOGS}trojan-panel.log ]]; then
  1647. tail -n 20 ${TROJAN_PANEL_LOGS}trojan-panel.log | grep error
  1648. else
  1649. docker logs trojan-panel
  1650. fi
  1651. fi
  1652. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-ui$") && -z $(docker ps -q -f "name=^trojan-panel-ui$" -f "status=running") ]]; then
  1653. echo_content red "---> The Trojan Panel Frontend is running abnormally and the running log is as follows:"
  1654. docker logs trojan-panel-ui
  1655. fi
  1656. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-core$") && -z $(docker ps -q -f "name=^trojan-panel-core$" -f "status=running") ]]; then
  1657. echo_content red "---> The Trojan Panel Core is running abnormally and the running log is as follows:"
  1658. if [[ -f ${TROJAN_PANEL_CORE_LOGS}trojan-panel.log ]]; then
  1659. tail -n 20 ${TROJAN_PANEL_CORE_LOGS}trojan-panel.log | grep error
  1660. else
  1661. docker logs trojan-panel-core
  1662. fi
  1663. fi
  1664. fi
  1665. echo_content green "---> Troubleshooting ended"
  1666. }
  1667. log_query() {
  1668. while :; do
  1669. echo_content skyBlue "Applications that can query logs are as follows:"
  1670. echo_content yellow "1. Trojan Panel Backend"
  1671. echo_content yellow "2. Trojan Panel Frontend"
  1672. echo_content yellow "3. Quit"
  1673. read -r -p "Please select an application (default: 1): " select_log_query_type
  1674. [[ -z "${select_log_query_type}" ]] && select_log_query_type=1
  1675. case ${select_log_query_type} in
  1676. 1)
  1677. log_file_path=${TROJAN_PANEL_LOGS}trojan-panel.log
  1678. ;;
  1679. 2)
  1680. log_file_path=${TROJAN_PANEL_CORE_LOGS}trojan-panel-core.log
  1681. ;;
  1682. 3)
  1683. break
  1684. ;;
  1685. *)
  1686. echo_content red "No such option"
  1687. continue
  1688. ;;
  1689. esac
  1690. read -r -p "Please enter the number of rows to query (default: 20): " select_log_query_line_type
  1691. [[ -z "${select_log_query_line_type}" ]] && select_log_query_line_type=20
  1692. if [[ -f ${log_file_path} ]]; then
  1693. echo_content skyBlue "The log is as follows:"
  1694. tail -n ${select_log_query_line_type} ${log_file_path}
  1695. else
  1696. echo_content red "No log file exists"
  1697. fi
  1698. done
  1699. }
  1700. version_query() {
  1701. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-ui$") && -n $(docker ps -q -f "name=^trojan-panel-ui$" -f "status=running") ]]; then
  1702. trojan_panel_ui_current_version=$(docker exec trojan-panel-ui cat ${TROJAN_PANEL_UI_DATA}version)
  1703. 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}"
  1704. fi
  1705. if [[ -n $(docker ps -a -q -f "name=^trojan-panel$") && -n $(docker ps -q -f "name=^trojan-panel$" -f "status=running") ]]; then
  1706. trojan_panel_current_version=$(docker exec trojan-panel ./trojan-panel -version)
  1707. 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}"
  1708. fi
  1709. if [[ -n $(docker ps -a -q -f "name=^trojan-panel-core$") && -n $(docker ps -q -f "name=^trojan-panel-core$" -f "status=running") ]]; then
  1710. trojan_panel_core_current_version=$(docker exec trojan-panel-core ./trojan-panel-core -version)
  1711. 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}"
  1712. fi
  1713. }
  1714. main() {
  1715. cd "$HOME" || exit 0
  1716. init_var
  1717. mkdir_tools
  1718. check_sys
  1719. depend_install
  1720. clear
  1721. echo_content red "\n=============================================================="
  1722. echo_content skyBlue "System Required: CentOS 7+/Ubuntu 18+/Debian 10+"
  1723. echo_content skyBlue "Version: v2.2.0"
  1724. echo_content skyBlue "Description: One click Install Trojan Panel server"
  1725. echo_content skyBlue "Author: jonssonyan <https://jonssonyan.com>"
  1726. echo_content skyBlue "Github: https://github.com/trojanpanel"
  1727. echo_content skyBlue "Docs: https://trojanpanel.github.io"
  1728. echo_content red "\n=============================================================="
  1729. echo_content yellow "1. Install Trojan Panel Frontend"
  1730. echo_content yellow "2. Install Trojan Panel Backend"
  1731. echo_content yellow "3. Install Trojan Panel Core"
  1732. echo_content yellow "4. Install Caddy2+https"
  1733. echo_content yellow "5. Install Nginx"
  1734. echo_content yellow "6. Install MariaDB"
  1735. echo_content yellow "7. Install Redis"
  1736. echo_content green "\n=============================================================="
  1737. echo_content yellow "8. Update Trojan Panel Frontend"
  1738. echo_content yellow "9. Update Trojan Panel Backend"
  1739. echo_content yellow "10. Update Trojan Panel Core"
  1740. echo_content green "\n=============================================================="
  1741. echo_content yellow "11. Uninstall Trojan Panel Frontend"
  1742. echo_content yellow "12. Uninstall Trojan Panel Backend"
  1743. echo_content yellow "13. Uninstall Trojan Panel Core"
  1744. echo_content yellow "14. Uninstall Caddy2+https"
  1745. echo_content yellow "15. Uninstall Nginx"
  1746. echo_content yellow "16. Uninstall MariaDB"
  1747. echo_content yellow "17. Uninstall Redis"
  1748. echo_content yellow "18. Uninstall all Trojan Panel related containers"
  1749. echo_content green "\n=============================================================="
  1750. echo_content yellow "19. Modify Trojan Panel Frontend port"
  1751. echo_content yellow "20. Refresh Redis cache"
  1752. echo_content yellow "21. Replace certificate"
  1753. echo_content yellow "22. Forgot sysadmin password"
  1754. echo_content green "\n=============================================================="
  1755. echo_content yellow "23. Fault detection"
  1756. echo_content yellow "24. Log query"
  1757. echo_content yellow "25. Version query"
  1758. read -r -p "Please choose: " selectInstall_type
  1759. case ${selectInstall_type} in
  1760. 1)
  1761. install_docker
  1762. install_reverse_proxy
  1763. install_cert
  1764. install_trojan_panel_ui
  1765. ;;
  1766. 2)
  1767. install_docker
  1768. install_mariadb
  1769. install_redis
  1770. install_trojan_panel
  1771. ;;
  1772. 3)
  1773. install_docker
  1774. install_reverse_proxy
  1775. install_cert
  1776. install_trojan_panel_core
  1777. ;;
  1778. 4)
  1779. install_docker
  1780. install_caddy2
  1781. ;;
  1782. 5)
  1783. install_docker
  1784. install_nginx
  1785. ;;
  1786. 6)
  1787. install_docker
  1788. install_mariadb
  1789. ;;
  1790. 7)
  1791. install_docker
  1792. install_redis
  1793. ;;
  1794. 8)
  1795. update_trojan_panel_ui
  1796. ;;
  1797. 9)
  1798. update_trojan_panel
  1799. ;;
  1800. 10)
  1801. update_trojan_panel_core
  1802. ;;
  1803. 11)
  1804. uninstall_trojan_panel_ui
  1805. ;;
  1806. 12)
  1807. uninstall_trojan_panel
  1808. ;;
  1809. 13)
  1810. uninstall_trojan_panel_core
  1811. ;;
  1812. 14)
  1813. uninstall_caddy2
  1814. ;;
  1815. 15)
  1816. uninstall_nginx
  1817. ;;
  1818. 16)
  1819. uninstall_mariadb
  1820. ;;
  1821. 17)
  1822. uninstall_redis
  1823. ;;
  1824. 18)
  1825. uninstall_all
  1826. ;;
  1827. 19)
  1828. update_trojan_panel_ui_port
  1829. ;;
  1830. 20)
  1831. redis_flush_all
  1832. ;;
  1833. 21)
  1834. change_cert
  1835. ;;
  1836. 22)
  1837. forget_pass
  1838. ;;
  1839. 23)
  1840. failure_testing
  1841. ;;
  1842. 24)
  1843. log_query
  1844. ;;
  1845. 25)
  1846. version_query
  1847. ;;
  1848. *)
  1849. echo_content red "No such option"
  1850. ;;
  1851. esac
  1852. }
  1853. main