mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-05-03 13:48:49 +00:00
Merge pull request #7 from serogaq/feature/6.subsHeadersAndBuildImageTar
6 / sub headers and build image tar on mac
This commit is contained in:
commit
8f9e9de7c8
4 changed files with 91 additions and 9 deletions
|
@ -4,4 +4,7 @@ BUILD_WITH_ANTIZAPRET="0"
|
||||||
XUI_SERVER_IP=""
|
XUI_SERVER_IP=""
|
||||||
XUI_PANEL_DOMAIN=""
|
XUI_PANEL_DOMAIN=""
|
||||||
XUI_SUB_DOMAIN=""
|
XUI_SUB_DOMAIN=""
|
||||||
XUI_VLESS_SNI=""
|
XUI_VLESS_SNI=""
|
||||||
|
#XUI_SUB_PROFILE_TITLE=""
|
||||||
|
#XUI_SUB_SUPPORT_URL=""
|
||||||
|
#XUI_SUB_PROFILE_WEB_PAGE_URL=""
|
|
@ -32,14 +32,18 @@ services:
|
||||||
- "traefik.tcp.routers.vless.service=3x-ui-inbound-443"
|
- "traefik.tcp.routers.vless.service=3x-ui-inbound-443"
|
||||||
- "traefik.tcp.services.3x-ui-inbound-443.loadbalancer.server.port=443"
|
- "traefik.tcp.services.3x-ui-inbound-443.loadbalancer.server.port=443"
|
||||||
volumes:
|
volumes:
|
||||||
- $PWD/db/:/etc/x-ui/
|
- ./db/:/etc/x-ui/
|
||||||
- $PWD/cert/:/root/cert/
|
- ./cert/:/root/cert/
|
||||||
|
- ./announce.txt:/etc/x-ui/announce.txt
|
||||||
environment:
|
environment:
|
||||||
PUID: 1000
|
PUID: 1000
|
||||||
PGID: 1000
|
PGID: 1000
|
||||||
XRAY_VMESS_AEAD_FORCED: "false"
|
XRAY_VMESS_AEAD_FORCED: "false"
|
||||||
TZ: Europe/Moscow
|
TZ: Europe/Moscow
|
||||||
XUI_SERVER_IP: "${XUI_SERVER_IP}"
|
XUI_SERVER_IP: "${XUI_SERVER_IP}"
|
||||||
|
XUI_SUB_PROFILE_TITLE: "${XUI_SUB_PROFILE_TITLE:-}"
|
||||||
|
XUI_SUB_SUPPORT_URL: "${XUI_SUB_SUPPORT_URL:-}"
|
||||||
|
XUI_SUB_PROFILE_WEB_PAGE_URL: "${XUI_SUB_PROFILE_WEB_PAGE_URL:-}"
|
||||||
tty: true
|
tty: true
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"net"
|
"net"
|
||||||
"strings"
|
"strings"
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
@ -74,6 +75,23 @@ func (a *SUBController) subs(c *gin.Context) {
|
||||||
host = c.Request.Host
|
host = c.Request.Host
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
var profileTitle string
|
||||||
|
profileTitle = os.Getenv("XUI_SUB_PROFILE_TITLE")
|
||||||
|
if profileTitle == "" {
|
||||||
|
profileTitle = subId
|
||||||
|
}
|
||||||
|
var supportUrl string
|
||||||
|
supportUrl = os.Getenv("XUI_SUB_PROFILE_TITLE")
|
||||||
|
if supportUrl == "" {
|
||||||
|
supportUrl = os.Getenv("XUI_SUB_DOMAIN")
|
||||||
|
}
|
||||||
|
var profileWebPageUrl string
|
||||||
|
profileWebPageUrl = os.Getenv("XUI_SUB_PROFILE_WEB_PAGE_URL")
|
||||||
|
if profileWebPageUrl == "" {
|
||||||
|
profileWebPageUrl = os.Getenv("XUI_SUB_DOMAIN")
|
||||||
|
}
|
||||||
|
var announceText string
|
||||||
|
announceText = getAnnounceText()
|
||||||
subs, header, err := a.subService.GetSubs(subId, host)
|
subs, header, err := a.subService.GetSubs(subId, host)
|
||||||
if err != nil || len(subs) == 0 {
|
if err != nil || len(subs) == 0 {
|
||||||
c.String(400, "Error!")
|
c.String(400, "Error!")
|
||||||
|
@ -86,7 +104,12 @@ func (a *SUBController) subs(c *gin.Context) {
|
||||||
// Add headers
|
// Add headers
|
||||||
c.Writer.Header().Set("Subscription-Userinfo", header)
|
c.Writer.Header().Set("Subscription-Userinfo", header)
|
||||||
c.Writer.Header().Set("Profile-Update-Interval", a.updateInterval)
|
c.Writer.Header().Set("Profile-Update-Interval", a.updateInterval)
|
||||||
c.Writer.Header().Set("Profile-Title", subId)
|
c.Writer.Header().Set("Profile-Title", profileTitle)
|
||||||
|
c.Writer.Header().Set("Support-Url", supportUrl)
|
||||||
|
c.Writer.Header().Set("Profile-Web-Page-Url", profileWebPageUrl)
|
||||||
|
if announceText != "" {
|
||||||
|
c.Writer.Header().Set("Announce", announceText)
|
||||||
|
}
|
||||||
|
|
||||||
if a.subEncrypt {
|
if a.subEncrypt {
|
||||||
c.String(200, base64.StdEncoding.EncodeToString([]byte(result)))
|
c.String(200, base64.StdEncoding.EncodeToString([]byte(result)))
|
||||||
|
@ -115,6 +138,23 @@ func (a *SUBController) subJsons(c *gin.Context) {
|
||||||
host = c.Request.Host
|
host = c.Request.Host
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
var profileTitle string
|
||||||
|
profileTitle = os.Getenv("XUI_SUB_PROFILE_TITLE")
|
||||||
|
if profileTitle == "" {
|
||||||
|
profileTitle = subId
|
||||||
|
}
|
||||||
|
var supportUrl string
|
||||||
|
supportUrl = os.Getenv("XUI_SUB_PROFILE_TITLE")
|
||||||
|
if supportUrl == "" {
|
||||||
|
supportUrl = os.Getenv("XUI_SUB_DOMAIN")
|
||||||
|
}
|
||||||
|
var profileWebPageUrl string
|
||||||
|
profileWebPageUrl = os.Getenv("XUI_SUB_PROFILE_WEB_PAGE_URL")
|
||||||
|
if profileWebPageUrl == "" {
|
||||||
|
profileWebPageUrl = os.Getenv("XUI_SUB_DOMAIN")
|
||||||
|
}
|
||||||
|
var announceText string
|
||||||
|
announceText = getAnnounceText()
|
||||||
jsonSub, header, err := a.subJsonService.GetJson(subId, host)
|
jsonSub, header, err := a.subJsonService.GetJson(subId, host)
|
||||||
if err != nil || len(jsonSub) == 0 {
|
if err != nil || len(jsonSub) == 0 {
|
||||||
c.String(400, "Error!")
|
c.String(400, "Error!")
|
||||||
|
@ -123,12 +163,32 @@ func (a *SUBController) subJsons(c *gin.Context) {
|
||||||
// Add headers
|
// Add headers
|
||||||
c.Writer.Header().Set("Subscription-Userinfo", header)
|
c.Writer.Header().Set("Subscription-Userinfo", header)
|
||||||
c.Writer.Header().Set("Profile-Update-Interval", a.updateInterval)
|
c.Writer.Header().Set("Profile-Update-Interval", a.updateInterval)
|
||||||
c.Writer.Header().Set("Profile-Title", subId)
|
c.Writer.Header().Set("Profile-Title", profileTitle)
|
||||||
|
c.Writer.Header().Set("Support-Url", supportUrl)
|
||||||
|
c.Writer.Header().Set("Profile-Web-Page-Url", profileWebPageUrl)
|
||||||
|
if announceText != "" {
|
||||||
|
c.Writer.Header().Set("Announce", announceText)
|
||||||
|
}
|
||||||
|
|
||||||
c.String(200, jsonSub)
|
c.String(200, jsonSub)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getAnnounceText() (string) {
|
||||||
|
announceFilePath := "/etc/x-ui/announce.txt"
|
||||||
|
_, err := os.Stat(announceFilePath)
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
content, err := ioutil.ReadFile(announceFilePath)
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
return string(content)
|
||||||
|
}
|
||||||
|
|
||||||
func getHostFromXFH(s string) (string, error) {
|
func getHostFromXFH(s string) (string, error) {
|
||||||
if strings.Contains(s, ":") {
|
if strings.Contains(s, ":") {
|
||||||
realHost, _, err := net.SplitHostPort(s)
|
realHost, _, err := net.SplitHostPort(s)
|
||||||
|
|
23
x-ui.sh
Normal file → Executable file
23
x-ui.sh
Normal file → Executable file
|
@ -18,9 +18,6 @@ function LOGI() {
|
||||||
echo -e "${green}[INF] $* ${plain}"
|
echo -e "${green}[INF] $* ${plain}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# check root
|
|
||||||
[[ $EUID -ne 0 ]] && LOGE "ERROR: You must be root to run this script! \n" && exit 1
|
|
||||||
|
|
||||||
# Check OS and set release variable
|
# Check OS and set release variable
|
||||||
if [[ -f /etc/os-release ]]; then
|
if [[ -f /etc/os-release ]]; then
|
||||||
source /etc/os-release
|
source /etc/os-release
|
||||||
|
@ -28,6 +25,8 @@ if [[ -f /etc/os-release ]]; then
|
||||||
elif [[ -f /usr/lib/os-release ]]; then
|
elif [[ -f /usr/lib/os-release ]]; then
|
||||||
source /usr/lib/os-release
|
source /usr/lib/os-release
|
||||||
release=$ID
|
release=$ID
|
||||||
|
elif command -v sw_vers &> /dev/null; then
|
||||||
|
release="macos"
|
||||||
else
|
else
|
||||||
echo "Failed to check the system OS, please contact the author!" >&2
|
echo "Failed to check the system OS, please contact the author!" >&2
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -36,7 +35,11 @@ fi
|
||||||
echo "The OS release is: $release"
|
echo "The OS release is: $release"
|
||||||
|
|
||||||
os_version=""
|
os_version=""
|
||||||
os_version=$(grep "^VERSION_ID" /etc/os-release | cut -d '=' -f2 | tr -d '"' | tr -d '.')
|
if [[ "${release}" != "macos" ]]; then
|
||||||
|
os_version=$(grep "^VERSION_ID" /etc/os-release | cut -d '=' -f2 | tr -d '"' | tr -d '.')
|
||||||
|
# check root
|
||||||
|
[[ $EUID -ne 0 ]] && LOGE "ERROR: You must be root to run this script! \n" && exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ "${release}" == "arch" ]]; then
|
if [[ "${release}" == "arch" ]]; then
|
||||||
echo "Your OS is Arch Linux"
|
echo "Your OS is Arch Linux"
|
||||||
|
@ -86,6 +89,8 @@ elif [[ "${release}" == "ol" ]]; then
|
||||||
if [[ ${os_version} -lt 8 ]]; then
|
if [[ ${os_version} -lt 8 ]]; then
|
||||||
echo -e "${red} Please use Oracle Linux 8 or higher ${plain}\n" && exit 1
|
echo -e "${red} Please use Oracle Linux 8 or higher ${plain}\n" && exit 1
|
||||||
fi
|
fi
|
||||||
|
elif [[ "${release}" == "macos" ]]; then
|
||||||
|
echo "Your OS is MacOS"
|
||||||
else
|
else
|
||||||
echo -e "${red}Your operating system is not supported by this script.${plain}\n"
|
echo -e "${red}Your operating system is not supported by this script.${plain}\n"
|
||||||
echo "Please ensure you are using one of the following supported operating systems:"
|
echo "Please ensure you are using one of the following supported operating systems:"
|
||||||
|
@ -103,6 +108,7 @@ else
|
||||||
echo "- Oracle Linux 8+"
|
echo "- Oracle Linux 8+"
|
||||||
echo "- OpenSUSE Tumbleweed"
|
echo "- OpenSUSE Tumbleweed"
|
||||||
echo "- Amazon Linux 2023"
|
echo "- Amazon Linux 2023"
|
||||||
|
echo "- MacOS (build only)"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -1277,6 +1283,11 @@ run_speedtest() {
|
||||||
speedtest
|
speedtest
|
||||||
}
|
}
|
||||||
|
|
||||||
|
build_image_tar() {
|
||||||
|
docker compose version;
|
||||||
|
docker compose --progress plain build --no-cache && docker save -o 3x-ui.tar 3x-ui:latest && echo "Image saved: 3x-ui.tar";
|
||||||
|
}
|
||||||
|
|
||||||
create_iplimit_jails() {
|
create_iplimit_jails() {
|
||||||
# Use default bantime if not passed => 15 minutes
|
# Use default bantime if not passed => 15 minutes
|
||||||
local bantime="${1:-15}"
|
local bantime="${1:-15}"
|
||||||
|
@ -1684,6 +1695,7 @@ show_menu() {
|
||||||
${green}23.${plain} Enable BBR
|
${green}23.${plain} Enable BBR
|
||||||
${green}24.${plain} Update Geo Files
|
${green}24.${plain} Update Geo Files
|
||||||
${green}25.${plain} Speedtest by Ookla
|
${green}25.${plain} Speedtest by Ookla
|
||||||
|
${green}99.${plain} Build Docker Image (tar archive)
|
||||||
"
|
"
|
||||||
show_status
|
show_status
|
||||||
echo && read -p "Please enter your selection [0-25]: " num
|
echo && read -p "Please enter your selection [0-25]: " num
|
||||||
|
@ -1767,6 +1779,9 @@ show_menu() {
|
||||||
25)
|
25)
|
||||||
run_speedtest
|
run_speedtest
|
||||||
;;
|
;;
|
||||||
|
99)
|
||||||
|
build_image_tar
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
LOGE "Please enter the correct number [0-25]"
|
LOGE "Please enter the correct number [0-25]"
|
||||||
;;
|
;;
|
||||||
|
|
Loading…
Reference in a new issue