mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-02-27 20:53:01 +00:00
Merge branch 'MHSanaei:main' into updatetimer
This commit is contained in:
commit
d8cb65e2b5
15 changed files with 1011 additions and 556 deletions
155
.github/copilot-instructions.md
vendored
Normal file
155
.github/copilot-instructions.md
vendored
Normal file
|
|
@ -0,0 +1,155 @@
|
||||||
|
# 3X-UI Development Guide
|
||||||
|
|
||||||
|
## Project Overview
|
||||||
|
3X-UI is a web-based control panel for managing Xray-core servers. It's a Go application using Gin web framework with embedded static assets and SQLite database. The panel manages VPN/proxy inbounds, monitors traffic, and provides Telegram bot integration.
|
||||||
|
|
||||||
|
## Architecture
|
||||||
|
|
||||||
|
### Core Components
|
||||||
|
- **main.go**: Entry point that initializes database, web server, and subscription server. Handles graceful shutdown via SIGHUP/SIGTERM signals
|
||||||
|
- **web/**: Primary web server with Gin router, HTML templates, and static assets embedded via `//go:embed`
|
||||||
|
- **xray/**: Xray-core process management and API communication for traffic monitoring
|
||||||
|
- **database/**: GORM-based SQLite database with models in `database/model/`
|
||||||
|
- **sub/**: Subscription server running alongside main web server (separate port)
|
||||||
|
- **web/service/**: Business logic layer containing InboundService, SettingService, TgBot, etc.
|
||||||
|
- **web/controller/**: HTTP handlers using Gin context (`*gin.Context`)
|
||||||
|
- **web/job/**: Cron-based background jobs for traffic monitoring, CPU checks, LDAP sync
|
||||||
|
|
||||||
|
### Key Architectural Patterns
|
||||||
|
1. **Embedded Resources**: All web assets (HTML, CSS, JS, translations) are embedded at compile time using `embed.FS`:
|
||||||
|
- `web/assets` → `assetsFS`
|
||||||
|
- `web/html` → `htmlFS`
|
||||||
|
- `web/translation` → `i18nFS`
|
||||||
|
|
||||||
|
2. **Dual Server Design**: Main web panel + subscription server run concurrently, managed by `web/global` package
|
||||||
|
|
||||||
|
3. **Xray Integration**: Panel generates `config.json` for Xray binary, communicates via gRPC API for real-time traffic stats
|
||||||
|
|
||||||
|
4. **Signal-Based Restart**: SIGHUP triggers graceful restart. **Critical**: Always call `service.StopBot()` before restart to prevent Telegram bot 409 conflicts
|
||||||
|
|
||||||
|
5. **Database Seeders**: Uses `HistoryOfSeeders` model to track one-time migrations (e.g., password bcrypt migration)
|
||||||
|
|
||||||
|
## Development Workflows
|
||||||
|
|
||||||
|
### Building & Running
|
||||||
|
```bash
|
||||||
|
# Build (creates bin/3x-ui.exe)
|
||||||
|
go run tasks.json → "go: build" task
|
||||||
|
|
||||||
|
# Run with debug logging
|
||||||
|
XUI_DEBUG=true go run ./main.go
|
||||||
|
# Or use task: "go: run"
|
||||||
|
|
||||||
|
# Test
|
||||||
|
go test ./...
|
||||||
|
```
|
||||||
|
|
||||||
|
### Command-Line Operations
|
||||||
|
The main.go accepts flags for admin tasks:
|
||||||
|
- `-reset` - Reset all panel settings to defaults
|
||||||
|
- `-show` - Display current settings (port, paths)
|
||||||
|
- Use these by running the binary directly, not via web interface
|
||||||
|
|
||||||
|
### Database Management
|
||||||
|
- DB path: Configured via `config.GetDBPath()`, typically `/etc/x-ui/x-ui.db`
|
||||||
|
- Models: Located in `database/model/model.go` - Auto-migrated on startup
|
||||||
|
- Seeders: Use `HistoryOfSeeders` to prevent re-running migrations
|
||||||
|
- Default credentials: admin/admin (hashed with bcrypt)
|
||||||
|
|
||||||
|
### Telegram Bot Development
|
||||||
|
- Bot instance in `web/service/tgbot.go` (3700+ lines)
|
||||||
|
- Uses `telego` library with long polling
|
||||||
|
- **Critical Pattern**: Must call `service.StopBot()` before any server restart to prevent 409 bot conflicts
|
||||||
|
- Bot handlers use `telegohandler.BotHandler` for routing
|
||||||
|
- i18n via embedded `i18nFS` passed to bot startup
|
||||||
|
|
||||||
|
## Code Conventions
|
||||||
|
|
||||||
|
### Service Layer Pattern
|
||||||
|
Services inject dependencies (like xray.XrayAPI) and operate on GORM models:
|
||||||
|
```go
|
||||||
|
type InboundService struct {
|
||||||
|
xrayApi xray.XrayAPI
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *InboundService) GetInbounds(userId int) ([]*model.Inbound, error) {
|
||||||
|
// Business logic here
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Controller Pattern
|
||||||
|
Controllers use Gin context and inherit from BaseController:
|
||||||
|
```go
|
||||||
|
func (a *InboundController) getInbounds(c *gin.Context) {
|
||||||
|
// Use I18nWeb(c, "key") for translations
|
||||||
|
// Check auth via checkLogin middleware
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Configuration Management
|
||||||
|
- Environment vars: `XUI_DEBUG`, `XUI_LOG_LEVEL`, `XUI_MAIN_FOLDER`
|
||||||
|
- Config embedded files: `config/version`, `config/name`
|
||||||
|
- Use `config.GetLogLevel()`, `config.GetDBPath()` helpers
|
||||||
|
|
||||||
|
### Internationalization
|
||||||
|
- Translation files: `web/translation/translate.*.toml`
|
||||||
|
- Access via `I18nWeb(c, "pages.login.loginAgain")` in controllers
|
||||||
|
- Use `locale.I18nType` enum (Web, Api, etc.)
|
||||||
|
|
||||||
|
## External Dependencies & Integration
|
||||||
|
|
||||||
|
### Xray-core
|
||||||
|
- Binary management: Download platform-specific binary (`xray-{os}-{arch}`) to bin folder
|
||||||
|
- Config generation: Panel creates `config.json` dynamically from inbound/outbound settings
|
||||||
|
- Process control: Start/stop via `xray/process.go`
|
||||||
|
- gRPC API: Real-time stats via `xray/api.go` using `google.golang.org/grpc`
|
||||||
|
|
||||||
|
### Critical External Paths
|
||||||
|
- Xray binary: `{bin_folder}/xray-{os}-{arch}`
|
||||||
|
- Xray config: `{bin_folder}/config.json`
|
||||||
|
- GeoIP/GeoSite: `{bin_folder}/geoip.dat`, `geosite.dat`
|
||||||
|
- Logs: `{log_folder}/3xipl.log`, `3xipl-banned.log`
|
||||||
|
|
||||||
|
### Job Scheduling
|
||||||
|
Uses `robfig/cron/v3` for periodic tasks:
|
||||||
|
- Traffic monitoring: `xray_traffic_job.go`
|
||||||
|
- CPU alerts: `check_cpu_usage.go`
|
||||||
|
- IP tracking: `check_client_ip_job.go`
|
||||||
|
- LDAP sync: `ldap_sync_job.go`
|
||||||
|
|
||||||
|
Jobs registered in `web/web.go` during server initialization
|
||||||
|
|
||||||
|
## Deployment & Scripts
|
||||||
|
|
||||||
|
### Installation Script Pattern
|
||||||
|
Both `install.sh` and `x-ui.sh` follow these patterns:
|
||||||
|
- Multi-distro support via `$release` variable (ubuntu, debian, centos, arch, etc.)
|
||||||
|
- Port detection with `is_port_in_use()` using ss/netstat/lsof
|
||||||
|
- Systemd service management with distro-specific unit files (`.service.debian`, `.service.arch`, `.service.rhel`)
|
||||||
|
|
||||||
|
### Docker Build
|
||||||
|
Multi-stage Dockerfile:
|
||||||
|
1. **Builder**: CGO-enabled build, runs `DockerInit.sh` to download Xray binary
|
||||||
|
2. **Final**: Alpine-based with fail2ban pre-configured
|
||||||
|
|
||||||
|
### Key File Locations (Production)
|
||||||
|
- Binary: `/usr/local/x-ui/`
|
||||||
|
- Database: `/etc/x-ui/x-ui.db`
|
||||||
|
- Logs: `/var/log/x-ui/`
|
||||||
|
- Service: `/etc/systemd/system/x-ui.service.*`
|
||||||
|
|
||||||
|
## Testing & Debugging
|
||||||
|
- Set `XUI_DEBUG=true` for detailed logging
|
||||||
|
- Check Xray process: `x-ui.sh` script provides menu for status/logs
|
||||||
|
- Database inspection: Direct SQLite access to x-ui.db
|
||||||
|
- Traffic debugging: Check `3xipl.log` for IP limit tracking
|
||||||
|
- Telegram bot: Logs show bot initialization and command handling
|
||||||
|
|
||||||
|
## Common Gotchas
|
||||||
|
1. **Bot Restart**: Always stop Telegram bot before server restart to avoid 409 conflict
|
||||||
|
2. **Embedded Assets**: Changes to HTML/CSS require recompilation (not hot-reload)
|
||||||
|
3. **Password Migration**: Seeder system tracks bcrypt migration - check `HistoryOfSeeders` table
|
||||||
|
4. **Port Binding**: Subscription server uses different port from main panel
|
||||||
|
5. **Xray Binary**: Must match OS/arch exactly - managed by installer scripts
|
||||||
|
6. **Session Management**: Uses `gin-contrib/sessions` with cookie store
|
||||||
|
7. **IP Limitation**: Implements "last IP wins" - when client exceeds LimitIP, oldest connections are automatically disconnected via Xray API to allow newest IPs
|
||||||
31
.github/workflows/cleanup_caches.yml
vendored
Normal file
31
.github/workflows/cleanup_caches.yml
vendored
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
name: Cleanup Caches
|
||||||
|
on:
|
||||||
|
schedule:
|
||||||
|
- cron: '0 3 * * 0' # every Sunday
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
cleanup:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
actions: write
|
||||||
|
steps:
|
||||||
|
- name: Delete caches older than 3 days
|
||||||
|
env:
|
||||||
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
run: |
|
||||||
|
CUTOFF_DATE=$(date -d "3 days ago" -Ins --utc | sed 's/+0000/Z/')
|
||||||
|
echo "Deleting caches older than: $CUTOFF_DATE"
|
||||||
|
|
||||||
|
CACHE_IDS=$(gh api --paginate repos/${{ github.repository }}/actions/caches \
|
||||||
|
--jq ".actions_caches[] | select(.last_accessed_at < \"$CUTOFF_DATE\") | .id" 2>/dev/null)
|
||||||
|
|
||||||
|
if [ -z "$CACHE_IDS" ]; then
|
||||||
|
echo "No old caches found to delete."
|
||||||
|
else
|
||||||
|
echo "$CACHE_IDS" | while read CACHE_ID; do
|
||||||
|
echo "Deleting cache: $CACHE_ID"
|
||||||
|
gh api -X DELETE repos/${{ github.repository }}/actions/caches/$CACHE_ID
|
||||||
|
done
|
||||||
|
echo "Old caches deleted successfully."
|
||||||
|
fi
|
||||||
37
.github/workflows/release.yml
vendored
37
.github/workflows/release.yml
vendored
|
|
@ -93,7 +93,7 @@ jobs:
|
||||||
cd x-ui/bin
|
cd x-ui/bin
|
||||||
|
|
||||||
# Download dependencies
|
# Download dependencies
|
||||||
Xray_URL="https://github.com/XTLS/Xray-core/releases/download/v26.1.31/"
|
Xray_URL="https://github.com/XTLS/Xray-core/releases/download/v26.2.2/"
|
||||||
if [ "${{ matrix.platform }}" == "amd64" ]; then
|
if [ "${{ matrix.platform }}" == "amd64" ]; then
|
||||||
wget -q ${Xray_URL}Xray-linux-64.zip
|
wget -q ${Xray_URL}Xray-linux-64.zip
|
||||||
unzip Xray-linux-64.zip
|
unzip Xray-linux-64.zip
|
||||||
|
|
@ -177,21 +177,42 @@ jobs:
|
||||||
go-version-file: go.mod
|
go-version-file: go.mod
|
||||||
check-latest: true
|
check-latest: true
|
||||||
|
|
||||||
- name: Build 3X-UI for Windows
|
- name: Install MSYS2
|
||||||
shell: pwsh
|
uses: msys2/setup-msys2@v2
|
||||||
|
with:
|
||||||
|
msystem: MINGW64
|
||||||
|
update: true
|
||||||
|
install: >-
|
||||||
|
mingw-w64-x86_64-gcc
|
||||||
|
mingw-w64-x86_64-sqlite3
|
||||||
|
mingw-w64-x86_64-pkg-config
|
||||||
|
|
||||||
|
- name: Build 3X-UI for Windows (CGO)
|
||||||
|
shell: msys2 {0}
|
||||||
run: |
|
run: |
|
||||||
$env:CGO_ENABLED="1"
|
export PATH="/c/hostedtoolcache/windows/go/$(ls /c/hostedtoolcache/windows/go | sort -V | tail -n1)/x64/bin:$PATH"
|
||||||
$env:GOOS="windows"
|
|
||||||
$env:GOARCH="amd64"
|
export CGO_ENABLED=1
|
||||||
|
export GOOS=windows
|
||||||
|
export GOARCH=amd64
|
||||||
|
export CC=x86_64-w64-mingw32-gcc
|
||||||
|
|
||||||
|
which go
|
||||||
|
go version
|
||||||
|
gcc --version
|
||||||
|
|
||||||
go build -ldflags "-w -s" -o xui-release.exe -v main.go
|
go build -ldflags "-w -s" -o xui-release.exe -v main.go
|
||||||
|
|
||||||
|
- name: Copy and download resources
|
||||||
|
shell: pwsh
|
||||||
|
run: |
|
||||||
mkdir x-ui
|
mkdir x-ui
|
||||||
Copy-Item xui-release.exe x-ui\
|
Copy-Item xui-release.exe x-ui\x-ui.exe
|
||||||
mkdir x-ui\bin
|
mkdir x-ui\bin
|
||||||
cd x-ui\bin
|
cd x-ui\bin
|
||||||
|
|
||||||
# Download Xray for Windows
|
# Download Xray for Windows
|
||||||
$Xray_URL = "https://github.com/XTLS/Xray-core/releases/download/v26.1.31/"
|
$Xray_URL = "https://github.com/XTLS/Xray-core/releases/download/v26.2.2/"
|
||||||
Invoke-WebRequest -Uri "${Xray_URL}Xray-windows-64.zip" -OutFile "Xray-windows-64.zip"
|
Invoke-WebRequest -Uri "${Xray_URL}Xray-windows-64.zip" -OutFile "Xray-windows-64.zip"
|
||||||
Expand-Archive -Path "Xray-windows-64.zip" -DestinationPath .
|
Expand-Archive -Path "Xray-windows-64.zip" -DestinationPath .
|
||||||
Remove-Item "Xray-windows-64.zip"
|
Remove-Item "Xray-windows-64.zip"
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ case $1 in
|
||||||
esac
|
esac
|
||||||
mkdir -p build/bin
|
mkdir -p build/bin
|
||||||
cd build/bin
|
cd build/bin
|
||||||
curl -sfLRO "https://github.com/XTLS/Xray-core/releases/download/v26.1.31/Xray-linux-${ARCH}.zip"
|
curl -sfLRO "https://github.com/XTLS/Xray-core/releases/download/v26.2.2/Xray-linux-${ARCH}.zip"
|
||||||
unzip "Xray-linux-${ARCH}.zip"
|
unzip "Xray-linux-${ARCH}.zip"
|
||||||
rm -f "Xray-linux-${ARCH}.zip" geoip.dat geosite.dat
|
rm -f "Xray-linux-${ARCH}.zip" geoip.dat geosite.dat
|
||||||
mv xray "xray-linux-${FNAME}"
|
mv xray "xray-linux-${FNAME}"
|
||||||
|
|
|
||||||
4
go.mod
4
go.mod
|
|
@ -20,7 +20,7 @@ require (
|
||||||
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
|
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
|
||||||
github.com/valyala/fasthttp v1.69.0
|
github.com/valyala/fasthttp v1.69.0
|
||||||
github.com/xlzd/gotp v0.1.0
|
github.com/xlzd/gotp v0.1.0
|
||||||
github.com/xtls/xray-core v1.260131.0
|
github.com/xtls/xray-core v1.260202.0
|
||||||
go.uber.org/atomic v1.11.0
|
go.uber.org/atomic v1.11.0
|
||||||
golang.org/x/crypto v0.47.0
|
golang.org/x/crypto v0.47.0
|
||||||
golang.org/x/sys v0.40.0
|
golang.org/x/sys v0.40.0
|
||||||
|
|
@ -40,7 +40,7 @@ require (
|
||||||
github.com/cloudflare/circl v1.6.3 // indirect
|
github.com/cloudflare/circl v1.6.3 // indirect
|
||||||
github.com/cloudwego/base64x v0.1.6 // indirect
|
github.com/cloudwego/base64x v0.1.6 // indirect
|
||||||
github.com/ebitengine/purego v0.9.1 // indirect
|
github.com/ebitengine/purego v0.9.1 // indirect
|
||||||
github.com/gabriel-vasile/mimetype v1.4.12 // indirect
|
github.com/gabriel-vasile/mimetype v1.4.13 // indirect
|
||||||
github.com/gin-contrib/sse v1.1.0 // indirect
|
github.com/gin-contrib/sse v1.1.0 // indirect
|
||||||
github.com/go-asn1-ber/asn1-ber v1.5.8-0.20250403174932-29230038a667 // indirect
|
github.com/go-asn1-ber/asn1-ber v1.5.8-0.20250403174932-29230038a667 // indirect
|
||||||
github.com/go-ole/go-ole v1.3.0 // indirect
|
github.com/go-ole/go-ole v1.3.0 // indirect
|
||||||
|
|
|
||||||
8
go.sum
8
go.sum
|
|
@ -23,8 +23,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/ebitengine/purego v0.9.1 h1:a/k2f2HQU3Pi399RPW1MOaZyhKJL9w/xFpKAg4q1s0A=
|
github.com/ebitengine/purego v0.9.1 h1:a/k2f2HQU3Pi399RPW1MOaZyhKJL9w/xFpKAg4q1s0A=
|
||||||
github.com/ebitengine/purego v0.9.1/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ=
|
github.com/ebitengine/purego v0.9.1/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ=
|
||||||
github.com/gabriel-vasile/mimetype v1.4.12 h1:e9hWvmLYvtp846tLHam2o++qitpguFiYCKbn0w9jyqw=
|
github.com/gabriel-vasile/mimetype v1.4.13 h1:46nXokslUBsAJE/wMsp5gtO500a4F3Nkz9Ufpk2AcUM=
|
||||||
github.com/gabriel-vasile/mimetype v1.4.12/go.mod h1:d+9Oxyo1wTzWdyVUPMmXFvp4F9tea18J8ufA774AB3s=
|
github.com/gabriel-vasile/mimetype v1.4.13/go.mod h1:d+9Oxyo1wTzWdyVUPMmXFvp4F9tea18J8ufA774AB3s=
|
||||||
github.com/ghodss/yaml v1.0.1-0.20220118164431-d8423dcdf344 h1:Arcl6UOIS/kgO2nW3A65HN+7CMjSDP/gofXL4CZt1V4=
|
github.com/ghodss/yaml v1.0.1-0.20220118164431-d8423dcdf344 h1:Arcl6UOIS/kgO2nW3A65HN+7CMjSDP/gofXL4CZt1V4=
|
||||||
github.com/ghodss/yaml v1.0.1-0.20220118164431-d8423dcdf344/go.mod h1:GIjDIg/heH5DOkXY3YJ/wNhfHsQHoXGjl8G8amsYQ1I=
|
github.com/ghodss/yaml v1.0.1-0.20220118164431-d8423dcdf344/go.mod h1:GIjDIg/heH5DOkXY3YJ/wNhfHsQHoXGjl8G8amsYQ1I=
|
||||||
github.com/gin-contrib/gzip v1.2.5 h1:fIZs0S+l17pIu1P5XRJOo/YNqfIuPCrZZ3TWB7pjckI=
|
github.com/gin-contrib/gzip v1.2.5 h1:fIZs0S+l17pIu1P5XRJOo/YNqfIuPCrZZ3TWB7pjckI=
|
||||||
|
|
@ -195,8 +195,8 @@ github.com/xlzd/gotp v0.1.0 h1:37blvlKCh38s+fkem+fFh7sMnceltoIEBYTVXyoa5Po=
|
||||||
github.com/xlzd/gotp v0.1.0/go.mod h1:ndLJ3JKzi3xLmUProq4LLxCuECL93dG9WASNLpHz8qg=
|
github.com/xlzd/gotp v0.1.0/go.mod h1:ndLJ3JKzi3xLmUProq4LLxCuECL93dG9WASNLpHz8qg=
|
||||||
github.com/xtls/reality v0.0.0-20251116175510-cd53f7d50237 h1:UXjrmniKlY+ZbIqpN91lejB3pszQQQRVu1vqH/p/aGM=
|
github.com/xtls/reality v0.0.0-20251116175510-cd53f7d50237 h1:UXjrmniKlY+ZbIqpN91lejB3pszQQQRVu1vqH/p/aGM=
|
||||||
github.com/xtls/reality v0.0.0-20251116175510-cd53f7d50237/go.mod h1:vbHCV/3VWUvy1oKvTxxWJRPEWSeR1sYgQHIh6u/JiZQ=
|
github.com/xtls/reality v0.0.0-20251116175510-cd53f7d50237/go.mod h1:vbHCV/3VWUvy1oKvTxxWJRPEWSeR1sYgQHIh6u/JiZQ=
|
||||||
github.com/xtls/xray-core v1.260131.0 h1:gPBykLhUvRZ8sfubNerkwWqV3c15UtmSYQG2cgKqrV4=
|
github.com/xtls/xray-core v1.260202.0 h1:dYduYxGlkn/krSQJbmksbTtCdRe8OFb3YwpuXXEJG5c=
|
||||||
github.com/xtls/xray-core v1.260131.0/go.mod h1:cxzYFZrxu1B1NtPjHsqv4UzgDvRA71mV4rXYH4KtO7Q=
|
github.com/xtls/xray-core v1.260202.0/go.mod h1:cxzYFZrxu1B1NtPjHsqv4UzgDvRA71mV4rXYH4KtO7Q=
|
||||||
github.com/xyproto/randomstring v1.0.5 h1:YtlWPoRdgMu3NZtP45drfy1GKoojuR7hmRcnhZqKjWU=
|
github.com/xyproto/randomstring v1.0.5 h1:YtlWPoRdgMu3NZtP45drfy1GKoojuR7hmRcnhZqKjWU=
|
||||||
github.com/xyproto/randomstring v1.0.5/go.mod h1:rgmS5DeNXLivK7YprL0pY+lTuhNQW3iGxZ18UQApw/E=
|
github.com/xyproto/randomstring v1.0.5/go.mod h1:rgmS5DeNXLivK7YprL0pY+lTuhNQW3iGxZ18UQApw/E=
|
||||||
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
|
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@ package sub
|
||||||
import (
|
import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/mhsanaei/3x-ui/v2/config"
|
"github.com/mhsanaei/3x-ui/v2/config"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -967,7 +967,7 @@ class SockoptStreamSettings extends XrayCommonClass {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class FinalMask extends XrayCommonClass {
|
class UdpMask extends XrayCommonClass {
|
||||||
constructor(type = 'salamander', settings = {}) {
|
constructor(type = 'salamander', settings = {}) {
|
||||||
super();
|
super();
|
||||||
this.type = type;
|
this.type = type;
|
||||||
|
|
@ -982,6 +982,8 @@ class FinalMask extends XrayCommonClass {
|
||||||
case 'header-dns':
|
case 'header-dns':
|
||||||
case 'xdns':
|
case 'xdns':
|
||||||
return { domain: settings.domain || '' };
|
return { domain: settings.domain || '' };
|
||||||
|
case 'xicmp':
|
||||||
|
return { ip: settings.ip || '', id: settings.id ?? 0 };
|
||||||
case 'mkcp-original':
|
case 'mkcp-original':
|
||||||
case 'header-dtls':
|
case 'header-dtls':
|
||||||
case 'header-srtp':
|
case 'header-srtp':
|
||||||
|
|
@ -995,20 +997,35 @@ class FinalMask extends XrayCommonClass {
|
||||||
}
|
}
|
||||||
|
|
||||||
static fromJson(json = {}) {
|
static fromJson(json = {}) {
|
||||||
return new FinalMask(
|
return new UdpMask(
|
||||||
json.type || 'salamander',
|
json.type || 'salamander',
|
||||||
json.settings || {}
|
json.settings || {}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
toJson() {
|
toJson() {
|
||||||
const result = {
|
return {
|
||||||
type: this.type
|
type: this.type,
|
||||||
|
settings: (this.settings && Object.keys(this.settings).length > 0) ? this.settings : undefined
|
||||||
};
|
};
|
||||||
if (this.settings && Object.keys(this.settings).length > 0) {
|
|
||||||
result.settings = this.settings;
|
|
||||||
}
|
}
|
||||||
return result;
|
}
|
||||||
|
|
||||||
|
class FinalMaskStreamSettings extends XrayCommonClass {
|
||||||
|
constructor(udp = []) {
|
||||||
|
super();
|
||||||
|
this.udp = Array.isArray(udp) ? udp.map(u => new UdpMask(u.type, u.settings)) : [new UdpMask(udp.type, udp.settings)];
|
||||||
|
}
|
||||||
|
|
||||||
|
static fromJson(json = {}) {
|
||||||
|
return new FinalMaskStreamSettings(json.udp || []);
|
||||||
|
}
|
||||||
|
|
||||||
|
toJson() {
|
||||||
|
return {
|
||||||
|
udp: this.udp.map(udp => udp.toJson())
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1024,7 +1041,7 @@ class StreamSettings extends XrayCommonClass {
|
||||||
grpcSettings = new GrpcStreamSettings(),
|
grpcSettings = new GrpcStreamSettings(),
|
||||||
httpupgradeSettings = new HTTPUpgradeStreamSettings(),
|
httpupgradeSettings = new HTTPUpgradeStreamSettings(),
|
||||||
xhttpSettings = new xHTTPStreamSettings(),
|
xhttpSettings = new xHTTPStreamSettings(),
|
||||||
finalmask = { udp: [] },
|
finalmask = new FinalMaskStreamSettings(),
|
||||||
sockopt = undefined,
|
sockopt = undefined,
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
|
|
@ -1044,10 +1061,7 @@ class StreamSettings extends XrayCommonClass {
|
||||||
}
|
}
|
||||||
|
|
||||||
addUdpMask(type = 'salamander') {
|
addUdpMask(type = 'salamander') {
|
||||||
if (!this.finalmask.udp) {
|
this.finalmask.udp.push(new UdpMask(type));
|
||||||
this.finalmask.udp = [];
|
|
||||||
}
|
|
||||||
this.finalmask.udp.push(new FinalMask(type));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
delUdpMask(index) {
|
delUdpMask(index) {
|
||||||
|
|
@ -1056,6 +1070,10 @@ class StreamSettings extends XrayCommonClass {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get hasFinalMask() {
|
||||||
|
return this.finalmask.udp && this.finalmask.udp.length > 0;
|
||||||
|
}
|
||||||
|
|
||||||
get isTls() {
|
get isTls() {
|
||||||
return this.security === "tls";
|
return this.security === "tls";
|
||||||
}
|
}
|
||||||
|
|
@ -1090,14 +1108,6 @@ class StreamSettings extends XrayCommonClass {
|
||||||
}
|
}
|
||||||
|
|
||||||
static fromJson(json = {}) {
|
static fromJson(json = {}) {
|
||||||
let finalmask = { udp: [] };
|
|
||||||
if (json.finalmask) {
|
|
||||||
if (Array.isArray(json.finalmask)) {
|
|
||||||
finalmask.udp = json.finalmask.map(mask => FinalMask.fromJson(mask));
|
|
||||||
} else if (json.finalmask.udp) {
|
|
||||||
finalmask.udp = json.finalmask.udp.map(mask => FinalMask.fromJson(mask));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return new StreamSettings(
|
return new StreamSettings(
|
||||||
json.network,
|
json.network,
|
||||||
json.security,
|
json.security,
|
||||||
|
|
@ -1110,7 +1120,7 @@ class StreamSettings extends XrayCommonClass {
|
||||||
GrpcStreamSettings.fromJson(json.grpcSettings),
|
GrpcStreamSettings.fromJson(json.grpcSettings),
|
||||||
HTTPUpgradeStreamSettings.fromJson(json.httpupgradeSettings),
|
HTTPUpgradeStreamSettings.fromJson(json.httpupgradeSettings),
|
||||||
xHTTPStreamSettings.fromJson(json.xhttpSettings),
|
xHTTPStreamSettings.fromJson(json.xhttpSettings),
|
||||||
finalmask,
|
FinalMaskStreamSettings.fromJson(json.finalmask),
|
||||||
SockoptStreamSettings.fromJson(json.sockopt),
|
SockoptStreamSettings.fromJson(json.sockopt),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -1129,9 +1139,7 @@ class StreamSettings extends XrayCommonClass {
|
||||||
grpcSettings: network === 'grpc' ? this.grpc.toJson() : undefined,
|
grpcSettings: network === 'grpc' ? this.grpc.toJson() : undefined,
|
||||||
httpupgradeSettings: network === 'httpupgrade' ? this.httpupgrade.toJson() : undefined,
|
httpupgradeSettings: network === 'httpupgrade' ? this.httpupgrade.toJson() : undefined,
|
||||||
xhttpSettings: network === 'xhttp' ? this.xhttp.toJson() : undefined,
|
xhttpSettings: network === 'xhttp' ? this.xhttp.toJson() : undefined,
|
||||||
finalmask: (this.finalmask.udp && this.finalmask.udp.length > 0) ? {
|
finalmask: this.hasFinalMask ? this.finalmask.toJson() : undefined,
|
||||||
udp: this.finalmask.udp.map(mask => mask.toJson())
|
|
||||||
} : undefined,
|
|
||||||
sockopt: this.sockopt != undefined ? this.sockopt.toJson() : undefined,
|
sockopt: this.sockopt != undefined ? this.sockopt.toJson() : undefined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -1302,14 +1310,6 @@ class Inbound extends XrayCommonClass {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
get kcpType() {
|
|
||||||
return this.stream.kcp.type;
|
|
||||||
}
|
|
||||||
|
|
||||||
get kcpSeed() {
|
|
||||||
return this.stream.kcp.seed;
|
|
||||||
}
|
|
||||||
|
|
||||||
get serviceName() {
|
get serviceName() {
|
||||||
return this.stream.grpc.serviceName;
|
return this.stream.grpc.serviceName;
|
||||||
}
|
}
|
||||||
|
|
@ -1386,8 +1386,6 @@ class Inbound extends XrayCommonClass {
|
||||||
}
|
}
|
||||||
} else if (network === 'kcp') {
|
} else if (network === 'kcp') {
|
||||||
const kcp = this.stream.kcp;
|
const kcp = this.stream.kcp;
|
||||||
obj.type = kcp.type;
|
|
||||||
obj.path = kcp.seed;
|
|
||||||
} else if (network === 'ws') {
|
} else if (network === 'ws') {
|
||||||
const ws = this.stream.ws;
|
const ws = this.stream.ws;
|
||||||
obj.path = ws.path;
|
obj.path = ws.path;
|
||||||
|
|
@ -1450,8 +1448,6 @@ class Inbound extends XrayCommonClass {
|
||||||
break;
|
break;
|
||||||
case "kcp":
|
case "kcp":
|
||||||
const kcp = this.stream.kcp;
|
const kcp = this.stream.kcp;
|
||||||
params.set("headerType", kcp.type);
|
|
||||||
params.set("seed", kcp.seed);
|
|
||||||
break;
|
break;
|
||||||
case "ws":
|
case "ws":
|
||||||
const ws = this.stream.ws;
|
const ws = this.stream.ws;
|
||||||
|
|
@ -1555,8 +1551,6 @@ class Inbound extends XrayCommonClass {
|
||||||
break;
|
break;
|
||||||
case "kcp":
|
case "kcp":
|
||||||
const kcp = this.stream.kcp;
|
const kcp = this.stream.kcp;
|
||||||
params.set("headerType", kcp.type);
|
|
||||||
params.set("seed", kcp.seed);
|
|
||||||
break;
|
break;
|
||||||
case "ws":
|
case "ws":
|
||||||
const ws = this.stream.ws;
|
const ws = this.stream.ws;
|
||||||
|
|
@ -1636,8 +1630,6 @@ class Inbound extends XrayCommonClass {
|
||||||
break;
|
break;
|
||||||
case "kcp":
|
case "kcp":
|
||||||
const kcp = this.stream.kcp;
|
const kcp = this.stream.kcp;
|
||||||
params.set("headerType", kcp.type);
|
|
||||||
params.set("seed", kcp.seed);
|
|
||||||
break;
|
break;
|
||||||
case "ws":
|
case "ws":
|
||||||
const ws = this.stream.ws;
|
const ws = this.stream.ws;
|
||||||
|
|
|
||||||
|
|
@ -568,7 +568,7 @@ class SockoptStreamSettings extends CommonClass {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class FinalMask extends CommonClass {
|
class UdpMask extends CommonClass {
|
||||||
constructor(type = 'salamander', settings = {}) {
|
constructor(type = 'salamander', settings = {}) {
|
||||||
super();
|
super();
|
||||||
this.type = type;
|
this.type = type;
|
||||||
|
|
@ -596,21 +596,35 @@ class FinalMask extends CommonClass {
|
||||||
}
|
}
|
||||||
|
|
||||||
static fromJson(json = {}) {
|
static fromJson(json = {}) {
|
||||||
return new FinalMask(
|
return new UdpMask(
|
||||||
json.type || 'salamander',
|
json.type || 'salamander',
|
||||||
json.settings || {}
|
json.settings || {}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
toJson() {
|
toJson() {
|
||||||
const result = {
|
return {
|
||||||
type: this.type
|
type: this.type,
|
||||||
|
settings: (this.settings && Object.keys(this.settings).length > 0) ? this.settings : undefined
|
||||||
};
|
};
|
||||||
// Only include settings if they exist and are not empty
|
|
||||||
if (this.settings && Object.keys(this.settings).length > 0) {
|
|
||||||
result.settings = this.settings;
|
|
||||||
}
|
}
|
||||||
return result;
|
}
|
||||||
|
|
||||||
|
class FinalMaskStreamSettings extends CommonClass {
|
||||||
|
constructor(udp = []) {
|
||||||
|
super();
|
||||||
|
this.udp = Array.isArray(udp) ? udp.map(u => new UdpMask(u.type, u.settings)) : [new UdpMask(udp.type, udp.settings)];
|
||||||
|
}
|
||||||
|
|
||||||
|
static fromJson(json = {}) {
|
||||||
|
return new FinalMaskStreamSettings(json.udp || []);
|
||||||
|
}
|
||||||
|
|
||||||
|
toJson() {
|
||||||
|
return {
|
||||||
|
udp: this.udp.map(udp => udp.toJson())
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -627,7 +641,7 @@ class StreamSettings extends CommonClass {
|
||||||
httpupgradeSettings = new HttpUpgradeStreamSettings(),
|
httpupgradeSettings = new HttpUpgradeStreamSettings(),
|
||||||
xhttpSettings = new xHTTPStreamSettings(),
|
xhttpSettings = new xHTTPStreamSettings(),
|
||||||
hysteriaSettings = new HysteriaStreamSettings(),
|
hysteriaSettings = new HysteriaStreamSettings(),
|
||||||
finalmask = { udp: [] },
|
finalmask = new FinalMaskStreamSettings(),
|
||||||
sockopt = undefined,
|
sockopt = undefined,
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
|
|
@ -647,10 +661,7 @@ class StreamSettings extends CommonClass {
|
||||||
}
|
}
|
||||||
|
|
||||||
addUdpMask(type = 'salamander') {
|
addUdpMask(type = 'salamander') {
|
||||||
if (!this.finalmask.udp) {
|
this.finalmask.udp.push(new UdpMask(type));
|
||||||
this.finalmask.udp = [];
|
|
||||||
}
|
|
||||||
this.finalmask.udp.push(new FinalMask(type));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
delUdpMask(index) {
|
delUdpMask(index) {
|
||||||
|
|
@ -659,6 +670,10 @@ class StreamSettings extends CommonClass {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get hasFinalMask() {
|
||||||
|
return this.finalmask.udp && this.finalmask.udp.length > 0;
|
||||||
|
}
|
||||||
|
|
||||||
get isTls() {
|
get isTls() {
|
||||||
return this.security === 'tls';
|
return this.security === 'tls';
|
||||||
}
|
}
|
||||||
|
|
@ -676,16 +691,6 @@ class StreamSettings extends CommonClass {
|
||||||
}
|
}
|
||||||
|
|
||||||
static fromJson(json = {}) {
|
static fromJson(json = {}) {
|
||||||
let finalmask = { udp: [] };
|
|
||||||
if (json.finalmask) {
|
|
||||||
if (Array.isArray(json.finalmask)) {
|
|
||||||
// Legacy format: direct array (backward compatibility)
|
|
||||||
finalmask.udp = json.finalmask.map(mask => FinalMask.fromJson(mask));
|
|
||||||
} else if (json.finalmask.udp) {
|
|
||||||
// New format: object with udp array
|
|
||||||
finalmask.udp = json.finalmask.udp.map(mask => FinalMask.fromJson(mask));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return new StreamSettings(
|
return new StreamSettings(
|
||||||
json.network,
|
json.network,
|
||||||
json.security,
|
json.security,
|
||||||
|
|
@ -698,7 +703,7 @@ class StreamSettings extends CommonClass {
|
||||||
HttpUpgradeStreamSettings.fromJson(json.httpupgradeSettings),
|
HttpUpgradeStreamSettings.fromJson(json.httpupgradeSettings),
|
||||||
xHTTPStreamSettings.fromJson(json.xhttpSettings),
|
xHTTPStreamSettings.fromJson(json.xhttpSettings),
|
||||||
HysteriaStreamSettings.fromJson(json.hysteriaSettings),
|
HysteriaStreamSettings.fromJson(json.hysteriaSettings),
|
||||||
finalmask,
|
FinalMaskStreamSettings.fromJson(json.finalmask),
|
||||||
SockoptStreamSettings.fromJson(json.sockopt),
|
SockoptStreamSettings.fromJson(json.sockopt),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -717,9 +722,7 @@ class StreamSettings extends CommonClass {
|
||||||
httpupgradeSettings: network === 'httpupgrade' ? this.httpupgrade.toJson() : undefined,
|
httpupgradeSettings: network === 'httpupgrade' ? this.httpupgrade.toJson() : undefined,
|
||||||
xhttpSettings: network === 'xhttp' ? this.xhttp.toJson() : undefined,
|
xhttpSettings: network === 'xhttp' ? this.xhttp.toJson() : undefined,
|
||||||
hysteriaSettings: network === 'hysteria' ? this.hysteria.toJson() : undefined,
|
hysteriaSettings: network === 'hysteria' ? this.hysteria.toJson() : undefined,
|
||||||
finalmask: (this.finalmask.udp && this.finalmask.udp.length > 0) ? {
|
finalmask: this.hasFinalMask ? this.finalmask.toJson() : undefined,
|
||||||
udp: this.finalmask.udp.map(mask => mask.toJson())
|
|
||||||
} : undefined,
|
|
||||||
sockopt: this.sockopt != undefined ? this.sockopt.toJson() : undefined,
|
sockopt: this.sockopt != undefined ? this.sockopt.toJson() : undefined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,9 @@
|
||||||
<a-select-option v-if="inbound.stream.network === 'kcp'"
|
<a-select-option v-if="inbound.stream.network === 'kcp'"
|
||||||
value="mkcp-original">
|
value="mkcp-original">
|
||||||
mKCP Original</a-select-option>
|
mKCP Original</a-select-option>
|
||||||
|
<a-select-option v-if="inbound.stream.network === 'kcp'"
|
||||||
|
value="xicmp">
|
||||||
|
xICMP (Experimental)</a-select-option>
|
||||||
<!-- xDNS for TCP/WS/HTTPUpgrade/XHTTP -->
|
<!-- xDNS for TCP/WS/HTTPUpgrade/XHTTP -->
|
||||||
<a-select-option
|
<a-select-option
|
||||||
v-if="['tcp', 'ws', 'httpupgrade', 'xhttp'].includes(inbound.stream.network)"
|
v-if="['tcp', 'ws', 'httpupgrade', 'xhttp'].includes(inbound.stream.network)"
|
||||||
|
|
@ -64,6 +67,17 @@
|
||||||
<a-input v-model.trim="mask.settings.domain"
|
<a-input v-model.trim="mask.settings.domain"
|
||||||
placeholder="e.g., www.example.com"></a-input>
|
placeholder="e.g., www.example.com"></a-input>
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
|
<!-- Settings for xICMP -->
|
||||||
|
<a-form-item label='IP'
|
||||||
|
v-if="mask.type === 'xicmp'">
|
||||||
|
<a-input v-model.trim="mask.settings.ip"
|
||||||
|
placeholder="e.g., 1.1.1.1"></a-input>
|
||||||
|
</a-form-item>
|
||||||
|
<a-form-item label='ID'
|
||||||
|
v-if="mask.type === 'xicmp'">
|
||||||
|
<a-input-number v-model.number="mask.settings.id"
|
||||||
|
:min="0" :max="65535"></a-input-number>
|
||||||
|
</a-form-item>
|
||||||
</a-form>
|
</a-form>
|
||||||
</template>
|
</template>
|
||||||
</a-form>
|
</a-form>
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
{{define "modals/inboundInfoModal"}}
|
{{define "modals/inboundInfoModal"}}
|
||||||
<a-modal id="inbound-info-modal" v-model="infoModal.visible" title='{{ i18n "pages.inbounds.details"}}' :closable="true" :mask-closable="true" :footer="null" width="600px" :class="themeSwitcher.currentTheme">
|
<a-modal id="inbound-info-modal" v-model="infoModal.visible"
|
||||||
|
title='{{ i18n "pages.inbounds.details"}}' :closable="true"
|
||||||
|
:mask-closable="true" :footer="null" width="600px"
|
||||||
|
:class="themeSwitcher.currentTheme">
|
||||||
<a-row>
|
<a-row>
|
||||||
<a-col :xs="24" :md="12">
|
<a-col :xs="24" :md="12">
|
||||||
<table>
|
<table>
|
||||||
|
|
@ -26,7 +29,8 @@
|
||||||
</table>
|
</table>
|
||||||
</a-col>
|
</a-col>
|
||||||
<a-col :xs="24" :md="12">
|
<a-col :xs="24" :md="12">
|
||||||
<template v-if="dbInbound.isVMess || dbInbound.isVLess || dbInbound.isTrojan || dbInbound.isSS">
|
<template
|
||||||
|
v-if="dbInbound.isVMess || dbInbound.isVLess || dbInbound.isTrojan || dbInbound.isSS">
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ i18n "transmission" }}</td>
|
<td>{{ i18n "transmission" }}</td>
|
||||||
|
|
@ -34,7 +38,8 @@
|
||||||
<a-tag color="green">[[ inbound.network ]]</a-tag>
|
<a-tag color="green">[[ inbound.network ]]</a-tag>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<template v-if="inbound.isTcp || inbound.isWs || inbound.isHttpupgrade || inbound.isXHTTP">
|
<template
|
||||||
|
v-if="inbound.isTcp || inbound.isWs || inbound.isHttpupgrade || inbound.isXHTTP">
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ i18n "host" }}</td>
|
<td>{{ i18n "host" }}</td>
|
||||||
<td v-if="inbound.host">
|
<td v-if="inbound.host">
|
||||||
|
|
@ -66,26 +71,13 @@
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</template>
|
</template>
|
||||||
<template v-if="inbound.isKcp">
|
|
||||||
<tr>
|
|
||||||
<td>kcp {{ i18n "encryption" }}</td>
|
|
||||||
<td>
|
|
||||||
<a-tag>[[ inbound.kcpType ]]</a-tag>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>kcp {{ i18n "password" }}</td>
|
|
||||||
<td>
|
|
||||||
<a-tag>[[ inbound.kcpSeed ]]</a-tag>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</template>
|
|
||||||
<template v-if="inbound.isGrpc">
|
<template v-if="inbound.isGrpc">
|
||||||
<tr>
|
<tr>
|
||||||
<td>grpc serviceName</td>
|
<td>grpc serviceName</td>
|
||||||
<td>
|
<td>
|
||||||
<a-tooltip :title="[[ inbound.serviceName ]]">
|
<a-tooltip :title="[[ inbound.serviceName ]]">
|
||||||
<a-tag class="info-large-tag">[[ inbound.serviceName ]]</a-tag>
|
<a-tag class="info-large-tag">[[ inbound.serviceName
|
||||||
|
]]</a-tag>
|
||||||
</a-tooltip>
|
</a-tooltip>
|
||||||
<tr>
|
<tr>
|
||||||
<td>grpc multiMode</td>
|
<td>grpc multiMode</td>
|
||||||
|
|
@ -99,25 +91,34 @@
|
||||||
</a-col>
|
</a-col>
|
||||||
<template v-if="dbInbound.hasLink()">
|
<template v-if="dbInbound.hasLink()">
|
||||||
{{ i18n "security" }}
|
{{ i18n "security" }}
|
||||||
<a-tag :color="inbound.stream.security == 'none' ? 'red' : 'green'">[[ inbound.stream.security ]]</a-tag>
|
<a-tag :color="inbound.stream.security == 'none' ? 'red' : 'green'">[[
|
||||||
|
inbound.stream.security ]]</a-tag>
|
||||||
<br />
|
<br />
|
||||||
<td>Authentication</td>
|
<td>Authentication</td>
|
||||||
<a-tag v-if="inbound.settings.selectedAuth" color="green">[[ inbound.settings.selectedAuth ? inbound.settings.selectedAuth : '' ]]</a-tag>
|
<a-tag v-if="inbound.settings.selectedAuth" color="green">[[
|
||||||
|
inbound.settings.selectedAuth ? inbound.settings.selectedAuth : ''
|
||||||
|
]]</a-tag>
|
||||||
<a-tag v-else color="red">{{ i18n "none" }}</a-tag>
|
<a-tag v-else color="red">{{ i18n "none" }}</a-tag>
|
||||||
<br />
|
<br />
|
||||||
{{ i18n "encryption" }}
|
{{ i18n "encryption" }}
|
||||||
<a-tag class="info-large-tag" :color="inbound.settings.encryption ? 'green' : 'red'">[[ inbound.settings.encryption ? inbound.settings.encryption : '' ]]</a-tag>
|
<a-tag class="info-large-tag"
|
||||||
|
:color="inbound.settings.encryption ? 'green' : 'red'">[[
|
||||||
|
inbound.settings.encryption ? inbound.settings.encryption : ''
|
||||||
|
]]</a-tag>
|
||||||
<a-tooltip title='{{ i18n "copy" }}'>
|
<a-tooltip title='{{ i18n "copy" }}'>
|
||||||
<a-button size="small" icon="snippets" @click="copy(inbound.settings.encryption)"></a-button>
|
<a-button size="small" icon="snippets"
|
||||||
|
@click="copy(inbound.settings.encryption)"></a-button>
|
||||||
</a-tooltip>
|
</a-tooltip>
|
||||||
<br />
|
<br />
|
||||||
<template v-if="inbound.stream.security != 'none'">
|
<template v-if="inbound.stream.security != 'none'">
|
||||||
{{ i18n "domainName" }}
|
{{ i18n "domainName" }}
|
||||||
<a-tag v-if="inbound.serverName" color="green">[[ inbound.serverName ? inbound.serverName : '' ]]</a-tag>
|
<a-tag v-if="inbound.serverName" color="green">[[ inbound.serverName
|
||||||
|
? inbound.serverName : '' ]]</a-tag>
|
||||||
<a-tag v-else color="orange">{{ i18n "none" }}</a-tag>
|
<a-tag v-else color="orange">{{ i18n "none" }}</a-tag>
|
||||||
</template>
|
</template>
|
||||||
</template>
|
</template>
|
||||||
<table v-if="dbInbound.isSS" :style="{ marginBottom: '10px', width: '100%' }">
|
<table v-if="dbInbound.isSS"
|
||||||
|
:style="{ marginBottom: '10px', width: '100%' }">
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ i18n "encryption" }}</td>
|
<td>{{ i18n "encryption" }}</td>
|
||||||
<td>
|
<td>
|
||||||
|
|
@ -128,7 +129,8 @@
|
||||||
<td>{{ i18n "password" }}</td>
|
<td>{{ i18n "password" }}</td>
|
||||||
<td>
|
<td>
|
||||||
<a-tooltip :title="[[ inbound.settings.password ]]">
|
<a-tooltip :title="[[ inbound.settings.password ]]">
|
||||||
<a-tag class="info-large-tag">[[ inbound.settings.password ]]</a-tag>
|
<a-tag class="info-large-tag">[[ inbound.settings.password
|
||||||
|
]]</a-tag>
|
||||||
</a-tooltip>
|
</a-tooltip>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
@ -145,7 +147,8 @@
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ i18n "pages.inbounds.email" }}</td>
|
<td>{{ i18n "pages.inbounds.email" }}</td>
|
||||||
<td v-if="infoModal.clientSettings.email">
|
<td v-if="infoModal.clientSettings.email">
|
||||||
<a-tag color="green">[[ infoModal.clientSettings.email ]]</a-tag>
|
<a-tag color="green">[[ infoModal.clientSettings.email
|
||||||
|
]]</a-tag>
|
||||||
</td>
|
</td>
|
||||||
<td v-else>
|
<td v-else>
|
||||||
<a-tag color="red">{{ i18n "none" }}</a-tag>
|
<a-tag color="red">{{ i18n "none" }}</a-tag>
|
||||||
|
|
@ -176,30 +179,40 @@
|
||||||
<td>{{ i18n "password" }}</td>
|
<td>{{ i18n "password" }}</td>
|
||||||
<td>
|
<td>
|
||||||
<a-tooltip :title="[[ infoModal.clientSettings.password ]]">
|
<a-tooltip :title="[[ infoModal.clientSettings.password ]]">
|
||||||
<a-tag class="info-large-tag">[[ infoModal.clientSettings.password ]]</a-tag>
|
<a-tag class="info-large-tag">[[
|
||||||
|
infoModal.clientSettings.password ]]</a-tag>
|
||||||
</a-tooltip>
|
</a-tooltip>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ i18n "status" }}</td>
|
<td>{{ i18n "status" }}</td>
|
||||||
<td>
|
<td>
|
||||||
<a-tag v-if="isDepleted" color="red">{{ i18n "depleted" }}</a-tag>
|
<a-tag v-if="isDepleted" color="red">{{ i18n "depleted"
|
||||||
<a-tag v-else-if="isEnable" color="green">{{ i18n "enabled" }}</a-tag>
|
}}</a-tag>
|
||||||
|
<a-tag v-else-if="isEnable" color="green">{{ i18n "enabled"
|
||||||
|
}}</a-tag>
|
||||||
<a-tag v-else>{{ i18n "disabled" }}</a-tag>
|
<a-tag v-else>{{ i18n "disabled" }}</a-tag>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr v-if="infoModal.clientStats">
|
<tr v-if="infoModal.clientStats">
|
||||||
<td>{{ i18n "usage" }}</td>
|
<td>{{ i18n "usage" }}</td>
|
||||||
<td>
|
<td>
|
||||||
<a-tag color="green">[[ SizeFormatter.sizeFormat(infoModal.clientStats.up + infoModal.clientStats.down) ]]</a-tag>
|
<a-tag color="green">[[
|
||||||
<a-tag>↑ [[ SizeFormatter.sizeFormat(infoModal.clientStats.up) ]] / [[ SizeFormatter.sizeFormat(infoModal.clientStats.down) ]] ↓</a-tag>
|
SizeFormatter.sizeFormat(infoModal.clientStats.up +
|
||||||
|
infoModal.clientStats.down) ]]</a-tag>
|
||||||
|
<a-tag>↑ [[ SizeFormatter.sizeFormat(infoModal.clientStats.up)
|
||||||
|
]] / [[ SizeFormatter.sizeFormat(infoModal.clientStats.down)
|
||||||
|
]] ↓</a-tag>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ i18n "pages.inbounds.createdAt" }}</td>
|
<td>{{ i18n "pages.inbounds.createdAt" }}</td>
|
||||||
<td>
|
<td>
|
||||||
<template v-if="infoModal.clientSettings && infoModal.clientSettings.created_at">
|
<template
|
||||||
<a-tag>[[ IntlUtil.formatDate(infoModal.clientSettings.created_at) ]]</a-tag>
|
v-if="infoModal.clientSettings && infoModal.clientSettings.created_at">
|
||||||
|
<a-tag>[[
|
||||||
|
IntlUtil.formatDate(infoModal.clientSettings.created_at)
|
||||||
|
]]</a-tag>
|
||||||
</template>
|
</template>
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<a-tag>-</a-tag>
|
<a-tag>-</a-tag>
|
||||||
|
|
@ -209,8 +222,11 @@
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ i18n "pages.inbounds.updatedAt" }}</td>
|
<td>{{ i18n "pages.inbounds.updatedAt" }}</td>
|
||||||
<td>
|
<td>
|
||||||
<template v-if="infoModal.clientSettings && infoModal.clientSettings.updated_at">
|
<template
|
||||||
<a-tag>[[ IntlUtil.formatDate(infoModal.clientSettings.updated_at) ]]</a-tag>
|
v-if="infoModal.clientSettings && infoModal.clientSettings.updated_at">
|
||||||
|
<a-tag>[[
|
||||||
|
IntlUtil.formatDate(infoModal.clientSettings.updated_at)
|
||||||
|
]]</a-tag>
|
||||||
</template>
|
</template>
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<a-tag>-</a-tag>
|
<a-tag>-</a-tag>
|
||||||
|
|
@ -220,14 +236,17 @@
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ i18n "lastOnline" }}</td>
|
<td>{{ i18n "lastOnline" }}</td>
|
||||||
<td>
|
<td>
|
||||||
<a-tag>[[ app.formatLastOnline(infoModal.clientSettings && infoModal.clientSettings.email ? infoModal.clientSettings.email : '') ]]</a-tag>
|
<a-tag>[[ app.formatLastOnline(infoModal.clientSettings &&
|
||||||
|
infoModal.clientSettings.email ?
|
||||||
|
infoModal.clientSettings.email : '') ]]</a-tag>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr v-if="infoModal.clientSettings.comment">
|
<tr v-if="infoModal.clientSettings.comment">
|
||||||
<td>{{ i18n "comment" }}</td>
|
<td>{{ i18n "comment" }}</td>
|
||||||
<td>
|
<td>
|
||||||
<a-tooltip :title="[[ infoModal.clientSettings.comment ]]">
|
<a-tooltip :title="[[ infoModal.clientSettings.comment ]]">
|
||||||
<a-tag class="info-large-tag">[[ infoModal.clientSettings.comment ]]</a-tag>
|
<a-tag class="info-large-tag">[[
|
||||||
|
infoModal.clientSettings.comment ]]</a-tag>
|
||||||
</a-tooltip>
|
</a-tooltip>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
@ -237,11 +256,13 @@
|
||||||
<a-tag>[[ infoModal.clientSettings.limitIp ]]</a-tag>
|
<a-tag>[[ infoModal.clientSettings.limitIp ]]</a-tag>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr v-if="app.ipLimitEnable && infoModal.clientSettings.limitIp > 0">
|
<tr
|
||||||
|
v-if="app.ipLimitEnable && infoModal.clientSettings.limitIp > 0">
|
||||||
<td>{{ i18n "pages.inbounds.IPLimitlog" }}</td>
|
<td>{{ i18n "pages.inbounds.IPLimitlog" }}</td>
|
||||||
<td>
|
<td>
|
||||||
<a-tag>[[ infoModal.clientIps ]]</a-tag>
|
<a-tag>[[ infoModal.clientIps ]]</a-tag>
|
||||||
<a-icon type="sync" :spin="refreshing" @click="refreshIPs" :style="{ margin: '0 5px' }"></a-icon>
|
<a-icon type="sync" :spin="refreshing" @click="refreshIPs"
|
||||||
|
:style="{ margin: '0 5px' }"></a-icon>
|
||||||
<a-tooltip :title="[[ dbInbound.address ]]">
|
<a-tooltip :title="[[ dbInbound.address ]]">
|
||||||
<template slot="title">
|
<template slot="title">
|
||||||
<span>{{ i18n "pages.inbounds.IPLimitlogclear" }}</span>
|
<span>{{ i18n "pages.inbounds.IPLimitlogclear" }}</span>
|
||||||
|
|
@ -251,7 +272,8 @@
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
<table :style="{ display: 'inline-table', marginBlock: '10px', width: '100%', textAlign: 'center' }">
|
<table
|
||||||
|
:style="{ display: 'inline-table', marginBlock: '10px', width: '100%', textAlign: 'center' }">
|
||||||
<tr>
|
<tr>
|
||||||
<th>{{ i18n "remained" }}</th>
|
<th>{{ i18n "remained" }}</th>
|
||||||
<th>{{ i18n "pages.inbounds.totalFlow" }}</th>
|
<th>{{ i18n "pages.inbounds.totalFlow" }}</th>
|
||||||
|
|
@ -259,51 +281,73 @@
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<a-tag v-if="infoModal.clientStats && infoModal.clientSettings.totalGB > 0" :color="statsColor(infoModal.clientStats)"> [[ getRemStats() ]] </a-tag>
|
<a-tag
|
||||||
|
v-if="infoModal.clientStats && infoModal.clientSettings.totalGB > 0"
|
||||||
|
:color="statsColor(infoModal.clientStats)"> [[ getRemStats()
|
||||||
|
]] </a-tag>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<a-tag v-if="infoModal.clientSettings.totalGB > 0" :color="statsColor(infoModal.clientStats)"> [[ SizeFormatter.sizeFormat(infoModal.clientSettings.totalGB) ]] </a-tag>
|
<a-tag v-if="infoModal.clientSettings.totalGB > 0"
|
||||||
|
:color="statsColor(infoModal.clientStats)"> [[
|
||||||
|
SizeFormatter.sizeFormat(infoModal.clientSettings.totalGB) ]]
|
||||||
|
</a-tag>
|
||||||
<a-tag v-else color="purple" class="infinite-tag">
|
<a-tag v-else color="purple" class="infinite-tag">
|
||||||
<svg height="10px" width="14px" viewBox="0 0 640 512" fill="currentColor">
|
<svg height="10px" width="14px" viewBox="0 0 640 512"
|
||||||
<path d="M484.4 96C407 96 349.2 164.1 320 208.5C290.8 164.1 233 96 155.6 96C69.75 96 0 167.8 0 256s69.75 160 155.6 160C233.1 416 290.8 347.9 320 303.5C349.2 347.9 407 416 484.4 416C570.3 416 640 344.2 640 256S570.3 96 484.4 96zM155.6 368C96.25 368 48 317.8 48 256s48.25-112 107.6-112c67.75 0 120.5 82.25 137.1 112C276 285.8 223.4 368 155.6 368zM484.4 368c-67.75 0-120.5-82.25-137.1-112C364 226.2 416.6 144 484.4 144C543.8 144 592 194.2 592 256S543.8 368 484.4 368z" fill="currentColor"></path>
|
fill="currentColor">
|
||||||
|
<path
|
||||||
|
d="M484.4 96C407 96 349.2 164.1 320 208.5C290.8 164.1 233 96 155.6 96C69.75 96 0 167.8 0 256s69.75 160 155.6 160C233.1 416 290.8 347.9 320 303.5C349.2 347.9 407 416 484.4 416C570.3 416 640 344.2 640 256S570.3 96 484.4 96zM155.6 368C96.25 368 48 317.8 48 256s48.25-112 107.6-112c67.75 0 120.5 82.25 137.1 112C276 285.8 223.4 368 155.6 368zM484.4 368c-67.75 0-120.5-82.25-137.1-112C364 226.2 416.6 144 484.4 144C543.8 144 592 194.2 592 256S543.8 368 484.4 368z"
|
||||||
|
fill="currentColor"></path>
|
||||||
</svg>
|
</svg>
|
||||||
</a-tag>
|
</a-tag>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<template v-if="infoModal.clientSettings.expiryTime > 0">
|
<template v-if="infoModal.clientSettings.expiryTime > 0">
|
||||||
<a-tag :color="ColorUtils.usageColor(new Date().getTime(), app.expireDiff, infoModal.clientSettings.expiryTime)">
|
<a-tag
|
||||||
[[ IntlUtil.formatDate(infoModal.clientSettings.expiryTime) ]]
|
:color="ColorUtils.usageColor(new Date().getTime(), app.expireDiff, infoModal.clientSettings.expiryTime)">
|
||||||
|
[[ IntlUtil.formatDate(infoModal.clientSettings.expiryTime)
|
||||||
|
]]
|
||||||
</a-tag>
|
</a-tag>
|
||||||
</template>
|
</template>
|
||||||
<a-tag v-else-if="infoModal.clientSettings.expiryTime < 0" color="green">[[ infoModal.clientSettings.expiryTime / -86400000 ]] {{ i18n "pages.client.days" }}
|
<a-tag v-else-if="infoModal.clientSettings.expiryTime < 0"
|
||||||
|
color="green">[[ infoModal.clientSettings.expiryTime /
|
||||||
|
-86400000 ]] {{ i18n "pages.client.days" }}
|
||||||
</a-tag>
|
</a-tag>
|
||||||
<a-tag v-else color="purple" class="infinite-tag">
|
<a-tag v-else color="purple" class="infinite-tag">
|
||||||
<svg height="10px" width="14px" viewBox="0 0 640 512" fill="currentColor">
|
<svg height="10px" width="14px" viewBox="0 0 640 512"
|
||||||
<path d="M484.4 96C407 96 349.2 164.1 320 208.5C290.8 164.1 233 96 155.6 96C69.75 96 0 167.8 0 256s69.75 160 155.6 160C233.1 416 290.8 347.9 320 303.5C349.2 347.9 407 416 484.4 416C570.3 416 640 344.2 640 256S570.3 96 484.4 96zM155.6 368C96.25 368 48 317.8 48 256s48.25-112 107.6-112c67.75 0 120.5 82.25 137.1 112C276 285.8 223.4 368 155.6 368zM484.4 368c-67.75 0-120.5-82.25-137.1-112C364 226.2 416.6 144 484.4 144C543.8 144 592 194.2 592 256S543.8 368 484.4 368z" fill="currentColor"></path>
|
fill="currentColor">
|
||||||
|
<path
|
||||||
|
d="M484.4 96C407 96 349.2 164.1 320 208.5C290.8 164.1 233 96 155.6 96C69.75 96 0 167.8 0 256s69.75 160 155.6 160C233.1 416 290.8 347.9 320 303.5C349.2 347.9 407 416 484.4 416C570.3 416 640 344.2 640 256S570.3 96 484.4 96zM155.6 368C96.25 368 48 317.8 48 256s48.25-112 107.6-112c67.75 0 120.5 82.25 137.1 112C276 285.8 223.4 368 155.6 368zM484.4 368c-67.75 0-120.5-82.25-137.1-112C364 226.2 416.6 144 484.4 144C543.8 144 592 194.2 592 256S543.8 368 484.4 368z"
|
||||||
|
fill="currentColor"></path>
|
||||||
</svg>
|
</svg>
|
||||||
</a-tag>
|
</a-tag>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
<template v-if="app.subSettings.enable && infoModal.clientSettings.subId">
|
<template
|
||||||
|
v-if="app.subSettings.enable && infoModal.clientSettings.subId">
|
||||||
<a-divider>Subscription URL</a-divider>
|
<a-divider>Subscription URL</a-divider>
|
||||||
<tr-info-row class="tr-info-row">
|
<tr-info-row class="tr-info-row">
|
||||||
<tr-info-title class="tr-info-title">
|
<tr-info-title class="tr-info-title">
|
||||||
<a-tag color="purple">Subscription Link</a-tag>
|
<a-tag color="purple">Subscription Link</a-tag>
|
||||||
<a-tooltip title='{{ i18n "copy" }}'>
|
<a-tooltip title='{{ i18n "copy" }}'>
|
||||||
<a-button size="small" icon="snippets" @click="copy(infoModal.subLink)"></a-button>
|
<a-button size="small" icon="snippets"
|
||||||
|
@click="copy(infoModal.subLink)"></a-button>
|
||||||
</a-tooltip>
|
</a-tooltip>
|
||||||
</tr-info-title>
|
</tr-info-title>
|
||||||
<a :href="[[ infoModal.subLink ]]" target="_blank">[[ infoModal.subLink ]]</a>
|
<a :href="[[ infoModal.subLink ]]" target="_blank">[[
|
||||||
|
infoModal.subLink ]]</a>
|
||||||
</tr-info-row>
|
</tr-info-row>
|
||||||
<tr-info-row class="tr-info-row" v-if="app.subSettings.subJsonEnable">
|
<tr-info-row class="tr-info-row"
|
||||||
|
v-if="app.subSettings.subJsonEnable">
|
||||||
<tr-info-title class="tr-info-title">
|
<tr-info-title class="tr-info-title">
|
||||||
<a-tag color="purple">Json Link</a-tag>
|
<a-tag color="purple">Json Link</a-tag>
|
||||||
<a-tooltip title='{{ i18n "copy" }}'>
|
<a-tooltip title='{{ i18n "copy" }}'>
|
||||||
<a-button size="small" icon="snippets" @click="copy(infoModal.subJsonLink)"></a-button>
|
<a-button size="small" icon="snippets"
|
||||||
|
@click="copy(infoModal.subJsonLink)"></a-button>
|
||||||
</a-tooltip>
|
</a-tooltip>
|
||||||
</tr-info-title>
|
</tr-info-title>
|
||||||
<a :href="[[ infoModal.subJsonLink ]]" target="_blank">[[ infoModal.subJsonLink ]]</a>
|
<a :href="[[ infoModal.subJsonLink ]]" target="_blank">[[
|
||||||
|
infoModal.subJsonLink ]]</a>
|
||||||
</tr-info-row>
|
</tr-info-row>
|
||||||
</template>
|
</template>
|
||||||
<template v-if="app.tgBotEnable && infoModal.clientSettings.tgId">
|
<template v-if="app.tgBotEnable && infoModal.clientSettings.tgId">
|
||||||
|
|
@ -312,18 +356,22 @@
|
||||||
<tr-info-title class="tr-info-title">
|
<tr-info-title class="tr-info-title">
|
||||||
<a-tag color="blue">[[ infoModal.clientSettings.tgId ]]</a-tag>
|
<a-tag color="blue">[[ infoModal.clientSettings.tgId ]]</a-tag>
|
||||||
<a-tooltip title='{{ i18n "copy" }}'>
|
<a-tooltip title='{{ i18n "copy" }}'>
|
||||||
<a-button size="small" icon="snippets" @click="copy(infoModal.clientSettings.tgId)"></a-button>
|
<a-button size="small" icon="snippets"
|
||||||
|
@click="copy(infoModal.clientSettings.tgId)"></a-button>
|
||||||
</a-tooltip>
|
</a-tooltip>
|
||||||
</tr-info-title>
|
</tr-info-title>
|
||||||
</tr-info-row>
|
</tr-info-row>
|
||||||
</template>
|
</template>
|
||||||
<template v-if="dbInbound.hasLink()">
|
<template v-if="dbInbound.hasLink()">
|
||||||
<a-divider>URL</a-divider>
|
<a-divider>URL</a-divider>
|
||||||
<tr-info-row v-for="(link,index) in infoModal.links" class="tr-info-row">
|
<tr-info-row v-for="(link,index) in infoModal.links"
|
||||||
|
class="tr-info-row">
|
||||||
<tr-info-title class="tr-info-title">
|
<tr-info-title class="tr-info-title">
|
||||||
<a-tag class="tr-info-tag" color="green">[[ link.remark ]]</a-tag>
|
<a-tag class="tr-info-tag" color="green">[[ link.remark
|
||||||
|
]]</a-tag>
|
||||||
<a-tooltip title='{{ i18n "copy" }}'>
|
<a-tooltip title='{{ i18n "copy" }}'>
|
||||||
<a-button :style="{ minWidth: '24px' }" size="small" icon="snippets" @click="copy(link.link)"></a-button>
|
<a-button :style="{ minWidth: '24px' }" size="small"
|
||||||
|
icon="snippets" @click="copy(link.link)"></a-button>
|
||||||
</a-tooltip>
|
</a-tooltip>
|
||||||
</tr-info-title>
|
</tr-info-title>
|
||||||
<code>[[ link.link ]]</code>
|
<code>[[ link.link ]]</code>
|
||||||
|
|
@ -333,17 +381,21 @@
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<template v-if="dbInbound.isSS && !inbound.isSSMultiUser">
|
<template v-if="dbInbound.isSS && !inbound.isSSMultiUser">
|
||||||
<a-divider>URL</a-divider>
|
<a-divider>URL</a-divider>
|
||||||
<tr-info-row v-for="(link,index) in infoModal.links" class="tr-info-row">
|
<tr-info-row v-for="(link,index) in infoModal.links"
|
||||||
|
class="tr-info-row">
|
||||||
<tr-info-title class="tr-info-title">
|
<tr-info-title class="tr-info-title">
|
||||||
<a-tag class="tr-info-tag" color="green">[[ link.remark ]]</a-tag>
|
<a-tag class="tr-info-tag" color="green">[[ link.remark
|
||||||
|
]]</a-tag>
|
||||||
<a-tooltip title='{{ i18n "copy" }}'>
|
<a-tooltip title='{{ i18n "copy" }}'>
|
||||||
<a-button :style="{ minWidth: '24px' }" size="small" icon="snippets" @click="copy(link.link)"></a-button>
|
<a-button :style="{ minWidth: '24px' }" size="small"
|
||||||
|
icon="snippets" @click="copy(link.link)"></a-button>
|
||||||
</a-tooltip>
|
</a-tooltip>
|
||||||
</tr-info-title>
|
</tr-info-title>
|
||||||
<code>[[ link.link ]]</code>
|
<code>[[ link.link ]]</code>
|
||||||
</tr-info-row>
|
</tr-info-row>
|
||||||
</template>
|
</template>
|
||||||
<table v-if="inbound.protocol == Protocols.TUNNEL" class="tr-info-table">
|
<table v-if="inbound.protocol == Protocols.TUNNEL"
|
||||||
|
class="tr-info-table">
|
||||||
<tr>
|
<tr>
|
||||||
<th>{{ i18n "pages.inbounds.targetAddress" }}</th>
|
<th>{{ i18n "pages.inbounds.targetAddress" }}</th>
|
||||||
<th>{{ i18n "pages.inbounds.destinationPort" }}</th>
|
<th>{{ i18n "pages.inbounds.destinationPort" }}</th>
|
||||||
|
|
@ -361,7 +413,8 @@
|
||||||
<a-tag color="green">[[ inbound.settings.network ]]</a-tag>
|
<a-tag color="green">[[ inbound.settings.network ]]</a-tag>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<a-tag color="green">[[ inbound.settings.followRedirect ]]</a-tag>
|
<a-tag color="green">[[ inbound.settings.followRedirect
|
||||||
|
]]</a-tag>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
@ -464,13 +517,20 @@
|
||||||
<tr-info-title class="tr-info-title">
|
<tr-info-title class="tr-info-title">
|
||||||
<a-tag color="blue">Config</a-tag>
|
<a-tag color="blue">Config</a-tag>
|
||||||
<a-tooltip title='{{ i18n "copy" }}'>
|
<a-tooltip title='{{ i18n "copy" }}'>
|
||||||
<a-button :style="{ minWidth: '24px' }" size="small" icon="snippets" @click="copy(infoModal.links[index])"></a-button>
|
<a-button :style="{ minWidth: '24px' }" size="small"
|
||||||
|
icon="snippets"
|
||||||
|
@click="copy(infoModal.links[index])"></a-button>
|
||||||
</a-tooltip>
|
</a-tooltip>
|
||||||
<a-tooltip title='{{ i18n "download" }}'>
|
<a-tooltip title='{{ i18n "download" }}'>
|
||||||
<a-button :style="{ minWidth: '24px' }" size="small" icon="download" @click="FileManager.downloadTextFile(infoModal.links[index], `peer-${index + 1}.conf`)"></a-button>
|
<a-button :style="{ minWidth: '24px' }" size="small"
|
||||||
|
icon="download"
|
||||||
|
@click="FileManager.downloadTextFile(infoModal.links[index], `peer-${index + 1}.conf`)"></a-button>
|
||||||
</a-tooltip>
|
</a-tooltip>
|
||||||
</tr-info-title>
|
</tr-info-title>
|
||||||
<div v-html="infoModal.links[index].replaceAll(`\n`,`<br />`)" :style="{ borderRadius: '1rem', padding: '0.5rem' }" class="client-table-odd-row">
|
<div
|
||||||
|
v-html="infoModal.links[index].replaceAll(`\n`,`<br />`)"
|
||||||
|
:style="{ borderRadius: '1rem', padding: '0.5rem' }"
|
||||||
|
class="client-table-odd-row">
|
||||||
</div>
|
</div>
|
||||||
</tr-info-row>
|
</tr-info-row>
|
||||||
</td>
|
</td>
|
||||||
|
|
|
||||||
|
|
@ -219,14 +219,14 @@
|
||||||
rule = {};
|
rule = {};
|
||||||
newRule = {};
|
newRule = {};
|
||||||
rule.type = "field";
|
rule.type = "field";
|
||||||
rule.domain = value.domain.length > 0 ? value.domain.split(',') : [];
|
rule.domain = value.domain.length > 0 ? value.domain.split(',').map(s => s.trim()) : [];
|
||||||
rule.ip = value.ip.length > 0 ? value.ip.split(',') : [];
|
rule.ip = value.ip.length > 0 ? value.ip.split(',').map(s => s.trim()) : [];
|
||||||
rule.port = value.port;
|
rule.port = value.port;
|
||||||
rule.sourcePort = value.sourcePort;
|
rule.sourcePort = value.sourcePort;
|
||||||
rule.vlessRoute = value.vlessRoute;
|
rule.vlessRoute = value.vlessRoute;
|
||||||
rule.network = value.network;
|
rule.network = value.network;
|
||||||
rule.sourceIP = value.sourceIP.length > 0 ? value.sourceIP.split(',') : [];
|
rule.sourceIP = value.sourceIP.length > 0 ? value.sourceIP.split(',').map(s => s.trim()) : [];
|
||||||
rule.user = value.user.length > 0 ? value.user.split(',') : [];
|
rule.user = value.user.length > 0 ? value.user.split(',').map(s => s.trim()) : [];
|
||||||
rule.inboundTag = value.inboundTag;
|
rule.inboundTag = value.inboundTag;
|
||||||
rule.protocol = value.protocol;
|
rule.protocol = value.protocol;
|
||||||
rule.attrs = Object.fromEntries(value.attrs);
|
rule.attrs = Object.fromEntries(value.attrs);
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package job
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
|
@ -10,6 +11,7 @@ import (
|
||||||
"regexp"
|
"regexp"
|
||||||
"runtime"
|
"runtime"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/mhsanaei/3x-ui/v2/database"
|
"github.com/mhsanaei/3x-ui/v2/database"
|
||||||
|
|
@ -18,6 +20,12 @@ import (
|
||||||
"github.com/mhsanaei/3x-ui/v2/xray"
|
"github.com/mhsanaei/3x-ui/v2/xray"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// IPWithTimestamp tracks an IP address with its last seen timestamp
|
||||||
|
type IPWithTimestamp struct {
|
||||||
|
IP string `json:"ip"`
|
||||||
|
Timestamp int64 `json:"timestamp"`
|
||||||
|
}
|
||||||
|
|
||||||
// CheckClientIpJob monitors client IP addresses from access logs and manages IP blocking based on configured limits.
|
// CheckClientIpJob monitors client IP addresses from access logs and manages IP blocking based on configured limits.
|
||||||
type CheckClientIpJob struct {
|
type CheckClientIpJob struct {
|
||||||
lastClear int64
|
lastClear int64
|
||||||
|
|
@ -119,12 +127,14 @@ func (j *CheckClientIpJob) processLogFile() bool {
|
||||||
|
|
||||||
ipRegex := regexp.MustCompile(`from (?:tcp:|udp:)?\[?([0-9a-fA-F\.:]+)\]?:\d+ accepted`)
|
ipRegex := regexp.MustCompile(`from (?:tcp:|udp:)?\[?([0-9a-fA-F\.:]+)\]?:\d+ accepted`)
|
||||||
emailRegex := regexp.MustCompile(`email: (.+)$`)
|
emailRegex := regexp.MustCompile(`email: (.+)$`)
|
||||||
|
timestampRegex := regexp.MustCompile(`^(\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2})`)
|
||||||
|
|
||||||
accessLogPath, _ := xray.GetAccessLogPath()
|
accessLogPath, _ := xray.GetAccessLogPath()
|
||||||
file, _ := os.Open(accessLogPath)
|
file, _ := os.Open(accessLogPath)
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
|
||||||
inboundClientIps := make(map[string]map[string]struct{}, 100)
|
// Track IPs with their last seen timestamp
|
||||||
|
inboundClientIps := make(map[string]map[string]int64, 100)
|
||||||
|
|
||||||
scanner := bufio.NewScanner(file)
|
scanner := bufio.NewScanner(file)
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
|
|
@ -147,28 +157,45 @@ func (j *CheckClientIpJob) processLogFile() bool {
|
||||||
}
|
}
|
||||||
email := emailMatches[1]
|
email := emailMatches[1]
|
||||||
|
|
||||||
if _, exists := inboundClientIps[email]; !exists {
|
// Extract timestamp from log line
|
||||||
inboundClientIps[email] = make(map[string]struct{})
|
var timestamp int64
|
||||||
|
timestampMatches := timestampRegex.FindStringSubmatch(line)
|
||||||
|
if len(timestampMatches) >= 2 {
|
||||||
|
t, err := time.Parse("2006/01/02 15:04:05", timestampMatches[1])
|
||||||
|
if err == nil {
|
||||||
|
timestamp = t.Unix()
|
||||||
|
} else {
|
||||||
|
timestamp = time.Now().Unix()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
timestamp = time.Now().Unix()
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, exists := inboundClientIps[email]; !exists {
|
||||||
|
inboundClientIps[email] = make(map[string]int64)
|
||||||
|
}
|
||||||
|
// Update timestamp - keep the latest
|
||||||
|
if existingTime, ok := inboundClientIps[email][ip]; !ok || timestamp > existingTime {
|
||||||
|
inboundClientIps[email][ip] = timestamp
|
||||||
}
|
}
|
||||||
inboundClientIps[email][ip] = struct{}{}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
shouldCleanLog := false
|
shouldCleanLog := false
|
||||||
for email, uniqueIps := range inboundClientIps {
|
for email, ipTimestamps := range inboundClientIps {
|
||||||
|
|
||||||
ips := make([]string, 0, len(uniqueIps))
|
// Convert to IPWithTimestamp slice
|
||||||
for ip := range uniqueIps {
|
ipsWithTime := make([]IPWithTimestamp, 0, len(ipTimestamps))
|
||||||
ips = append(ips, ip)
|
for ip, timestamp := range ipTimestamps {
|
||||||
|
ipsWithTime = append(ipsWithTime, IPWithTimestamp{IP: ip, Timestamp: timestamp})
|
||||||
}
|
}
|
||||||
sort.Strings(ips)
|
|
||||||
|
|
||||||
clientIpsRecord, err := j.getInboundClientIps(email)
|
clientIpsRecord, err := j.getInboundClientIps(email)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
j.addInboundClientIps(email, ips)
|
j.addInboundClientIps(email, ipsWithTime)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
shouldCleanLog = j.updateInboundClientIps(clientIpsRecord, email, ips) || shouldCleanLog
|
shouldCleanLog = j.updateInboundClientIps(clientIpsRecord, email, ipsWithTime) || shouldCleanLog
|
||||||
}
|
}
|
||||||
|
|
||||||
return shouldCleanLog
|
return shouldCleanLog
|
||||||
|
|
@ -213,9 +240,9 @@ func (j *CheckClientIpJob) getInboundClientIps(clientEmail string) (*model.Inbou
|
||||||
return InboundClientIps, nil
|
return InboundClientIps, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *CheckClientIpJob) addInboundClientIps(clientEmail string, ips []string) error {
|
func (j *CheckClientIpJob) addInboundClientIps(clientEmail string, ipsWithTime []IPWithTimestamp) error {
|
||||||
inboundClientIps := &model.InboundClientIps{}
|
inboundClientIps := &model.InboundClientIps{}
|
||||||
jsonIps, err := json.Marshal(ips)
|
jsonIps, err := json.Marshal(ipsWithTime)
|
||||||
j.checkError(err)
|
j.checkError(err)
|
||||||
|
|
||||||
inboundClientIps.ClientEmail = clientEmail
|
inboundClientIps.ClientEmail = clientEmail
|
||||||
|
|
@ -239,16 +266,8 @@ func (j *CheckClientIpJob) addInboundClientIps(clientEmail string, ips []string)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *CheckClientIpJob) updateInboundClientIps(inboundClientIps *model.InboundClientIps, clientEmail string, ips []string) bool {
|
func (j *CheckClientIpJob) updateInboundClientIps(inboundClientIps *model.InboundClientIps, clientEmail string, newIpsWithTime []IPWithTimestamp) bool {
|
||||||
jsonIps, err := json.Marshal(ips)
|
// Get the inbound configuration
|
||||||
if err != nil {
|
|
||||||
logger.Error("failed to marshal IPs to JSON:", err)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
inboundClientIps.ClientEmail = clientEmail
|
|
||||||
inboundClientIps.Ips = string(jsonIps)
|
|
||||||
|
|
||||||
inbound, err := j.getInboundByEmail(clientEmail)
|
inbound, err := j.getInboundByEmail(clientEmail)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Errorf("failed to fetch inbound settings for email %s: %s", clientEmail, err)
|
logger.Errorf("failed to fetch inbound settings for email %s: %s", clientEmail, err)
|
||||||
|
|
@ -263,9 +282,57 @@ func (j *CheckClientIpJob) updateInboundClientIps(inboundClientIps *model.Inboun
|
||||||
settings := map[string][]model.Client{}
|
settings := map[string][]model.Client{}
|
||||||
json.Unmarshal([]byte(inbound.Settings), &settings)
|
json.Unmarshal([]byte(inbound.Settings), &settings)
|
||||||
clients := settings["clients"]
|
clients := settings["clients"]
|
||||||
|
|
||||||
|
// Find the client's IP limit
|
||||||
|
var limitIp int
|
||||||
|
var clientFound bool
|
||||||
|
for _, client := range clients {
|
||||||
|
if client.Email == clientEmail {
|
||||||
|
limitIp = client.LimitIP
|
||||||
|
clientFound = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !clientFound || limitIp <= 0 || !inbound.Enable {
|
||||||
|
// No limit or inbound disabled, just update and return
|
||||||
|
jsonIps, _ := json.Marshal(newIpsWithTime)
|
||||||
|
inboundClientIps.Ips = string(jsonIps)
|
||||||
|
db := database.GetDB()
|
||||||
|
db.Save(inboundClientIps)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse old IPs from database
|
||||||
|
var oldIpsWithTime []IPWithTimestamp
|
||||||
|
if inboundClientIps.Ips != "" {
|
||||||
|
json.Unmarshal([]byte(inboundClientIps.Ips), &oldIpsWithTime)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Merge old and new IPs, keeping the latest timestamp for each IP
|
||||||
|
ipMap := make(map[string]int64)
|
||||||
|
for _, ipTime := range oldIpsWithTime {
|
||||||
|
ipMap[ipTime.IP] = ipTime.Timestamp
|
||||||
|
}
|
||||||
|
for _, ipTime := range newIpsWithTime {
|
||||||
|
if existingTime, ok := ipMap[ipTime.IP]; !ok || ipTime.Timestamp > existingTime {
|
||||||
|
ipMap[ipTime.IP] = ipTime.Timestamp
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert back to slice and sort by timestamp (newest first)
|
||||||
|
allIps := make([]IPWithTimestamp, 0, len(ipMap))
|
||||||
|
for ip, timestamp := range ipMap {
|
||||||
|
allIps = append(allIps, IPWithTimestamp{IP: ip, Timestamp: timestamp})
|
||||||
|
}
|
||||||
|
sort.Slice(allIps, func(i, j int) bool {
|
||||||
|
return allIps[i].Timestamp > allIps[j].Timestamp // Descending order (newest first)
|
||||||
|
})
|
||||||
|
|
||||||
shouldCleanLog := false
|
shouldCleanLog := false
|
||||||
j.disAllowedIps = []string{}
|
j.disAllowedIps = []string{}
|
||||||
|
|
||||||
|
// Open log file
|
||||||
logIpFile, err := os.OpenFile(xray.GetIPLimitLogPath(), os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644)
|
logIpFile, err := os.OpenFile(xray.GetIPLimitLogPath(), os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Errorf("failed to open IP limit log file: %s", err)
|
logger.Errorf("failed to open IP limit log file: %s", err)
|
||||||
|
|
@ -275,27 +342,33 @@ func (j *CheckClientIpJob) updateInboundClientIps(inboundClientIps *model.Inboun
|
||||||
log.SetOutput(logIpFile)
|
log.SetOutput(logIpFile)
|
||||||
log.SetFlags(log.LstdFlags)
|
log.SetFlags(log.LstdFlags)
|
||||||
|
|
||||||
for _, client := range clients {
|
// Check if we exceed the limit
|
||||||
if client.Email == clientEmail {
|
if len(allIps) > limitIp {
|
||||||
limitIp := client.LimitIP
|
|
||||||
|
|
||||||
if limitIp > 0 && inbound.Enable {
|
|
||||||
shouldCleanLog = true
|
shouldCleanLog = true
|
||||||
|
|
||||||
if limitIp < len(ips) {
|
// Keep only the newest IPs (up to limitIp)
|
||||||
j.disAllowedIps = append(j.disAllowedIps, ips[limitIp:]...)
|
keptIps := allIps[:limitIp]
|
||||||
for i := limitIp; i < len(ips); i++ {
|
disconnectedIps := allIps[limitIp:]
|
||||||
log.Printf("[LIMIT_IP] Email = %s || SRC = %s", clientEmail, ips[i])
|
|
||||||
}
|
// Log the disconnected IPs (old ones)
|
||||||
}
|
for _, ipTime := range disconnectedIps {
|
||||||
}
|
j.disAllowedIps = append(j.disAllowedIps, ipTime.IP)
|
||||||
}
|
log.Printf("[LIMIT_IP] Email = %s || Disconnecting OLD IP = %s || Timestamp = %d", clientEmail, ipTime.IP, ipTime.Timestamp)
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.Strings(j.disAllowedIps)
|
// Actually disconnect old IPs by temporarily removing and re-adding user
|
||||||
|
// This forces Xray to drop existing connections from old IPs
|
||||||
|
if len(disconnectedIps) > 0 {
|
||||||
|
j.disconnectClientTemporarily(inbound, clientEmail, clients)
|
||||||
|
}
|
||||||
|
|
||||||
if len(j.disAllowedIps) > 0 {
|
// Update database with only the newest IPs
|
||||||
logger.Debug("disAllowedIps:", j.disAllowedIps)
|
jsonIps, _ := json.Marshal(keptIps)
|
||||||
|
inboundClientIps.Ips = string(jsonIps)
|
||||||
|
} else {
|
||||||
|
// Under limit, save all IPs
|
||||||
|
jsonIps, _ := json.Marshal(allIps)
|
||||||
|
inboundClientIps.Ips = string(jsonIps)
|
||||||
}
|
}
|
||||||
|
|
||||||
db := database.GetDB()
|
db := database.GetDB()
|
||||||
|
|
@ -305,9 +378,68 @@ func (j *CheckClientIpJob) updateInboundClientIps(inboundClientIps *model.Inboun
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(j.disAllowedIps) > 0 {
|
||||||
|
logger.Infof("[LIMIT_IP] Client %s: Kept %d newest IPs, disconnected %d old IPs", clientEmail, limitIp, len(j.disAllowedIps))
|
||||||
|
}
|
||||||
|
|
||||||
return shouldCleanLog
|
return shouldCleanLog
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// disconnectClientTemporarily removes and re-adds a client to force disconnect old connections
|
||||||
|
func (j *CheckClientIpJob) disconnectClientTemporarily(inbound *model.Inbound, clientEmail string, clients []model.Client) {
|
||||||
|
var xrayAPI xray.XrayAPI
|
||||||
|
|
||||||
|
// Get panel settings for API port
|
||||||
|
db := database.GetDB()
|
||||||
|
var apiPort int
|
||||||
|
var apiPortSetting model.Setting
|
||||||
|
if err := db.Where("key = ?", "xrayApiPort").First(&apiPortSetting).Error; err == nil {
|
||||||
|
apiPort, _ = strconv.Atoi(apiPortSetting.Value)
|
||||||
|
}
|
||||||
|
|
||||||
|
if apiPort == 0 {
|
||||||
|
apiPort = 10085 // Default API port
|
||||||
|
}
|
||||||
|
|
||||||
|
err := xrayAPI.Init(apiPort)
|
||||||
|
if err != nil {
|
||||||
|
logger.Warningf("[LIMIT_IP] Failed to init Xray API for disconnection: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer xrayAPI.Close()
|
||||||
|
|
||||||
|
// Find the client config
|
||||||
|
var clientConfig map[string]any
|
||||||
|
for _, client := range clients {
|
||||||
|
if client.Email == clientEmail {
|
||||||
|
// Convert client to map for API
|
||||||
|
clientBytes, _ := json.Marshal(client)
|
||||||
|
json.Unmarshal(clientBytes, &clientConfig)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if clientConfig == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove user to disconnect all connections
|
||||||
|
err = xrayAPI.RemoveUser(inbound.Tag, clientEmail)
|
||||||
|
if err != nil {
|
||||||
|
logger.Warningf("[LIMIT_IP] Failed to remove user %s: %v", clientEmail, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait a moment for disconnection to take effect
|
||||||
|
time.Sleep(100 * time.Millisecond)
|
||||||
|
|
||||||
|
// Re-add user to allow new connections
|
||||||
|
err = xrayAPI.AddUser(string(inbound.Protocol), inbound.Tag, clientConfig)
|
||||||
|
if err != nil {
|
||||||
|
logger.Warningf("[LIMIT_IP] Failed to re-add user %s: %v", clientEmail, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (j *CheckClientIpJob) getInboundByEmail(clientEmail string) (*model.Inbound, error) {
|
func (j *CheckClientIpJob) getInboundByEmail(clientEmail string) (*model.Inbound, error) {
|
||||||
db := database.GetDB()
|
db := database.GetDB()
|
||||||
inbound := &model.Inbound{}
|
inbound := &model.Inbound{}
|
||||||
|
|
|
||||||
|
|
@ -1087,13 +1087,60 @@ func (s *ServerService) UpdateGeofile(fileName string) error {
|
||||||
return common.NewErrorf("Invalid geofile name: %s not in allowlist", fileName)
|
return common.NewErrorf("Invalid geofile name: %s not in allowlist", fileName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
downloadFile := func(url, destPath string) error {
|
downloadFile := func(url, destPath string) error {
|
||||||
resp, err := http.Get(url)
|
var req *http.Request
|
||||||
|
req, err := http.NewRequest("GET", url, nil)
|
||||||
|
if err != nil {
|
||||||
|
return common.NewErrorf("Failed to create HTTP request for %s: %v", url, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var localFileModTime time.Time
|
||||||
|
if fileInfo, err := os.Stat(destPath); err == nil {
|
||||||
|
localFileModTime = fileInfo.ModTime()
|
||||||
|
if !localFileModTime.IsZero() {
|
||||||
|
req.Header.Set("If-Modified-Since", localFileModTime.UTC().Format(http.TimeFormat))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
client := &http.Client{}
|
||||||
|
resp, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return common.NewErrorf("Failed to download Geofile from %s: %v", url, err)
|
return common.NewErrorf("Failed to download Geofile from %s: %v", url, err)
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
// Parse Last-Modified header from server
|
||||||
|
var serverModTime time.Time
|
||||||
|
serverModTimeStr := resp.Header.Get("Last-Modified")
|
||||||
|
if serverModTimeStr != "" {
|
||||||
|
parsedTime, err := time.Parse(http.TimeFormat, serverModTimeStr)
|
||||||
|
if err != nil {
|
||||||
|
logger.Warningf("Failed to parse Last-Modified header for %s: %v", url, err)
|
||||||
|
} else {
|
||||||
|
serverModTime = parsedTime
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Function to update local file's modification time
|
||||||
|
updateFileModTime := func() {
|
||||||
|
if !serverModTime.IsZero() {
|
||||||
|
if err := os.Chtimes(destPath, serverModTime, serverModTime); err != nil {
|
||||||
|
logger.Warningf("Failed to update modification time for %s: %v", destPath, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle 304 Not Modified
|
||||||
|
if resp.StatusCode == http.StatusNotModified {
|
||||||
|
updateFileModTime()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
return common.NewErrorf("Failed to download Geofile from %s: received status code %d", url, resp.StatusCode)
|
||||||
|
}
|
||||||
|
|
||||||
file, err := os.Create(destPath)
|
file, err := os.Create(destPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return common.NewErrorf("Failed to create Geofile %s: %v", destPath, err)
|
return common.NewErrorf("Failed to create Geofile %s: %v", destPath, err)
|
||||||
|
|
@ -1105,6 +1152,7 @@ func (s *ServerService) UpdateGeofile(fileName string) error {
|
||||||
return common.NewErrorf("Failed to save Geofile %s: %v", destPath, err)
|
return common.NewErrorf("Failed to save Geofile %s: %v", destPath, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateFileModTime()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1114,7 +1162,6 @@ func (s *ServerService) UpdateGeofile(fileName string) error {
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
// Sanitize the filename from our allowlist as an extra precaution
|
// Sanitize the filename from our allowlist as an extra precaution
|
||||||
destPath := filepath.Join(config.GetBinFolderPath(), filepath.Base(file.FileName))
|
destPath := filepath.Join(config.GetBinFolderPath(), filepath.Base(file.FileName))
|
||||||
|
|
||||||
if err := downloadFile(file.URL, destPath); err != nil {
|
if err := downloadFile(file.URL, destPath); err != nil {
|
||||||
errorMessages = append(errorMessages, fmt.Sprintf("Error downloading Geofile '%s': %v", file.FileName, err))
|
errorMessages = append(errorMessages, fmt.Sprintf("Error downloading Geofile '%s': %v", file.FileName, err))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue