Compare commits

..

No commits in common. "3b262cf180bb206dd84c83bd19536e9c2cf2fe9a" and "4c7249c451bdf0b6fa78f450468b686ca70b5440" have entirely different histories.

25 changed files with 180 additions and 444 deletions

View file

@ -1,9 +1,7 @@
name: Release 3X-UI for Docker name: Release 3X-UI for Docker
permissions: permissions:
contents: read contents: read
packages: write packages: write
on: on:
workflow_dispatch: workflow_dispatch:
push: push:
@ -15,48 +13,48 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v5
with: with:
submodules: true submodules: true
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
hsanaeii/3x-ui
ghcr.io/mhsanaei/3x-ui
tags: |
type=ref,event=branch
type=ref,event=tag
type=pep440,pattern={{version}}
- name: Docker meta - name: Set up QEMU
id: meta uses: docker/setup-qemu-action@v3
uses: docker/metadata-action@v5
with:
images: |
hsanaeii/3x-ui
ghcr.io/mhsanaei/3x-ui
tags: |
type=ref,event=branch
type=ref,event=tag
type=semver,pattern={{version}}
- name: Set up QEMU - name: Set up Docker Buildx
uses: docker/setup-qemu-action@v3 uses: docker/setup-buildx-action@v3
with:
install: true
- name: Set up Docker Buildx - name: Login to Docker Hub
uses: docker/setup-buildx-action@v3 uses: docker/login-action@v3
with: with:
install: true username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}
- name: Login to Docker Hub - name: Login to GHCR
uses: docker/login-action@v3 uses: docker/login-action@v3
with: with:
username: ${{ secrets.DOCKER_HUB_USERNAME }} registry: ghcr.io
password: ${{ secrets.DOCKER_HUB_TOKEN }} username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to GHCR - name: Build and push Docker image
uses: docker/login-action@v3 uses: docker/build-push-action@v6
with: with:
registry: ghcr.io context: .
username: ${{ github.actor }} push: true
password: ${{ secrets.GITHUB_TOKEN }} platforms: linux/amd64, linux/arm64/v8, linux/arm/v7, linux/arm/v6, linux/386
tags: ${{ steps.meta.outputs.tags }}
- name: Build and push Docker image labels: ${{ steps.meta.outputs.labels }}
uses: docker/build-push-action@v6
with:
context: .
push: true
platforms: linux/amd64,linux/arm64/v8,linux/arm/v7,linux/arm/v6,linux/386
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

View file

@ -1 +1 @@
2.8.4 2.8.3

2
go.mod
View file

@ -96,7 +96,7 @@ require (
golang.org/x/tools v0.37.0 // indirect golang.org/x/tools v0.37.0 // indirect
golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2 // indirect golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2 // indirect
golang.zx2c4.com/wireguard v0.0.0-20250521234502-f333402bd9cb // indirect golang.zx2c4.com/wireguard v0.0.0-20250521234502-f333402bd9cb // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250922171735-9219d122eba9 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20250908214217-97024824d090 // indirect
google.golang.org/protobuf v1.36.9 // indirect google.golang.org/protobuf v1.36.9 // indirect
gvisor.dev/gvisor v0.0.0-20250503011706-39ed1f5ac29c // indirect gvisor.dev/gvisor v0.0.0-20250503011706-39ed1f5ac29c // indirect
lukechampine.com/blake3 v1.4.1 // indirect lukechampine.com/blake3 v1.4.1 // indirect

2
go.sum
View file

@ -236,8 +236,6 @@ gonum.org/v1/gonum v0.16.0 h1:5+ul4Swaf3ESvrOnidPp4GZbzf0mxVQpDCYUQE7OJfk=
gonum.org/v1/gonum v0.16.0/go.mod h1:fef3am4MQ93R2HHpKnLk4/Tbh/s0+wqD5nfa6Pnwy4E= gonum.org/v1/gonum v0.16.0/go.mod h1:fef3am4MQ93R2HHpKnLk4/Tbh/s0+wqD5nfa6Pnwy4E=
google.golang.org/genproto/googleapis/rpc v0.0.0-20250908214217-97024824d090 h1:/OQuEa4YWtDt7uQWHd3q3sUMb+QOLQUg1xa8CEsRv5w= google.golang.org/genproto/googleapis/rpc v0.0.0-20250908214217-97024824d090 h1:/OQuEa4YWtDt7uQWHd3q3sUMb+QOLQUg1xa8CEsRv5w=
google.golang.org/genproto/googleapis/rpc v0.0.0-20250908214217-97024824d090/go.mod h1:GmFNa4BdJZ2a8G+wCe9Bg3wwThLrJun751XstdJt5Og= google.golang.org/genproto/googleapis/rpc v0.0.0-20250908214217-97024824d090/go.mod h1:GmFNa4BdJZ2a8G+wCe9Bg3wwThLrJun751XstdJt5Og=
google.golang.org/genproto/googleapis/rpc v0.0.0-20250922171735-9219d122eba9 h1:V1jCN2HBa8sySkR5vLcCSqJSTMv093Rw9EJefhQGP7M=
google.golang.org/genproto/googleapis/rpc v0.0.0-20250922171735-9219d122eba9/go.mod h1:HSkG/KdJWusxU1F6CNrwNDjBMgisKxGnc5dAZfT0mjQ=
google.golang.org/grpc v1.75.1 h1:/ODCNEuf9VghjgO3rqLcfg8fiOP0nSluljWFlDxELLI= google.golang.org/grpc v1.75.1 h1:/ODCNEuf9VghjgO3rqLcfg8fiOP0nSluljWFlDxELLI=
google.golang.org/grpc v1.75.1/go.mod h1:JtPAzKiq4v1xcAB2hydNlWI2RnF85XXcV0mhKXr2ecQ= google.golang.org/grpc v1.75.1/go.mod h1:JtPAzKiq4v1xcAB2hydNlWI2RnF85XXcV0mhKXr2ecQ=
google.golang.org/protobuf v1.36.9 h1:w2gp2mA27hUeUzj9Ex9FBjsBm40zfaDtEWow293U7Iw= google.golang.org/protobuf v1.36.9 h1:w2gp2mA27hUeUzj9Ex9FBjsBm40zfaDtEWow293U7Iw=

View file

@ -56,9 +56,6 @@ install_base() {
opensuse-tumbleweed) opensuse-tumbleweed)
zypper refresh && zypper -q install -y wget curl tar timezone zypper refresh && zypper -q install -y wget curl tar timezone
;; ;;
alpine)
apk update && apk add wget curl tar tzdata
;;
*) *)
apt-get update && apt-get install -y -q wget curl tar tzdata apt-get update && apt-get install -y -q wget curl tar tzdata
;; ;;
@ -187,11 +184,7 @@ install_x-ui() {
# Stop x-ui service and remove old resources # Stop x-ui service and remove old resources
if [[ -e /usr/local/x-ui/ ]]; then if [[ -e /usr/local/x-ui/ ]]; then
if [[ $release == "alpine" ]]; then systemctl stop x-ui
rc-service x-ui stop
else
systemctl stop x-ui
fi
rm /usr/local/x-ui/ -rf rm /usr/local/x-ui/ -rf
fi fi
@ -215,18 +208,10 @@ install_x-ui() {
chmod +x /usr/bin/x-ui chmod +x /usr/bin/x-ui
config_after_install config_after_install
if [[ $release == "alpine" ]]; then cp -f x-ui.service /etc/systemd/system/
wget -O /etc/init.d/x-ui https://raw.githubusercontent.com/MHSanaei/3x-ui/main/x-ui.rc systemctl daemon-reload
chmod +x /etc/init.d/x-ui systemctl enable x-ui
rc-update add x-ui systemctl start x-ui
rc-service x-ui start
else
cp -f x-ui.service /etc/systemd/system/
systemctl daemon-reload
systemctl enable x-ui
systemctl start x-ui
fi
echo -e "${green}x-ui ${tag_version}${plain} installation finished, it is running now..." echo -e "${green}x-ui ${tag_version}${plain} installation finished, it is running now..."
echo -e "" echo -e ""
echo -e "┌───────────────────────────────────────────────────────┐ echo -e "┌───────────────────────────────────────────────────────┐

View file

@ -98,14 +98,8 @@ func (s *Server) initRouter() (*gin.Engine, error) {
} }
// Set base_path based on LinksPath for template rendering // Set base_path based on LinksPath for template rendering
// Ensure LinksPath ends with "/" for proper asset URL generation
basePath := LinksPath
if basePath != "/" && !strings.HasSuffix(basePath, "/") {
basePath += "/"
}
logger.Debug("sub: Setting base_path to:", basePath)
engine.Use(func(c *gin.Context) { engine.Use(func(c *gin.Context) {
c.Set("base_path", basePath) c.Set("base_path", LinksPath)
}) })
Encrypt, err := s.settingService.GetSubEncrypt() Encrypt, err := s.settingService.GetSubEncrypt()
@ -185,48 +179,22 @@ func (s *Server) initRouter() (*gin.Engine, error) {
linksPathForAssets = strings.TrimRight(LinksPath, "/") + "/assets" linksPathForAssets = strings.TrimRight(LinksPath, "/") + "/assets"
} }
// Mount assets in multiple paths to handle different URL patterns
var assetsFS http.FileSystem
if _, err := os.Stat("web/assets"); err == nil { if _, err := os.Stat("web/assets"); err == nil {
assetsFS = http.FS(os.DirFS("web/assets")) engine.StaticFS("/assets", http.FS(os.DirFS("web/assets")))
if linksPathForAssets != "/assets" {
engine.StaticFS(linksPathForAssets, http.FS(os.DirFS("web/assets")))
}
} else { } else {
if subFS, err := fs.Sub(webpkg.EmbeddedAssets(), "assets"); err == nil { if subFS, err := fs.Sub(webpkg.EmbeddedAssets(), "assets"); err == nil {
assetsFS = http.FS(subFS) engine.StaticFS("/assets", http.FS(subFS))
if linksPathForAssets != "/assets" {
engine.StaticFS(linksPathForAssets, http.FS(subFS))
}
} else { } else {
logger.Error("sub: failed to mount embedded assets:", err) logger.Error("sub: failed to mount embedded assets:", err)
} }
} }
if assetsFS != nil {
engine.StaticFS("/assets", assetsFS)
if linksPathForAssets != "/assets" {
engine.StaticFS(linksPathForAssets, assetsFS)
}
// Add middleware to handle dynamic asset paths with subid
if LinksPath != "/" {
engine.Use(func(c *gin.Context) {
path := c.Request.URL.Path
// Check if this is an asset request with subid pattern: /sub/path/{subid}/assets/...
pathPrefix := strings.TrimRight(LinksPath, "/") + "/"
if strings.HasPrefix(path, pathPrefix) && strings.Contains(path, "/assets/") {
// Extract the asset path after /assets/
assetsIndex := strings.Index(path, "/assets/")
if assetsIndex != -1 {
assetPath := path[assetsIndex+8:] // +8 to skip "/assets/"
if assetPath != "" {
// Serve the asset file
c.FileFromFS(assetPath, assetsFS)
c.Abort()
return
}
}
}
c.Next()
})
}
}
g := engine.Group("/") g := engine.Group("/")
s.sub = NewSUBController( s.sub = NewSUBController(

View file

@ -87,20 +87,7 @@ func (a *SUBController) subs(c *gin.Context) {
if !a.jsonEnabled { if !a.jsonEnabled {
subJsonURL = "" subJsonURL = ""
} }
// Get base_path from context (set by middleware) page := a.subService.BuildPageData(subId, hostHeader, traffic, lastOnline, subs, subURL, subJsonURL)
basePath, exists := c.Get("base_path")
if !exists {
basePath = "/"
}
// Add subId to base_path for asset URLs
basePathStr := basePath.(string)
if basePathStr == "/" {
basePathStr = "/" + subId + "/"
} else {
// Remove trailing slash if exists, add subId, then add trailing slash
basePathStr = strings.TrimRight(basePathStr, "/") + "/" + subId + "/"
}
page := a.subService.BuildPageData(subId, hostHeader, traffic, lastOnline, subs, subURL, subJsonURL, basePathStr)
c.HTML(200, "subpage.html", gin.H{ c.HTML(200, "subpage.html", gin.H{
"title": "subscription.title", "title": "subscription.title",
"cur_ver": config.GetVersion(), "cur_ver": config.GetVersion(),

View file

@ -1169,7 +1169,7 @@ func (s *SubService) joinPathWithID(basePath, subId string) string {
// BuildPageData parses header and prepares the template view model. // BuildPageData parses header and prepares the template view model.
// BuildPageData constructs page data for rendering the subscription information page. // BuildPageData constructs page data for rendering the subscription information page.
func (s *SubService) BuildPageData(subId string, hostHeader string, traffic xray.ClientTraffic, lastOnline int64, subs []string, subURL, subJsonURL string, basePath string) PageData { func (s *SubService) BuildPageData(subId string, hostHeader string, traffic xray.ClientTraffic, lastOnline int64, subs []string, subURL, subJsonURL string) PageData {
download := common.FormatTraffic(traffic.Down) download := common.FormatTraffic(traffic.Down)
upload := common.FormatTraffic(traffic.Up) upload := common.FormatTraffic(traffic.Up)
total := "∞" total := "∞"
@ -1188,7 +1188,7 @@ func (s *SubService) BuildPageData(subId string, hostHeader string, traffic xray
return PageData{ return PageData{
Host: hostHeader, Host: hostHeader,
BasePath: basePath, BasePath: "/", // kept as "/"; templates now use context base_path injected from router
SId: subId, SId: subId,
Download: download, Download: download,
Upload: upload, Upload: upload,

View file

@ -142,10 +142,7 @@
}, },
npvtunUrl() { npvtunUrl() {
return this.app.subUrl; return this.app.subUrl;
}, }
happUrl() {
return `happ://add/${encodeURIComponent(this.app.subUrl)}`;
}
}, },
methods: { methods: {
renderLink, renderLink,

View file

@ -1,10 +1,7 @@
package controller package controller
import ( import (
"net/http"
"github.com/mhsanaei/3x-ui/v2/web/service" "github.com/mhsanaei/3x-ui/v2/web/service"
"github.com/mhsanaei/3x-ui/v2/web/session"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
@ -24,21 +21,11 @@ func NewAPIController(g *gin.RouterGroup) *APIController {
return a return a
} }
// checkAPIAuth is a middleware that returns 404 for unauthenticated API requests
// to hide the existence of API endpoints from unauthorized users
func (a *APIController) checkAPIAuth(c *gin.Context) {
if !session.IsLogin(c) {
c.AbortWithStatus(http.StatusNotFound)
return
}
c.Next()
}
// initRouter sets up the API routes for inbounds, server, and other endpoints. // initRouter sets up the API routes for inbounds, server, and other endpoints.
func (a *APIController) initRouter(g *gin.RouterGroup) { func (a *APIController) initRouter(g *gin.RouterGroup) {
// Main API group // Main API group
api := g.Group("/panel/api") api := g.Group("/panel/api")
api.Use(a.checkAPIAuth) api.Use(a.checkLogin)
// Inbounds API // Inbounds API
inbounds := api.Group("/inbounds") inbounds := api.Group("/inbounds")

View file

@ -39,9 +39,8 @@ func NewIndexController(g *gin.RouterGroup) *IndexController {
// initRouter sets up the routes for index, login, logout, and two-factor authentication. // initRouter sets up the routes for index, login, logout, and two-factor authentication.
func (a *IndexController) initRouter(g *gin.RouterGroup) { func (a *IndexController) initRouter(g *gin.RouterGroup) {
g.GET("/", a.index) g.GET("/", a.index)
g.GET("/logout", a.logout)
g.POST("/login", a.login) g.POST("/login", a.login)
g.GET("/logout", a.logout)
g.POST("/getTwoFactorEnable", a.getTwoFactorEnable) g.POST("/getTwoFactorEnable", a.getTwoFactorEnable)
} }

View file

@ -8,6 +8,8 @@ import (
type XUIController struct { type XUIController struct {
BaseController BaseController
inboundController *InboundController
serverController *ServerController
settingController *SettingController settingController *SettingController
xraySettingController *XraySettingController xraySettingController *XraySettingController
} }
@ -30,6 +32,8 @@ func (a *XUIController) initRouter(g *gin.RouterGroup) {
g.GET("/settings", a.settings) g.GET("/settings", a.settings)
g.GET("/xray", a.xraySettings) g.GET("/xray", a.xraySettings)
a.inboundController = NewInboundController(g)
a.serverController = NewServerController(g)
a.settingController = NewSettingController(g) a.settingController = NewSettingController(g)
a.xraySettingController = NewXraySettingController(g) a.xraySettingController = NewXraySettingController(g)
} }

View file

@ -28,7 +28,7 @@
</a-form-item> </a-form-item>
<a-form-item label='{{ i18n "pages.inbounds.port" }}'> <a-form-item label='{{ i18n "pages.inbounds.port" }}'>
<a-input-number v-model.number="inbound.port" :min="1" :max="65535"></a-input-number> <a-input-number v-model.number="inbound.port" :min="1" :max="65531"></a-input-number>
</a-form-item> </a-form-item>
<a-form-item> <a-form-item>
@ -51,9 +51,8 @@
<span>{{ i18n "pages.inbounds.periodicTrafficResetDesc" }}</span> <span>{{ i18n "pages.inbounds.periodicTrafficResetDesc" }}</span>
<br v-if="dbInbound.lastTrafficResetTime && dbInbound.lastTrafficResetTime > 0"> <br v-if="dbInbound.lastTrafficResetTime && dbInbound.lastTrafficResetTime > 0">
<span v-if="dbInbound.lastTrafficResetTime && dbInbound.lastTrafficResetTime > 0"> <span v-if="dbInbound.lastTrafficResetTime && dbInbound.lastTrafficResetTime > 0">
<strong>{{ i18n "pages.inbounds.lastReset" }}:</strong> <strong>{{ i18n "pages.inbounds.lastReset" }}:</strong>
<span v-if="datepicker == 'gregorian'">[[ <span v-if="datepicker == 'gregorian'">[[ moment(dbInbound.lastTrafficResetTime).format('YYYY-MM-DD HH:mm:ss') ]]</span>
moment(dbInbound.lastTrafficResetTime).format('YYYY-MM-DD HH:mm:ss') ]]</span>
<span v-else>[[ DateUtil.convertToJalalian(moment(dbInbound.lastTrafficResetTime)) ]]</span> <span v-else>[[ DateUtil.convertToJalalian(moment(dbInbound.lastTrafficResetTime)) ]]</span>
</span> </span>
</template> </template>
@ -146,4 +145,4 @@
</a-collapse-panel> </a-collapse-panel>
</a-collapse> </a-collapse>
{{end}} {{end}}

View file

@ -3,14 +3,12 @@
<a-divider :style="{ margin: '5px 0 0' }"></a-divider> <a-divider :style="{ margin: '5px 0 0' }"></a-divider>
<a-form-item label="External Proxy"> <a-form-item label="External Proxy">
<a-switch v-model="externalProxy"></a-switch> <a-switch v-model="externalProxy"></a-switch>
<a-button icon="plus" v-if="externalProxy" type="primary" :style="{ marginLeft: '10px' }" size="small" <a-button icon="plus" v-if="externalProxy" type="primary" :style="{ marginLeft: '10px' }" size="small" @click="inbound.stream.externalProxy.push({forceTls: 'same', dest: '', port: 443, remark: ''})"></a-button>
@click="inbound.stream.externalProxy.push({forceTls: 'same', dest: '', port: 443, remark: ''})"></a-button>
</a-form-item> </a-form-item>
<a-input-group :style="{ margin: '8px 0' }" compact v-for="(row, index) in inbound.stream.externalProxy"> <a-input-group :style="{ margin: '8px 0' }" compact v-for="(row, index) in inbound.stream.externalProxy">
<template> <template>
<a-tooltip title="Force TLS"> <a-tooltip title="Force TLS">
<a-select v-model="row.forceTls" :style="{ width: '20%', margin: '0px' }" <a-select v-model="row.forceTls" :style="{ width: '20%', margin: '0px' }" :dropdown-class-name="themeSwitcher.currentTheme">
:dropdown-class-name="themeSwitcher.currentTheme">
<a-select-option value="same">{{ i18n "pages.inbounds.same" }}</a-select-option> <a-select-option value="same">{{ i18n "pages.inbounds.same" }}</a-select-option>
<a-select-option value="none">{{ i18n "none" }}</a-select-option> <a-select-option value="none">{{ i18n "none" }}</a-select-option>
<a-select-option value="tls">TLS</a-select-option> <a-select-option value="tls">TLS</a-select-option>
@ -19,7 +17,7 @@
</template> </template>
<a-input :style="{ width: '30%' }" v-model.trim="row.dest" placeholder='{{ i18n "host" }}'></a-input> <a-input :style="{ width: '30%' }" v-model.trim="row.dest" placeholder='{{ i18n "host" }}'></a-input>
<a-tooltip title='{{ i18n "pages.inbounds.port" }}'> <a-tooltip title='{{ i18n "pages.inbounds.port" }}'>
<a-input-number :style="{ width: '15%' }" v-model.number="row.port" min="1" max="65535"></a-input-number> <a-input-number :style="{ width: '15%' }" v-model.number="row.port" min="1" max="65531"></a-input-number>
</a-tooltip> </a-tooltip>
<a-input :style="{ width: '30%', top: '0' }" v-model.trim="row.remark" placeholder='{{ i18n "remark" }}'> <a-input :style="{ width: '30%', top: '0' }" v-model.trim="row.remark" placeholder='{{ i18n "remark" }}'>
<template slot="addonAfter"> <template slot="addonAfter">
@ -28,4 +26,4 @@
</a-input> </a-input>
</a-input-group> </a-input-group>
</a-form> </a-form>
{{end}} {{end}}

View file

@ -4,7 +4,7 @@
{{ template "page/body_start" .}} {{ template "page/body_start" .}}
<a-layout id="app" v-cloak :class="themeSwitcher.currentTheme + ' login-app'"> <a-layout id="app" v-cloak :class="themeSwitcher.currentTheme + ' login-app'">
<transition name="list" appear> <transition name="list" appear>
<a-layout-content class="under min-h-0"> <a-layout-content class="under min-h-0">
<div class="waves-header"> <div class="waves-header">
<div class="waves-inner-header"></div> <div class="waves-inner-header"></div>
<svg class="waves" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" <svg class="waves" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
@ -20,7 +20,7 @@
</g> </g>
</svg> </svg>
</div> </div>
<a-row type="flex" justify="center" align="middle" class="h-100 overflow-y-auto overflow-x-hidden"> <a-row type="flex" justify="center" align="middle" class="h-100 overflow-y-auto overflow-x-hidden">
<a-col :xs="22" :sm="12" :md="10" :lg="8" :xl="6" :xxl="5" id="login" class="my-3rem"> <a-col :xs="22" :sm="12" :md="10" :lg="8" :xl="6" :xxl="5" id="login" class="my-3rem">
<template v-if="!loadingStates.fetched"> <template v-if="!loadingStates.fetched">
<div class="text-center"> <div class="text-center">
@ -35,8 +35,8 @@
<a-space direction="vertical" :size="10"> <a-space direction="vertical" :size="10">
<a-theme-switch-login></a-theme-switch-login> <a-theme-switch-login></a-theme-switch-login>
<span>{{ i18n "pages.settings.language" }}</span> <span>{{ i18n "pages.settings.language" }}</span>
<a-select ref="selectLang" class="w-100" v-model="lang" @change="LanguageManager.setLanguage(lang)" <a-select ref="selectLang" class="w-100" v-model="lang"
:dropdown-class-name="themeSwitcher.currentTheme"> @change="LanguageManager.setLanguage(lang)" :dropdown-class-name="themeSwitcher.currentTheme">
<a-select-option :value="l.value" label="English" v-for="l in LanguageManager.supportedLanguages"> <a-select-option :value="l.value" label="English" v-for="l in LanguageManager.supportedLanguages">
<span role="img" aria-label="l.name" v-text="l.icon"></span> <span role="img" aria-label="l.name" v-text="l.icon"></span>
&nbsp;&nbsp;<span v-text="l.name"></span> &nbsp;&nbsp;<span v-text="l.name"></span>
@ -68,7 +68,7 @@
</a-input> </a-input>
</a-form-item> </a-form-item>
<a-form-item> <a-form-item>
<a-input-password autocomplete="current-password" name="password" v-model.trim="user.password" <a-input-password autocomplete="password" name="password" v-model.trim="user.password"
placeholder='{{ i18n "password" }}' required> placeholder='{{ i18n "password" }}' required>
<a-icon slot="prefix" type="lock" class="fs-1rem"></a-icon> <a-icon slot="prefix" type="lock" class="fs-1rem"></a-icon>
</a-input-password> </a-input-password>
@ -81,8 +81,7 @@
</a-form-item> </a-form-item>
<a-form-item> <a-form-item>
<a-row justify="center" class="centered"> <a-row justify="center" class="centered">
<div class="wave-btn-bg wave-btn-bg-cl h-50px mt-1rem" <div class="wave-btn-bg wave-btn-bg-cl h-50px mt-1rem" :style="loadingStates.spinning ? 'width: 52px' : 'display: inline-block'">
:style="loadingStates.spinning ? 'width: 52px' : 'display: inline-block'">
<a-button class="ant-btn-primary-login" type="primary" :loading="loadingStates.spinning" <a-button class="ant-btn-primary-login" type="primary" :loading="loadingStates.spinning"
:icon="loadingStates.spinning ? 'poweroff' : undefined" html-type="submit"> :icon="loadingStates.spinning ? 'poweroff' : undefined" html-type="submit">
[[ loadingStates.spinning ? '' : '{{ i18n "login" }}' ]] [[ loadingStates.spinning ? '' : '{{ i18n "login" }}' ]]

View file

@ -7,13 +7,12 @@
<a-input v-model.trim="dnsModal.dnsServer.address"></a-input> <a-input v-model.trim="dnsModal.dnsServer.address"></a-input>
</a-form-item> </a-form-item>
<a-form-item label='{{ i18n "pages.inbounds.port" }}'> <a-form-item label='{{ i18n "pages.inbounds.port" }}'>
<a-input-number v-model.number="dnsModal.dnsServer.port" :min="1" :max="65535"></a-input-number> <a-input-number v-model.number="dnsModal.dnsServer.port" :min="1" :max="65531"></a-input-number>
</a-form-item> </a-form-item>
<a-form-item label='{{ i18n "pages.xray.dns.strategy" }}'> <a-form-item label='{{ i18n "pages.xray.dns.strategy" }}'>
<a-select v-model="dnsModal.dnsServer.queryStrategy" :style="{ width: '100%' }" <a-select v-model="dnsModal.dnsServer.queryStrategy" :style="{ width: '100%' }"
:dropdown-class-name="themeSwitcher.currentTheme"> :dropdown-class-name="themeSwitcher.currentTheme">
<a-select-option :value="l" :label="l" v-for="l in ['UseSystem', 'UseIP', 'UseIPv4', 'UseIPv6']"> [[ l ]] <a-select-option :value="l" :label="l" v-for="l in ['UseSystem', 'UseIP', 'UseIPv4', 'UseIPv6']"> [[ l ]] </a-select-option>
</a-select-option>
</a-select> </a-select>
</a-form-item> </a-form-item>
<a-divider :style="{ margin: '5px 0' }"></a-divider> <a-divider :style="{ margin: '5px 0' }"></a-divider>
@ -76,7 +75,7 @@
isEdit: false, isEdit: false,
confirm: null, confirm: null,
dnsServer: { ...defaultDnsObject }, dnsServer: { ...defaultDnsObject },
ok() { ok() {
ObjectUtil.execute(dnsModal.confirm, { ...dnsModal.dnsServer }); ObjectUtil.execute(dnsModal.confirm, { ...dnsModal.dnsServer });
}, },
show({ show({
@ -107,7 +106,7 @@
} }
} else { } else {
this.dnsServer = { ...defaultDnsObject }; this.dnsServer = { ...defaultDnsObject };
this.dnsServer.domains = []; this.dnsServer.domains = [];
this.dnsServer.expectIPs = []; this.dnsServer.expectIPs = [];
this.dnsServer.unexpectedIPs = []; this.dnsServer.unexpectedIPs = [];

View file

@ -39,7 +39,7 @@
<template #title>{{ i18n "pages.settings.panelPort"}}</template> <template #title>{{ i18n "pages.settings.panelPort"}}</template>
<template #description>{{ i18n "pages.settings.panelPortDesc"}}</template> <template #description>{{ i18n "pages.settings.panelPortDesc"}}</template>
<template #control> <template #control>
<a-input-number :min="1" :min="65535" v-model="allSetting.webPort" :style="{ width: '100%' }"></a-input> <a-input-number :min="1" :min="65531" v-model="allSetting.webPort" :style="{ width: '100%' }"></a-input>
</template> </template>
</a-setting-list-item> </a-setting-list-item>
<a-setting-list-item paddings="small"> <a-setting-list-item paddings="small">
@ -137,8 +137,7 @@
<template #title>{{ i18n "pages.settings.datepicker"}}</template> <template #title>{{ i18n "pages.settings.datepicker"}}</template>
<template #description>{{ i18n "pages.settings.datepickerDescription"}}</template> <template #description>{{ i18n "pages.settings.datepickerDescription"}}</template>
<template #control> <template #control>
<a-select :style="{ width: '100%' }" :dropdown-class-name="themeSwitcher.currentTheme" <a-select :style="{ width: '100%' }" :dropdown-class-name="themeSwitcher.currentTheme" v-model="datepicker">
v-model="datepicker">
<a-select-option v-for="item in datepickerList" :value="item.value"> <a-select-option v-for="item in datepickerList" :value="item.value">
<span v-text="item.name"></span> <span v-text="item.name"></span>
</a-select-option> </a-select-option>

View file

@ -40,7 +40,7 @@
<template #title>{{ i18n "pages.settings.subPort"}}</template> <template #title>{{ i18n "pages.settings.subPort"}}</template>
<template #description>{{ i18n "pages.settings.subPortDesc"}}</template> <template #description>{{ i18n "pages.settings.subPortDesc"}}</template>
<template #control> <template #control>
<a-input-number v-model="allSetting.subPort" :min="1" :min="65535" <a-input-number v-model="allSetting.subPort" :min="1" :min="65531"
:style="{ width: '100%' }"></a-input-number> :style="{ width: '100%' }"></a-input-number>
</template> </template>
</a-setting-list-item> </a-setting-list-item>
@ -48,10 +48,13 @@
<template #title>{{ i18n "pages.settings.subPath"}}</template> <template #title>{{ i18n "pages.settings.subPath"}}</template>
<template #description>{{ i18n "pages.settings.subPathDesc"}}</template> <template #description>{{ i18n "pages.settings.subPathDesc"}}</template>
<template #control> <template #control>
<a-input type="text" v-model="allSetting.subPath" <a-input
type="text"
v-model="allSetting.subPath"
@input="allSetting.subPath = ((typeof $event === 'string' ? $event : ($event && $event.target ? $event.target.value : '')) || '').replace(/[:*]/g, '')" @input="allSetting.subPath = ((typeof $event === 'string' ? $event : ($event && $event.target ? $event.target.value : '')) || '').replace(/[:*]/g, '')"
@blur="allSetting.subPath = (p => { p = p || '/'; if (!p.startsWith('/')) p='/' + p; if (!p.endsWith('/')) p += '/'; return p.replace(/\/+/g,'/'); })(allSetting.subPath)" @blur="allSetting.subPath = (p => { p = p || '/'; if (!p.startsWith('/')) p='/' + p; if (!p.endsWith('/')) p += '/'; return p.replace(/\/+/g,'/'); })(allSetting.subPath)"
placeholder="/sub/"></a-input> placeholder="/sub/"
></a-input>
</template> </template>
</a-setting-list-item> </a-setting-list-item>
<a-setting-list-item paddings="small"> <a-setting-list-item paddings="small">
@ -105,4 +108,4 @@
</a-setting-list-item> </a-setting-list-item>
</a-collapse-panel> </a-collapse-panel>
</a-collapse> </a-collapse>
{{end}} {{end}}

View file

@ -218,8 +218,6 @@
<a-menu-item key="android-npvtunnel" <a-menu-item key="android-npvtunnel"
@click="copy(app.subUrl)">NPV @click="copy(app.subUrl)">NPV
Tunnel</a-menu-item> Tunnel</a-menu-item>
<a-menu-item key="android-happ"
@click="open('happ://add/' + encodeURIComponent(app.subUrl))">Happ</a-menu-item>
</a-menu> </a-menu>
</a-dropdown> </a-dropdown>
</a-col> </a-col>
@ -246,8 +244,6 @@
@click="copy(npvtunUrl)">NPV @click="copy(npvtunUrl)">NPV
Tunnel Tunnel
</a-menu-item> </a-menu-item>
<a-menu-item key="ios-happ"
@click="open(happUrl)">Happ</a-menu-item>
</a-menu> </a-menu>
</a-dropdown> </a-dropdown>
</a-col> </a-col>

View file

@ -12,14 +12,13 @@
<a-layout-content> <a-layout-content>
<a-spin :spinning="loadingStates.spinning" :delay="500" tip='{{ i18n "loading"}}'> <a-spin :spinning="loadingStates.spinning" :delay="500" tip='{{ i18n "loading"}}'>
<transition name="list" appear> <transition name="list" appear>
<a-alert type="error" v-if="showAlert && loadingStates.fetched" :style="{ marginBottom: '10px' }" <a-alert type="error" v-if="showAlert && loadingStates.fetched" :style="{ marginBottom: '10px' }" message='{{ i18n "secAlertTitle" }}'
message='{{ i18n "secAlertTitle" }}' color="red" description='{{ i18n "secAlertSsl" }}' show-icon closable> color="red" description='{{ i18n "secAlertSsl" }}' show-icon closable>
</a-alert> </a-alert>
</transition> </transition>
<transition name="list" appear> <transition name="list" appear>
<a-row v-if="!loadingStates.fetched"> <a-row v-if="!loadingStates.fetched">
<a-card <a-card :style="{ textAlign: 'center', padding: '30px 0', marginTop: '10px', background: 'transparent', border: 'none' }">
:style="{ textAlign: 'center', padding: '30px 0', marginTop: '10px', background: 'transparent', border: 'none' }">
<a-spin tip='{{ i18n "loading" }}'></a-spin> <a-spin tip='{{ i18n "loading" }}'></a-spin>
</a-card> </a-card>
</a-row> </a-row>
@ -38,8 +37,7 @@
<a-popover v-if="restartResult" :overlay-class-name="themeSwitcher.currentTheme"> <a-popover v-if="restartResult" :overlay-class-name="themeSwitcher.currentTheme">
<span slot="title">{{ i18n "pages.index.xrayErrorPopoverTitle" }}</span> <span slot="title">{{ i18n "pages.index.xrayErrorPopoverTitle" }}</span>
<template slot="content"> <template slot="content">
<span :style="{ maxWidth: '400px' }" v-for="line in restartResult.split('\n')">[[ line <span :style="{ maxWidth: '400px' }" v-for="line in restartResult.split('\n')">[[ line ]]</span>
]]</span>
</template> </template>
<a-icon type="question-circle"></a-icon> <a-icon type="question-circle"></a-icon>
</a-popover> </a-popover>
@ -539,7 +537,6 @@
serverObj = o.settings.vnext; serverObj = o.settings.vnext;
break; break;
case Protocols.VLESS: case Protocols.VLESS:
return [o.settings?.address + ':' + o.settings?.port];
case Protocols.HTTP: case Protocols.HTTP:
case Protocols.Socks: case Protocols.Socks:
case Protocols.Shadowsocks: case Protocols.Shadowsocks:

View file

@ -38,25 +38,6 @@ func (s *InboundService) GetInbounds(userId int) ([]*model.Inbound, error) {
if err != nil && err != gorm.ErrRecordNotFound { if err != nil && err != gorm.ErrRecordNotFound {
return nil, err return nil, err
} }
// Enrich client stats with UUID/SubId from inbound settings
for _, inbound := range inbounds {
clients, _ := s.GetClients(inbound)
if len(clients) == 0 || len(inbound.ClientStats) == 0 {
continue
}
// Build a map email -> client
cMap := make(map[string]model.Client, len(clients))
for _, c := range clients {
cMap[strings.ToLower(c.Email)] = c
}
for i := range inbound.ClientStats {
email := strings.ToLower(inbound.ClientStats[i].Email)
if c, ok := cMap[email]; ok {
inbound.ClientStats[i].UUID = c.ID
inbound.ClientStats[i].SubId = c.SubID
}
}
}
return inbounds, nil return inbounds, nil
} }
@ -69,24 +50,6 @@ func (s *InboundService) GetAllInbounds() ([]*model.Inbound, error) {
if err != nil && err != gorm.ErrRecordNotFound { if err != nil && err != gorm.ErrRecordNotFound {
return nil, err return nil, err
} }
// Enrich client stats with UUID/SubId from inbound settings
for _, inbound := range inbounds {
clients, _ := s.GetClients(inbound)
if len(clients) == 0 || len(inbound.ClientStats) == 0 {
continue
}
cMap := make(map[string]model.Client, len(clients))
for _, c := range clients {
cMap[strings.ToLower(c.Email)] = c
}
for i := range inbound.ClientStats {
email := strings.ToLower(inbound.ClientStats[i].Email)
if c, ok := cMap[email]; ok {
inbound.ClientStats[i].UUID = c.ID
inbound.ClientStats[i].SubId = c.SubID
}
}
}
return inbounds, nil return inbounds, nil
} }

View file

@ -46,22 +46,22 @@ var (
hashStorage *global.HashStorage hashStorage *global.HashStorage
// Performance improvements // Performance improvements
messageWorkerPool chan struct{} // Semaphore for limiting concurrent message processing messageWorkerPool chan struct{} // Semaphore for limiting concurrent message processing
optimizedHTTPClient *http.Client // HTTP client with connection pooling and timeouts optimizedHTTPClient *http.Client // HTTP client with connection pooling and timeouts
// Simple cache for frequently accessed data // Simple cache for frequently accessed data
statusCache struct { statusCache struct {
data *Status data *Status
timestamp time.Time timestamp time.Time
mutex sync.RWMutex mutex sync.RWMutex
} }
serverStatsCache struct { serverStatsCache struct {
data string data string
timestamp time.Time timestamp time.Time
mutex sync.RWMutex mutex sync.RWMutex
} }
// clients data to adding new client // clients data to adding new client
receiver_inbound_ID int receiver_inbound_ID int
client_Id string client_Id string
@ -122,7 +122,7 @@ func (t *Tgbot) GetHashStorage() *global.HashStorage {
func (t *Tgbot) getCachedStatus() (*Status, bool) { func (t *Tgbot) getCachedStatus() (*Status, bool) {
statusCache.mutex.RLock() statusCache.mutex.RLock()
defer statusCache.mutex.RUnlock() defer statusCache.mutex.RUnlock()
if statusCache.data != nil && time.Since(statusCache.timestamp) < 5*time.Second { if statusCache.data != nil && time.Since(statusCache.timestamp) < 5*time.Second {
return statusCache.data, true return statusCache.data, true
} }
@ -133,7 +133,7 @@ func (t *Tgbot) getCachedStatus() (*Status, bool) {
func (t *Tgbot) setCachedStatus(status *Status) { func (t *Tgbot) setCachedStatus(status *Status) {
statusCache.mutex.Lock() statusCache.mutex.Lock()
defer statusCache.mutex.Unlock() defer statusCache.mutex.Unlock()
statusCache.data = status statusCache.data = status
statusCache.timestamp = time.Now() statusCache.timestamp = time.Now()
} }
@ -142,7 +142,7 @@ func (t *Tgbot) setCachedStatus(status *Status) {
func (t *Tgbot) getCachedServerStats() (string, bool) { func (t *Tgbot) getCachedServerStats() (string, bool) {
serverStatsCache.mutex.RLock() serverStatsCache.mutex.RLock()
defer serverStatsCache.mutex.RUnlock() defer serverStatsCache.mutex.RUnlock()
if serverStatsCache.data != "" && time.Since(serverStatsCache.timestamp) < 10*time.Second { if serverStatsCache.data != "" && time.Since(serverStatsCache.timestamp) < 10*time.Second {
return serverStatsCache.data, true return serverStatsCache.data, true
} }
@ -153,7 +153,7 @@ func (t *Tgbot) getCachedServerStats() (string, bool) {
func (t *Tgbot) setCachedServerStats(stats string) { func (t *Tgbot) setCachedServerStats(stats string) {
serverStatsCache.mutex.Lock() serverStatsCache.mutex.Lock()
defer serverStatsCache.mutex.Unlock() defer serverStatsCache.mutex.Unlock()
serverStatsCache.data = stats serverStatsCache.data = stats
serverStatsCache.timestamp = time.Now() serverStatsCache.timestamp = time.Now()
} }
@ -171,7 +171,7 @@ func (t *Tgbot) Start(i18nFS embed.FS) error {
// Initialize worker pool for concurrent message processing (max 10 concurrent handlers) // Initialize worker pool for concurrent message processing (max 10 concurrent handlers)
messageWorkerPool = make(chan struct{}, 10) messageWorkerPool = make(chan struct{}, 10)
// Initialize optimized HTTP client with connection pooling // Initialize optimized HTTP client with connection pooling
optimizedHTTPClient = &http.Client{ optimizedHTTPClient = &http.Client{
Timeout: 15 * time.Second, Timeout: 15 * time.Second,
@ -359,9 +359,9 @@ func (t *Tgbot) OnReceive() {
botHandler.HandleMessage(func(ctx *th.Context, message telego.Message) error { botHandler.HandleMessage(func(ctx *th.Context, message telego.Message) error {
// Use goroutine with worker pool for concurrent command processing // Use goroutine with worker pool for concurrent command processing
go func() { go func() {
messageWorkerPool <- struct{}{} // Acquire worker messageWorkerPool <- struct{}{} // Acquire worker
defer func() { <-messageWorkerPool }() // Release worker defer func() { <-messageWorkerPool }() // Release worker
delete(userStates, message.Chat.ID) delete(userStates, message.Chat.ID)
t.answerCommand(&message, message.Chat.ID, checkAdmin(message.From.ID)) t.answerCommand(&message, message.Chat.ID, checkAdmin(message.From.ID))
}() }()
@ -371,9 +371,9 @@ func (t *Tgbot) OnReceive() {
botHandler.HandleCallbackQuery(func(ctx *th.Context, query telego.CallbackQuery) error { botHandler.HandleCallbackQuery(func(ctx *th.Context, query telego.CallbackQuery) error {
// Use goroutine with worker pool for concurrent callback processing // Use goroutine with worker pool for concurrent callback processing
go func() { go func() {
messageWorkerPool <- struct{}{} // Acquire worker messageWorkerPool <- struct{}{} // Acquire worker
defer func() { <-messageWorkerPool }() // Release worker defer func() { <-messageWorkerPool }() // Release worker
delete(userStates, query.Message.GetChat().ID) delete(userStates, query.Message.GetChat().ID)
t.answerCallback(&query, checkAdmin(query.From.ID)) t.answerCallback(&query, checkAdmin(query.From.ID))
}() }()
@ -2537,7 +2537,7 @@ func (t *Tgbot) prepareServerUsageInfo() string {
if cachedStats, found := t.getCachedServerStats(); found { if cachedStats, found := t.getCachedServerStats(); found {
return cachedStats return cachedStats
} }
info, ipv4, ipv6 := "", "", "" info, ipv4, ipv6 := "", "", ""
// get latest status of server with caching // get latest status of server with caching
@ -2588,10 +2588,10 @@ func (t *Tgbot) prepareServerUsageInfo() string {
info += t.I18nBot("tgbot.messages.udpCount", "Count=="+strconv.Itoa(t.lastStatus.UdpCount)) info += t.I18nBot("tgbot.messages.udpCount", "Count=="+strconv.Itoa(t.lastStatus.UdpCount))
info += t.I18nBot("tgbot.messages.traffic", "Total=="+common.FormatTraffic(int64(t.lastStatus.NetTraffic.Sent+t.lastStatus.NetTraffic.Recv)), "Upload=="+common.FormatTraffic(int64(t.lastStatus.NetTraffic.Sent)), "Download=="+common.FormatTraffic(int64(t.lastStatus.NetTraffic.Recv))) info += t.I18nBot("tgbot.messages.traffic", "Total=="+common.FormatTraffic(int64(t.lastStatus.NetTraffic.Sent+t.lastStatus.NetTraffic.Recv)), "Upload=="+common.FormatTraffic(int64(t.lastStatus.NetTraffic.Sent)), "Download=="+common.FormatTraffic(int64(t.lastStatus.NetTraffic.Recv)))
info += t.I18nBot("tgbot.messages.xrayStatus", "State=="+fmt.Sprint(t.lastStatus.Xray.State)) info += t.I18nBot("tgbot.messages.xrayStatus", "State=="+fmt.Sprint(t.lastStatus.Xray.State))
// Cache the complete server stats // Cache the complete server stats
t.setCachedServerStats(info) t.setCachedServerStats(info)
return info return info
} }

View file

@ -95,9 +95,10 @@ type Server struct {
httpServer *http.Server httpServer *http.Server
listener net.Listener listener net.Listener
index *controller.IndexController index *controller.IndexController
panel *controller.XUIController server *controller.ServerController
api *controller.APIController panel *controller.XUIController
api *controller.APIController
xrayService service.XrayService xrayService service.XrayService
settingService service.SettingService settingService service.SettingService
@ -263,6 +264,7 @@ func (s *Server) initRouter() (*gin.Engine, error) {
g := engine.Group(basePath) g := engine.Group(basePath)
s.index = controller.NewIndexController(g) s.index = controller.NewIndexController(g)
s.server = controller.NewMultiServerController(g)
s.panel = controller.NewXUIController(g) s.panel = controller.NewXUIController(g)
s.api = controller.NewAPIController(g) s.api = controller.NewAPIController(g)

13
x-ui.rc
View file

@ -1,13 +0,0 @@
#!/sbin/openrc-run
command="/usr/local/x-ui/x-ui"
command_background=true
pidfile="/run/x-ui.pid"
description="x-ui Service"
procname="x-ui"
depend() {
need net
}
start_pre(){
cd /usr/local/x-ui
}

251
x-ui.sh
View file

@ -153,19 +153,11 @@ uninstall() {
fi fi
return 0 return 0
fi fi
systemctl stop x-ui
if [[ $release == "alpine" ]]; then systemctl disable x-ui
rc-service x-ui stop rm /etc/systemd/system/x-ui.service -f
rc-update del x-ui systemctl daemon-reload
rm /etc/init.d/x-ui -f systemctl reset-failed
else
systemctl stop x-ui
systemctl disable x-ui
rm /etc/systemd/system/x-ui.service -f
systemctl daemon-reload
systemctl reset-failed
fi
rm /etc/x-ui/ -rf rm /etc/x-ui/ -rf
rm /usr/local/x-ui/ -rf rm /usr/local/x-ui/ -rf
@ -294,11 +286,7 @@ start() {
echo "" echo ""
LOGI "Panel is running, No need to start again, If you need to restart, please select restart" LOGI "Panel is running, No need to start again, If you need to restart, please select restart"
else else
if [[ $release == "alpine" ]]; then systemctl start x-ui
rc-service x-ui start
else
systemctl start x-ui
fi
sleep 2 sleep 2
check_status check_status
if [[ $? == 0 ]]; then if [[ $? == 0 ]]; then
@ -319,11 +307,7 @@ stop() {
echo "" echo ""
LOGI "Panel stopped, No need to stop again!" LOGI "Panel stopped, No need to stop again!"
else else
if [[ $release == "alpine" ]]; then systemctl stop x-ui
rc-service x-ui stop
else
systemctl stop x-ui
fi
sleep 2 sleep 2
check_status check_status
if [[ $? == 1 ]]; then if [[ $? == 1 ]]; then
@ -339,11 +323,7 @@ stop() {
} }
restart() { restart() {
if [[ $release == "alpine" ]]; then systemctl restart x-ui
rc-service x-ui restart
else
systemctl restart x-ui
fi
sleep 2 sleep 2
check_status check_status
if [[ $? == 0 ]]; then if [[ $? == 0 ]]; then
@ -357,22 +337,14 @@ restart() {
} }
status() { status() {
if [[ $release == "alpine" ]]; then systemctl status x-ui -l
rc-service x-ui status
else
systemctl status x-ui -l
fi
if [[ $# == 0 ]]; then if [[ $# == 0 ]]; then
before_show_menu before_show_menu
fi fi
} }
enable() { enable() {
if [[ $release == "alpine" ]]; then systemctl enable x-ui
rc-update add x-ui
else
systemctl enable x-ui
fi
if [[ $? == 0 ]]; then if [[ $? == 0 ]]; then
LOGI "x-ui Set to boot automatically on startup successfully" LOGI "x-ui Set to boot automatically on startup successfully"
else else
@ -385,11 +357,7 @@ enable() {
} }
disable() { disable() {
if [[ $release == "alpine" ]]; then systemctl disable x-ui
rc-update del x-ui
else
systemctl disable x-ui
fi
if [[ $? == 0 ]]; then if [[ $? == 0 ]]; then
LOGI "x-ui Autostart Cancelled successfully" LOGI "x-ui Autostart Cancelled successfully"
else else
@ -402,54 +370,32 @@ disable() {
} }
show_log() { show_log() {
if [[ $release == "alpine" ]]; then echo -e "${green}\t1.${plain} Debug Log"
echo -e "${green}\t1.${plain} Debug Log" echo -e "${green}\t2.${plain} Clear All logs"
echo -e "${green}\t0.${plain} Back to Main Menu" echo -e "${green}\t0.${plain} Back to Main Menu"
read -rp "Choose an option: " choice read -rp "Choose an option: " choice
case "$choice" in case "$choice" in
0) 0)
show_menu show_menu
;; ;;
1) 1)
grep -F 'x-ui[' /var/log/messages journalctl -u x-ui -e --no-pager -f -p debug
if [[ $# == 0 ]]; then if [[ $# == 0 ]]; then
before_show_menu before_show_menu
fi fi
;; ;;
*) 2)
echo -e "${red}Invalid option. Please select a valid number.${plain}\n" sudo journalctl --rotate
show_log sudo journalctl --vacuum-time=1s
;; echo "All Logs cleared."
esac restart
else ;;
echo -e "${green}\t1.${plain} Debug Log" *)
echo -e "${green}\t2.${plain} Clear All logs" echo -e "${red}Invalid option. Please select a valid number.${plain}\n"
echo -e "${green}\t0.${plain} Back to Main Menu" show_log
read -rp "Choose an option: " choice ;;
esac
case "$choice" in
0)
show_menu
;;
1)
journalctl -u x-ui -e --no-pager -f -p debug
if [[ $# == 0 ]]; then
before_show_menu
fi
;;
2)
sudo journalctl --rotate
sudo journalctl --vacuum-time=1s
echo "All Logs cleared."
restart
;;
*)
echo -e "${red}Invalid option. Please select a valid number.${plain}\n"
show_log
;;
esac
fi
} }
bbr_menu() { bbr_menu() {
@ -518,9 +464,6 @@ enable_bbr() {
arch | manjaro | parch) arch | manjaro | parch)
pacman -Sy --noconfirm ca-certificates pacman -Sy --noconfirm ca-certificates
;; ;;
alpine)
apk add ca-certificates
;;
*) *)
echo -e "${red}Unsupported operating system. Please check the script and install the necessary packages manually.${plain}\n" echo -e "${red}Unsupported operating system. Please check the script and install the necessary packages manually.${plain}\n"
exit 1 exit 1
@ -557,42 +500,23 @@ update_shell() {
# 0: running, 1: not running, 2: not installed # 0: running, 1: not running, 2: not installed
check_status() { check_status() {
if [[ $release == "alpine" ]]; then if [[ ! -f /etc/systemd/system/x-ui.service ]]; then
if [[ ! -f /etc/init.d/x-ui ]]; then return 2
return 2 fi
fi temp=$(systemctl status x-ui | grep Active | awk '{print $3}' | cut -d "(" -f2 | cut -d ")" -f1)
if [[ $(rc-service x-ui status | grep -F 'status: started' -c) == 1 ]]; then if [[ "${temp}" == "running" ]]; then
return 0 return 0
else
return 1
fi
else else
if [[ ! -f /etc/systemd/system/x-ui.service ]]; then return 1
return 2
fi
temp=$(systemctl status x-ui | grep Active | awk '{print $3}' | cut -d "(" -f2 | cut -d ")" -f1)
if [[ "${temp}" == "running" ]]; then
return 0
else
return 1
fi
fi fi
} }
check_enabled() { check_enabled() {
if [[ $release == "alpine" ]]; then temp=$(systemctl is-enabled x-ui)
if [[ $(rc-update show | grep -F 'x-ui' | grep default -c) == 1 ]]; then if [[ "${temp}" == "enabled" ]]; then
return 0 return 0
else
return 1
fi
else else
temp=$(systemctl is-enabled x-ui) return 1
if [[ "${temp}" == "enabled" ]]; then
return 0
else
return 1
fi
fi fi
} }
@ -874,11 +798,7 @@ update_geo() {
show_menu show_menu
;; ;;
1) 1)
if [[ $release == "alpine" ]]; then systemctl stop x-ui
rc-service x-ui stop
else
systemctl stop x-ui
fi
rm -f geoip.dat geosite.dat rm -f geoip.dat geosite.dat
wget -N https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geoip.dat wget -N https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geoip.dat
wget -N https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat wget -N https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat
@ -886,11 +806,7 @@ update_geo() {
restart restart
;; ;;
2) 2)
if [[ $release == "alpine" ]]; then systemctl stop x-ui
rc-service x-ui stop
else
systemctl stop x-ui
fi
rm -f geoip_IR.dat geosite_IR.dat rm -f geoip_IR.dat geosite_IR.dat
wget -O geoip_IR.dat -N https://github.com/chocolate4u/Iran-v2ray-rules/releases/latest/download/geoip.dat wget -O geoip_IR.dat -N https://github.com/chocolate4u/Iran-v2ray-rules/releases/latest/download/geoip.dat
wget -O geosite_IR.dat -N https://github.com/chocolate4u/Iran-v2ray-rules/releases/latest/download/geosite.dat wget -O geosite_IR.dat -N https://github.com/chocolate4u/Iran-v2ray-rules/releases/latest/download/geosite.dat
@ -898,11 +814,7 @@ update_geo() {
restart restart
;; ;;
3) 3)
if [[ $release == "alpine" ]]; then systemctl stop x-ui
rc-service x-ui stop
else
systemctl stop x-ui
fi
rm -f geoip_RU.dat geosite_RU.dat rm -f geoip_RU.dat geosite_RU.dat
wget -O geoip_RU.dat -N https://github.com/runetfreedom/russia-v2ray-rules-dat/releases/latest/download/geoip.dat wget -O geoip_RU.dat -N https://github.com/runetfreedom/russia-v2ray-rules-dat/releases/latest/download/geoip.dat
wget -O geosite_RU.dat -N https://github.com/runetfreedom/russia-v2ray-rules-dat/releases/latest/download/geosite.dat wget -O geosite_RU.dat -N https://github.com/runetfreedom/russia-v2ray-rules-dat/releases/latest/download/geosite.dat
@ -1073,9 +985,6 @@ ssl_cert_issue() {
arch | manjaro | parch) arch | manjaro | parch)
pacman -Sy --noconfirm socat pacman -Sy --noconfirm socat
;; ;;
alpine)
apk add socat
;;
*) *)
echo -e "${red}Unsupported operating system. Please check the script and install the necessary packages manually.${plain}\n" echo -e "${red}Unsupported operating system. Please check the script and install the necessary packages manually.${plain}\n"
exit 1 exit 1
@ -1426,11 +1335,7 @@ iplimit_main() {
read -rp "Please enter new Ban Duration in Minutes [default 30]: " NUM read -rp "Please enter new Ban Duration in Minutes [default 30]: " NUM
if [[ $NUM =~ ^[0-9]+$ ]]; then if [[ $NUM =~ ^[0-9]+$ ]]; then
create_iplimit_jails ${NUM} create_iplimit_jails ${NUM}
if [[ $release == "alpine" ]]; then systemctl restart fail2ban
rc-service fail2ban restart
else
systemctl restart fail2ban
fi
else else
echo -e "${red}${NUM} is not a number! Please, try again.${plain}" echo -e "${red}${NUM} is not a number! Please, try again.${plain}"
fi fi
@ -1483,11 +1388,7 @@ iplimit_main() {
iplimit_main iplimit_main
;; ;;
9) 9)
if [[ $release == "alpine" ]]; then systemctl restart fail2ban
rc-service fail2ban restart
else
systemctl restart fail2ban
fi
iplimit_main iplimit_main
;; ;;
10) 10)
@ -1535,9 +1436,6 @@ install_iplimit() {
arch | manjaro | parch) arch | manjaro | parch)
pacman -Syu --noconfirm fail2ban pacman -Syu --noconfirm fail2ban
;; ;;
alpine)
apk add fail2ban
;;
*) *)
echo -e "${red}Unsupported operating system. Please check the script and install the necessary packages manually.${plain}\n" echo -e "${red}Unsupported operating system. Please check the script and install the necessary packages manually.${plain}\n"
exit 1 exit 1
@ -1574,21 +1472,12 @@ install_iplimit() {
create_iplimit_jails create_iplimit_jails
# Launching fail2ban # Launching fail2ban
if [[ $release == "alpine" ]]; then if ! systemctl is-active --quiet fail2ban; then
if [[ $(rc-service fail2ban status | grep -F 'status: started' -c) == 0 ]]; then systemctl start fail2ban
rc-service fail2ban start
else
rc-service fail2ban restart
fi
rc-update add fail2ban
else else
if ! systemctl is-active --quiet fail2ban; then systemctl restart fail2ban
systemctl start fail2ban
else
systemctl restart fail2ban
fi
systemctl enable fail2ban
fi fi
systemctl enable fail2ban
echo -e "${green}IP Limit installed and configured successfully!${plain}\n" echo -e "${green}IP Limit installed and configured successfully!${plain}\n"
before_show_menu before_show_menu
@ -1604,21 +1493,13 @@ remove_iplimit() {
rm -f /etc/fail2ban/filter.d/3x-ipl.conf rm -f /etc/fail2ban/filter.d/3x-ipl.conf
rm -f /etc/fail2ban/action.d/3x-ipl.conf rm -f /etc/fail2ban/action.d/3x-ipl.conf
rm -f /etc/fail2ban/jail.d/3x-ipl.conf rm -f /etc/fail2ban/jail.d/3x-ipl.conf
if [[ $release == "alpine" ]]; then systemctl restart fail2ban
rc-service fail2ban restart
else
systemctl restart fail2ban
fi
echo -e "${green}IP Limit removed successfully!${plain}\n" echo -e "${green}IP Limit removed successfully!${plain}\n"
before_show_menu before_show_menu
;; ;;
2) 2)
rm -rf /etc/fail2ban rm -rf /etc/fail2ban
if [[ $release == "alpine" ]]; then systemctl stop fail2ban
rc-service fail2ban stop
else
systemctl stop fail2ban
fi
case "${release}" in case "${release}" in
ubuntu | debian | armbian) ubuntu | debian | armbian)
apt-get remove -y fail2ban apt-get remove -y fail2ban
@ -1636,9 +1517,6 @@ remove_iplimit() {
arch | manjaro | parch) arch | manjaro | parch)
pacman -Rns --noconfirm fail2ban pacman -Rns --noconfirm fail2ban
;; ;;
alpine)
apk del fail2ban
;;
*) *)
echo -e "${red}Unsupported operating system. Please uninstall Fail2ban manually.${plain}\n" echo -e "${red}Unsupported operating system. Please uninstall Fail2ban manually.${plain}\n"
exit 1 exit 1
@ -1662,16 +1540,9 @@ show_banlog() {
echo -e "${green}Checking ban logs...${plain}\n" echo -e "${green}Checking ban logs...${plain}\n"
if [[ $release == "alpine" ]]; then if ! systemctl is-active --quiet fail2ban; then
if [[ $(rc-service fail2ban status | grep -F 'status: started' -c) == 0 ]]; then echo -e "${red}Fail2ban service is not running!${plain}\n"
echo -e "${red}Fail2ban service is not running!${plain}\n" return 1
return 1
fi
else
if ! systemctl is-active --quiet fail2ban; then
echo -e "${red}Fail2ban service is not running!${plain}\n"
return 1
fi
fi fi
if [[ -f "$system_log" ]]; then if [[ -f "$system_log" ]]; then