From 9ba1c7cb1fa95aaa62207582372d9690a3c2738a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BF=83=E9=9A=A8=E7=B7=A3=E5=8B=95?= <88259403+xeefei@users.noreply.github.com> Date: Sun, 3 Aug 2025 23:17:49 +0800 Subject: [PATCH] v2.6.3 v2.6.3 --- install.sh | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 57 insertions(+), 3 deletions(-) diff --git a/install.sh b/install.sh index 7bdf729e..c8e28ee4 100644 --- a/install.sh +++ b/install.sh @@ -200,10 +200,11 @@ config_after_install() { echo -e "${red}--------------->>>>Cancel...--------------->>>>>>>取消修改...${plain}" echo "" if [[ ! -f "/etc/x-ui/x-ui.db" ]]; then - local usernameTemp=$(head -c 6 /dev/urandom | base64) - local passwordTemp=$(head -c 6 /dev/urandom | base64) - local webBasePathTemp=$(gen_random_string 10) + local usernameTemp=$(head -c 10 /dev/urandom | base64) + local passwordTemp=$(head -c 10 /dev/urandom | base64) + local webBasePathTemp=$(gen_random_string 15) /usr/local/x-ui/x-ui setting -username ${usernameTemp} -password ${passwordTemp} -webBasePath ${webBasePathTemp} + echo "" echo -e "${yellow}检测到为全新安装,出于安全考虑将生成随机登录信息:${plain}" echo -e "###############################################" echo -e "${green}用户名: ${usernameTemp}${plain}" @@ -308,6 +309,59 @@ install_x-ui() { echo "" config_after_install +ssh_forwarding() { + # 获取 IPv4 和 IPv6 地址 + v4=$(curl -s4m8 http://ip.sb -k) + v6=$(curl -s6m8 http://ip.sb -k) + local existing_webBasePath=$(/usr/local/x-ui/x-ui setting -show true | grep -Eo 'webBasePath(访问路径): .+' | awk '{print $2}') + local existing_port=$(/usr/local/x-ui/x-ui setting -show true | grep -Eo 'port(端口号): .+' | awk '{print $2}') + local existing_cert=$(/usr/local/x-ui/x-ui setting -getCert true | grep -Eo 'cert: .+' | awk '{print $2}') + local existing_key=$(/usr/local/x-ui/x-ui setting -getCert true | grep -Eo 'key: .+' | awk '{print $2}') + + if [[ -n "$existing_cert" && -n "$existing_key" ]]; then + echo -e "${green}面板已安装证书采用SSL保护${plain}" + echo "" + echo -e "${green}登录访问面板URL: https://你的域名:${existing_port}${existing_webBasePath}${plain}" + fi + echo "" + if [[ -z "$existing_cert" && -z "$existing_key" ]]; then + echo -e "${red}警告:未找到证书和密钥,面板不安全!${plain}" + echo "" + echo -e "${green}------->>>>请按照下述方法设置〔ssh转发〕<<<<-------${plain}" + echo "" + + # 检查 IP 并输出相应的 SSH 和浏览器访问信息 + if [[ -z $v4 ]]; then + echo -e "${green}1、本地电脑客户端转发命令:${plain} ${blue}ssh -L [::]:15208:127.0.0.1:${existing_port}${blue} root@[$v6]${plain}" + echo "" + echo -e "${green}2、请在本地打开终端,成功输入服务器的〔root密码〕用以上命令进行转发${plain}" + echo "" + echo -e "${green}3、请在浏览器地址栏复制${plain} ${blue}[::1]:15208${existing_webBasePath}${plain} ${green}进入〔3X-UI〕登录界面" + echo "" + echo -e "${red}注意:若不使用〔ssh转发〕请为3X-UI面板配置安装证书再行登录管理后台${plain}" + elif [[ -n $v4 && -n $v6 ]]; then + echo -e "${green}1、本地电脑客户端转发命令:${plain} ${blue}ssh -L 15208:127.0.0.1:${existing_port}${blue} root@$v4${plain} ${yellow}或者 ${blue}ssh -L [::]:15208:127.0.0.1:${existing_port}${blue} root@[$v6]${plain}" + echo "" + echo -e "${green}2、请在本地打开终端,成功输入服务器的〔root密码〕用以上命令进行转发${plain}" + echo "" + echo -e "${green}3、请在浏览器地址栏复制${plain} ${blue}127.0.0.1:15208${existing_webBasePath}${plain} ${yellow}或者${plain} ${blue}[::1]:15208${existing_webBasePath}${plain} ${green}进入〔3X-UI〕登录界面" + echo "" + echo -e "${red}注意:若不使用〔ssh转发〕请为3X-UI面板配置安装证书再行登录管理后台${plain}" + else + echo -e "${green}1、本地电脑客户端转发命令:${plain} ${blue}ssh -L 15208:127.0.0.1:${existing_port}${blue} root@$v4${plain}" + echo "" + echo -e "${green}2、请在本地打开终端,成功输入服务器的〔root密码〕用以上命令进行转发${plain}" + echo "" + echo -e "${green}3、请在浏览器地址栏复制${plain} ${blue}127.0.0.1:15208${existing_webBasePath}${plain} ${green}进入〔3X-UI〕登录界面" + echo "" + echo -e "${red}注意:若不使用〔ssh转发〕请为3X-UI面板配置安装证书再行登录管理后台${plain}" + echo "" + fi + fi +} +# 执行ssh端口转发 +ssh_forwarding + cp -f x-ui.service /etc/systemd/system/ systemctl daemon-reload systemctl enable x-ui