Compare commits
233 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 840a28e072 | |||
| 29283ce83b | |||
| 3fd2cf05bb | |||
| 1ac7bce6b4 | |||
| 4865072f55 | |||
| 7faa28a89d | |||
| f4b1b09362 | |||
| c97467da3c | |||
| cde8eb100e | |||
| 20520552c2 | |||
| e380cb888f | |||
| 24a3e7b0da | |||
| b6c16e1bdf | |||
| 5da87cf14d | |||
| 1edd9d4323 | |||
| ce968d20ac | |||
| 60c64bab18 | |||
| f3432b119c | |||
| 049cfc5287 | |||
| 891a61ac16 | |||
| a0dc165995 | |||
| 4dc02f783a | |||
| 1282d67640 | |||
| f116e7f5ea | |||
| d06b6be4a2 | |||
| b43a6ade97 | |||
| f18345b30d | |||
| 67582015d3 | |||
| 94473b40de | |||
| 7e41af0da8 | |||
| 88adcc7c9a | |||
| 8fb5d3964a | |||
| 3d92431269 | |||
| f06840eaea | |||
| 906769e21a | |||
| 3641bbe25f | |||
| a39a669d75 | |||
| 9f6771ec09 | |||
| 13da0b59a9 | |||
| 5713f97e42 | |||
| 7621b7a348 | |||
| 9e63944d83 | |||
| 8c9736cf19 | |||
| 5e626f7c18 | |||
| eb4c128350 | |||
| 99f555dc95 | |||
| d53d9b80f5 | |||
| 2d8b56208d | |||
| f2605a550f | |||
| e92cf56557 | |||
| 8073e8ab0a | |||
| 8bab127f19 | |||
| a77964afc0 | |||
| b2195b72b9 | |||
| 5dd0baad34 | |||
| d86adedd8b | |||
| a6dc0cc589 | |||
| 751066ac6c | |||
| dbee22b637 | |||
| 56710aef1e | |||
| 753d1f9256 | |||
| fe428ed412 | |||
| ed48cdca33 | |||
| 7a047daf6f | |||
| ecd9348a0f | |||
| f1b6c8a131 | |||
| 056c458753 | |||
| 572268e9f6 | |||
| 0101e342a0 | |||
| 8b663df1ee | |||
| 4649bd42ae | |||
| e89ac96885 | |||
| fe5b6cf922 | |||
| 42f24c45c9 | |||
| 282e244517 | |||
| 1d46d72186 | |||
| 7554b02a61 | |||
| fecb29f6ab | |||
| 7b7e5ac79d | |||
| e5fc14efd4 | |||
| 837150e065 | |||
| 93868b02d4 | |||
| 50d1177443 | |||
| d255905907 | |||
| 5f3963ff1c | |||
| bc6f356789 | |||
| 119cff3d85 | |||
| 90b2876867 | |||
| 5105c138f7 | |||
| b019633c3f | |||
| 419cce250f | |||
| bdc458dfa9 | |||
| 3dff49d6e4 | |||
| 47e3c6944a | |||
| 54e48c8c76 | |||
| 9c7814a765 | |||
| 6a174cf4db | |||
| 19e060ad33 | |||
| 5c09bc011e | |||
| f6f90b07d3 | |||
| 2da30dc596 | |||
| bdad92fe01 | |||
| 5ddee6aa12 | |||
| 6f0df2d555 | |||
| 0bb3a67f79 | |||
| 869c51885f | |||
| 7b58edeaaf | |||
| e287ced0e4 | |||
| c518bf5a86 | |||
| 89b85f818d | |||
| ea3ad15b76 | |||
| 5cc3791f79 | |||
| eef7e200ba | |||
| 39022c1b2d | |||
| 2b6874a58d | |||
| 1631ac0c30 | |||
| d70006cd91 | |||
| 19901efeaa | |||
| b2d0134567 | |||
| 58f4a676b5 | |||
| 7904cb3db0 | |||
| 6222533594 | |||
| cb4a7fe6df | |||
| 96564f1f86 | |||
| cf6b61fe96 | |||
| e1aaa3d748 | |||
| 209561497a | |||
| 60b374e5d4 | |||
| ea8538148f | |||
| b3a2078ed6 | |||
| f169064fbc | |||
| 7d441723ba | |||
| a41140190f | |||
| bb5cd91bc9 | |||
| 5b6f6daaa8 | |||
| ba06ad598d | |||
| 69725ee5af | |||
| 0d36b811dc | |||
| 6672a2721f | |||
| 6b24506ddd | |||
| 3298fd4e0d | |||
| 6dc7c93030 | |||
| 7c127f07bb | |||
| b5a2dd18f5 | |||
| 53ed86c373 | |||
| ccbd591b39 | |||
| f5792c9d82 | |||
| 4a2ac30a95 | |||
| 45b03d8472 | |||
| db3270feaa | |||
| b144aecb6a | |||
| 474e5156bb | |||
| d057076251 | |||
| 29cc6fd3e3 | |||
| dd0f770c1a | |||
| 8e369535bf | |||
| 6a5e0a940b | |||
| 3b24819309 | |||
| b5920cdc07 | |||
| cf620962bb | |||
| 17f1126c23 | |||
| 16203fdece | |||
| 12fe21906e | |||
| 1b9d5e9378 | |||
| c152a977c6 | |||
| 341baf69de | |||
| dedd4b3ee3 | |||
| bfbf9777e9 | |||
| 2cabf0aefb | |||
| c994f4b24a | |||
| f136229539 | |||
| 40fbb22b74 | |||
| 9547038164 | |||
| aca870e78f | |||
| dbf01c2086 | |||
| c3debcec5a | |||
| c179bf8a37 | |||
| 21add1f3ce | |||
| 9968f3885f | |||
| 2ac13ef8f4 | |||
| 4900c14295 | |||
| 55a6d78114 | |||
| caa115bbe3 | |||
| e3be3be9d9 | |||
| 988675a7a7 | |||
| 458f0c20da | |||
| f8fbc3c329 | |||
| 89bc3b5b23 | |||
| edfe0c86e7 | |||
| 6865c8b49d | |||
| 07947c9665 | |||
| 09616b6fac | |||
| 15105710bc | |||
| c88fb45e27 | |||
| 4f7a90b7dd | |||
| cc45e8de20 | |||
| 5805e397af | |||
| db36756515 | |||
| 609132a5b1 | |||
| c0aef193ea | |||
| 7d39252fec | |||
| b4fcec9477 | |||
| 8e2023ee66 | |||
| 8b6cd88625 | |||
| 8272285fe5 | |||
| cb606828ff | |||
| 70c986662f | |||
| bf7b42ec20 | |||
| 43d1aecec7 | |||
| 9a02e6593c | |||
| abb869c75b | |||
| fa922291ea | |||
| ae7fa7285f | |||
| a0e437a549 | |||
| 3d263d500f | |||
| c1c05c4863 | |||
| af2861f2c9 | |||
| 39ad029e20 | |||
| f545bcb30c | |||
| 819d74cf10 | |||
| 68ed8d120f | |||
| 5b804eb149 | |||
| 6a6d7d7c1a | |||
| 5726e64b9f | |||
| 52db4e5332 | |||
| b673fd9032 | |||
| e80519eac0 | |||
| 5371227fb6 | |||
| b9a7cefc7c | |||
| 13b750f965 | |||
| 4ced272d9a | |||
| 8b0cd4b89d | |||
| de43f9779c |
@@ -3,6 +3,7 @@ dist/
|
|||||||
release/
|
release/
|
||||||
backup/
|
backup/
|
||||||
bin/
|
bin/
|
||||||
|
db/
|
||||||
sui
|
sui
|
||||||
web/html
|
web/html
|
||||||
main
|
main
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
buy_me_a_coffee: alireza7
|
||||||
@@ -1,9 +1,5 @@
|
|||||||
version: 2
|
version: 2
|
||||||
updates:
|
updates:
|
||||||
- package-ecosystem: "npm"
|
|
||||||
directory: "/"
|
|
||||||
schedule:
|
|
||||||
interval: "daily"
|
|
||||||
- package-ecosystem: "gomod"
|
- package-ecosystem: "gomod"
|
||||||
directory: "/"
|
directory: "/"
|
||||||
schedule:
|
schedule:
|
||||||
|
|||||||
@@ -7,12 +7,13 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-22.04
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4.1.1
|
||||||
with:
|
with:
|
||||||
submodules: true
|
submodules: recursive
|
||||||
|
|
||||||
- name: Docker meta
|
- name: Docker meta
|
||||||
id: meta
|
id: meta
|
||||||
@@ -46,10 +47,10 @@ jobs:
|
|||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
- name: Build and push
|
- name: Build and push
|
||||||
uses: docker/build-push-action@v5
|
uses: docker/build-push-action@v6
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
push: true
|
push: true
|
||||||
platforms: linux/amd64,linux/arm64/v8
|
platforms: linux/amd64, linux/arm64/v8, linux/arm/v7, linux/arm/v6, linux/386
|
||||||
tags: ${{ steps.meta.outputs.tags }}
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
@@ -14,22 +14,27 @@ jobs:
|
|||||||
- amd64
|
- amd64
|
||||||
- arm64
|
- arm64
|
||||||
- armv7
|
- armv7
|
||||||
|
- armv6
|
||||||
|
- armv5
|
||||||
- 386
|
- 386
|
||||||
runs-on: ubuntu-20.04
|
- s390x
|
||||||
|
runs-on: ubuntu-22.04
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v4.1.1
|
uses: actions/checkout@v4.1.1
|
||||||
|
with:
|
||||||
|
submodules: recursive
|
||||||
|
|
||||||
- name: Setup Go
|
- name: Setup Go
|
||||||
uses: actions/setup-go@v5
|
uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
cache: false
|
cache: false
|
||||||
go-version: '1.22'
|
go-version-file: go.mod
|
||||||
|
|
||||||
- name: Setup Node.js
|
- name: Setup Node.js
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: '20'
|
node-version: '22'
|
||||||
registry-url: 'https://registry.npmjs.org'
|
registry-url: 'https://registry.npmjs.org'
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
@@ -39,8 +44,14 @@ jobs:
|
|||||||
sudo apt install gcc-aarch64-linux-gnu
|
sudo apt install gcc-aarch64-linux-gnu
|
||||||
elif [ "${{ matrix.platform }}" == "armv7" ]; then
|
elif [ "${{ matrix.platform }}" == "armv7" ]; then
|
||||||
sudo apt install gcc-arm-linux-gnueabihf
|
sudo apt install gcc-arm-linux-gnueabihf
|
||||||
|
elif [ "${{ matrix.platform }}" == "armv6" ]; then
|
||||||
|
sudo apt install gcc-arm-linux-gnueabihf
|
||||||
|
elif [ "${{ matrix.platform }}" == "armv5" ]; then
|
||||||
|
sudo apt install gcc-arm-linux-gnueabi
|
||||||
elif [ "${{ matrix.platform }}" == "386" ]; then
|
elif [ "${{ matrix.platform }}" == "386" ]; then
|
||||||
sudo apt install gcc-i686-linux-gnu
|
sudo apt install gcc-i686-linux-gnu
|
||||||
|
elif [ "${{ matrix.platform }}" == "s390x" ]; then
|
||||||
|
sudo apt install gcc-s390x-linux-gnu
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Build frontend
|
- name: Build frontend
|
||||||
@@ -49,9 +60,10 @@ jobs:
|
|||||||
npm install
|
npm install
|
||||||
npm run build
|
npm run build
|
||||||
cd ..
|
cd ..
|
||||||
mv frontend/dist backend/web/html
|
mv frontend/dist web/html
|
||||||
|
rm -fr frontend
|
||||||
|
|
||||||
- name: Build s-ui & singbox
|
- name: Build s-ui
|
||||||
run: |
|
run: |
|
||||||
export CGO_ENABLED=1
|
export CGO_ENABLED=1
|
||||||
export GOOS=linux
|
export GOOS=linux
|
||||||
@@ -63,33 +75,33 @@ jobs:
|
|||||||
export GOARCH=arm
|
export GOARCH=arm
|
||||||
export GOARM=7
|
export GOARM=7
|
||||||
export CC=arm-linux-gnueabihf-gcc
|
export CC=arm-linux-gnueabihf-gcc
|
||||||
|
elif [ "${{ matrix.platform }}" == "armv6" ]; then
|
||||||
|
export GOARCH=arm
|
||||||
|
export GOARM=6
|
||||||
|
export CC=arm-linux-gnueabihf-gcc
|
||||||
|
elif [ "${{ matrix.platform }}" == "armv5" ]; then
|
||||||
|
export GOARCH=arm
|
||||||
|
export GOARM=5
|
||||||
|
export CC=arm-linux-gnueabi-gcc
|
||||||
elif [ "${{ matrix.platform }}" == "386" ]; then
|
elif [ "${{ matrix.platform }}" == "386" ]; then
|
||||||
export GOARCH=386
|
export GOARCH=386
|
||||||
export CC=i686-linux-gnu-gcc
|
export CC=i686-linux-gnu-gcc
|
||||||
|
elif [ "${{ matrix.platform }}" == "s390x" ]; then
|
||||||
|
export GOARCH=s390x
|
||||||
|
export CC=s390x-linux-gnu-gcc
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#### Build Sing-Box
|
|
||||||
git clone -b v1.8.7 https://github.com/SagerNet/sing-box
|
|
||||||
cd sing-box
|
|
||||||
go build -tags with_v2ray_api,with_clash_api,with_grpc,with_quic,with_ech -o sing-box ./cmd/sing-box
|
|
||||||
cd ..
|
|
||||||
|
|
||||||
### Build s-ui
|
### Build s-ui
|
||||||
cd backend
|
go build -ldflags="-w -s" -tags "with_quic,with_grpc,with_ech,with_utls,with_reality_server,with_acme,with_gvisor" -o sui main.go
|
||||||
go build -o ../sui main.go
|
|
||||||
cd ..
|
|
||||||
|
|
||||||
mkdir s-ui
|
mkdir s-ui
|
||||||
cp sui s-ui/
|
cp sui s-ui/
|
||||||
cp s-ui.service s-ui/
|
cp s-ui.service s-ui/
|
||||||
cp sing-box.service s-ui/
|
cp s-ui.sh s-ui/
|
||||||
mkdir s-ui/bin
|
|
||||||
cp sing-box/sing-box s-ui/bin/
|
|
||||||
cp runSingbox.sh s-ui/bin/
|
|
||||||
|
|
||||||
- name: Package
|
- name: Package
|
||||||
run: tar -zcvf s-ui-linux-${{ matrix.platform }}.tar.gz s-ui
|
run: tar -zcvf s-ui-linux-${{ matrix.platform }}.tar.gz s-ui
|
||||||
|
|
||||||
- name: Upload
|
- name: Upload
|
||||||
uses: svenstaro/upload-release-action@v2
|
uses: svenstaro/upload-release-action@v2
|
||||||
with:
|
with:
|
||||||
|
|||||||
@@ -5,10 +5,12 @@ backup/
|
|||||||
bin/
|
bin/
|
||||||
db/
|
db/
|
||||||
sui
|
sui
|
||||||
|
web/html
|
||||||
main
|
main
|
||||||
tmp
|
tmp
|
||||||
.sync*
|
.sync*
|
||||||
*.tar.gz
|
*.tar.gz
|
||||||
|
frontend/
|
||||||
|
|
||||||
# local env files
|
# local env files
|
||||||
.env.local
|
.env.local
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
[submodule "frontend"]
|
||||||
|
path = frontend
|
||||||
|
url = https://github.com/alireza0/s-ui-frontend
|
||||||
|
branch = main
|
||||||
+9
-7
@@ -1,23 +1,25 @@
|
|||||||
FROM node:alpine as front-builder
|
FROM --platform=$BUILDPLATFORM node:alpine AS front-builder
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY frontend/ ./
|
COPY frontend/ ./
|
||||||
RUN npm install && npm run build
|
RUN npm install && npm run build
|
||||||
|
|
||||||
FROM golang:1.22-alpine AS backend-builder
|
FROM golang:1.23-alpine AS backend-builder
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
ARG TARGETARCH
|
ARG TARGETARCH
|
||||||
ENV CGO_CFLAGS="-D_LARGEFILE64_SOURCE"
|
ENV CGO_CFLAGS="-D_LARGEFILE64_SOURCE"
|
||||||
ENV CGO_ENABLED=1
|
ENV CGO_ENABLED=1
|
||||||
RUN apk --no-cache --update add build-base gcc wget unzip
|
ENV GOARCH=$TARGETARCH
|
||||||
COPY backend/ ./
|
RUN apk update && apk --no-cache --update add build-base gcc wget unzip
|
||||||
|
COPY . .
|
||||||
COPY --from=front-builder /app/dist/ /app/web/html/
|
COPY --from=front-builder /app/dist/ /app/web/html/
|
||||||
RUN go build -o sui main.go
|
RUN go build -ldflags="-w -s" -tags "with_quic,with_grpc,with_ech,with_utls,with_reality_server,with_acme,with_gvisor" -o sui main.go
|
||||||
|
|
||||||
FROM alpine
|
FROM --platform=$TARGETPLATFORM alpine
|
||||||
LABEL org.opencontainers.image.authors="alireza7@gmail.com"
|
LABEL org.opencontainers.image.authors="alireza7@gmail.com"
|
||||||
ENV TZ=Asia/Tehran
|
ENV TZ=Asia/Tehran
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
RUN apk add --no-cache --update ca-certificates tzdata
|
RUN apk add --no-cache --update ca-certificates tzdata
|
||||||
COPY --from=backend-builder /app/sui /app/
|
COPY --from=backend-builder /app/sui /app/
|
||||||
|
COPY entrypoint.sh /app/
|
||||||
VOLUME [ "s-ui" ]
|
VOLUME [ "s-ui" ]
|
||||||
CMD [ "./sui" ]
|
ENTRYPOINT [ "./entrypoint.sh" ]
|
||||||
@@ -2,7 +2,9 @@
|
|||||||
**An Advanced Web Panel • Built on SagerNet/Sing-Box**
|
**An Advanced Web Panel • Built on SagerNet/Sing-Box**
|
||||||
|
|
||||||

|

|
||||||

|

|
||||||
|

|
||||||
|
[](https://goreportcard.com/report/github.com/alireza0/s-ui)
|
||||||
[](https://img.shields.io/github/downloads/alireza0/s-ui/total.svg)
|
[](https://img.shields.io/github/downloads/alireza0/s-ui/total.svg)
|
||||||
[](https://www.gnu.org/licenses/gpl-3.0.en.html)
|
[](https://www.gnu.org/licenses/gpl-3.0.en.html)
|
||||||
|
|
||||||
@@ -22,14 +24,20 @@
|
|||||||
| Multi-Client/Inbound | :heavy_check_mark: |
|
| Multi-Client/Inbound | :heavy_check_mark: |
|
||||||
| Advanced Traffic Routing Interface | :heavy_check_mark: |
|
| Advanced Traffic Routing Interface | :heavy_check_mark: |
|
||||||
| Client & Traffic & System Status | :heavy_check_mark: |
|
| Client & Traffic & System Status | :heavy_check_mark: |
|
||||||
| Subscription Service (link + info) | :heavy_check_mark: |
|
| Subscription Service (link/json + info)| :heavy_check_mark: |
|
||||||
| Dark/Light Theme | :heavy_check_mark: |
|
| Dark/Light Theme | :heavy_check_mark: |
|
||||||
|
| API Interface | :heavy_check_mark: |
|
||||||
|
|
||||||
|
## API Documentation
|
||||||
|
|
||||||
## Default Installation Informarion
|
[API-Documentation Wiki](https://github.com/alireza0/s-ui/wiki/API-Documentation)
|
||||||
|
|
||||||
|
## Default Installation Information
|
||||||
- Panel Port: 2095
|
- Panel Port: 2095
|
||||||
|
- Panel Path: /app/
|
||||||
- Subscription Port: 2096
|
- Subscription Port: 2096
|
||||||
- User/Passowrd: admin
|
- Subscription Path: /sub/
|
||||||
|
- User/Password: admin
|
||||||
|
|
||||||
## Install & Upgrade to Latest Version
|
## Install & Upgrade to Latest Version
|
||||||
|
|
||||||
@@ -37,25 +45,36 @@
|
|||||||
bash <(curl -Ls https://raw.githubusercontent.com/alireza0/s-ui/master/install.sh)
|
bash <(curl -Ls https://raw.githubusercontent.com/alireza0/s-ui/master/install.sh)
|
||||||
```
|
```
|
||||||
|
|
||||||
## Install Custom Version
|
## Install legacy Version
|
||||||
|
|
||||||
**Step 1:** To install your desired version, add the version to the end of the installation command. e.g., ver `0.0.1`:
|
**Step 1:** To install your desired legacy version, add the version to the end of the installation command. e.g., ver `1.0.0`:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
bash <(curl -Ls https://raw.githubusercontent.com/alireza0/s-ui/master/install.sh) 0.0.1
|
VERSION=1.0.0 && bash <(curl -Ls https://raw.githubusercontent.com/alireza0/s-ui/$VERSION/install.sh) $VERSION
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Manual installation
|
||||||
|
|
||||||
|
1. Get the latest version of S-UI based on your OS/Architecture from GitHub: [https://github.com/alireza0/s-ui/releases/latest](https://github.com/alireza0/s-ui/releases/latest)
|
||||||
|
2. **OPTIONAL** Get the latest version of `s-ui.sh` [https://raw.githubusercontent.com/alireza0/s-ui/master/s-ui.sh](https://raw.githubusercontent.com/alireza0/s-ui/master/s-ui.sh)
|
||||||
|
3. **OPTIONAL** Copy `s-ui.sh` to /usr/bin/ and run `chmod +x /usr/bin/s-ui`.
|
||||||
|
4. Extract s-ui tar.gz file to a directory of your choice and navigate to the directory where you extracted the tar.gz file.
|
||||||
|
5. Copy *.service files to /etc/systemd/system/ and run `systemctl daemon-reload`.
|
||||||
|
6. Enable autostart and start S-UI service using `systemctl enable s-ui --now`
|
||||||
|
7. Start sing-box service using `systemctl enable sing-box --now`
|
||||||
|
|
||||||
## Uninstall S-UI
|
## Uninstall S-UI
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
systemctl disable sing-box --now
|
sudo -i
|
||||||
|
|
||||||
systemctl disable s-ui --now
|
systemctl disable s-ui --now
|
||||||
|
|
||||||
rm -f /etc/systemd/system/s-ui.service
|
|
||||||
rm -f /etc/systemd/system/sing-box.service
|
rm -f /etc/systemd/system/sing-box.service
|
||||||
systemctl daemon-reload
|
systemctl daemon-reload
|
||||||
|
|
||||||
rm -fr /usr/local/s-ui
|
rm -fr /usr/local/s-ui
|
||||||
|
rm /usr/bin/s-ui
|
||||||
```
|
```
|
||||||
|
|
||||||
## Install using Docker
|
## Install using Docker
|
||||||
@@ -73,10 +92,20 @@ curl -fsSL https://get.docker.com | sh
|
|||||||
|
|
||||||
**Step 2:** Install S-UI
|
**Step 2:** Install S-UI
|
||||||
|
|
||||||
|
> Docker compose method
|
||||||
|
|
||||||
|
```shell
|
||||||
|
mkdir s-ui && cd s-ui
|
||||||
|
wget -q https://raw.githubusercontent.com/alireza0/s-ui/master/docker-compose.yml
|
||||||
|
docker compose up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
> Use docker
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
mkdir s-ui && cd s-ui
|
mkdir s-ui && cd s-ui
|
||||||
docker run -itd \
|
docker run -itd \
|
||||||
-p 2095:2095 -p 443:443 -p 80:80 \
|
-p 2095:2095 -p 2096:2096 -p 443:443 -p 80:80 \
|
||||||
-v $PWD/db/:/usr/local/s-ui/db/ \
|
-v $PWD/db/:/usr/local/s-ui/db/ \
|
||||||
-v $PWD/cert/:/root/cert/ \
|
-v $PWD/cert/:/root/cert/ \
|
||||||
--name s-ui --restart=unless-stopped \
|
--name s-ui --restart=unless-stopped \
|
||||||
@@ -86,22 +115,71 @@ docker run -itd \
|
|||||||
> Build your own image
|
> Build your own image
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
|
git clone https://github.com/alireza0/s-ui
|
||||||
|
git submodule update --init --recursive
|
||||||
docker build -t s-ui .
|
docker build -t s-ui .
|
||||||
```
|
```
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
|
## Manual run ( contribution )
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Click for details</summary>
|
||||||
|
|
||||||
|
### Build and run whole project
|
||||||
|
```shell
|
||||||
|
./runSUI.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
### Clone the repository
|
||||||
|
```shell
|
||||||
|
# clone repository
|
||||||
|
git clone https://github.com/alireza0/s-ui
|
||||||
|
# clone submodules
|
||||||
|
git submodule update --init --recursive
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
### - Frontend
|
||||||
|
|
||||||
|
Visit [s-ui-frontend](https://github.com/alireza0/s-ui-frontend) for frontend code
|
||||||
|
|
||||||
|
### - Backend
|
||||||
|
> Please build frontend once before!
|
||||||
|
|
||||||
|
To build backend:
|
||||||
|
```shell
|
||||||
|
# remove old frontend compiled files
|
||||||
|
rm -fr web/html/*
|
||||||
|
# apply new frontend compiled files
|
||||||
|
cp -R frontend/dist/ web/html/
|
||||||
|
# build
|
||||||
|
go build -o sui main.go
|
||||||
|
```
|
||||||
|
|
||||||
|
To run backend (from root folder of repository):
|
||||||
|
```shell
|
||||||
|
./sui
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
## Languages
|
## Languages
|
||||||
|
|
||||||
- English
|
- English
|
||||||
- Farsi
|
- Farsi
|
||||||
|
- Vietnamese
|
||||||
|
- Chinese (Simplified)
|
||||||
|
- Chinese (Traditional)
|
||||||
|
- Russian
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
- Supported protocols:
|
- Supported protocols:
|
||||||
- General: Mixed, SOCKS, HTTP, HTTPS, Direct, Redirect, TProxy
|
- General: Mixed, SOCKS, HTTP, HTTPS, Direct, Redirect, TProxy
|
||||||
- V2Ray based: VLESS, VMess, Trojan, Shadowsocks
|
- V2Ray based: VLESS, VMess, Trojan, Shadowsocks
|
||||||
- Other protocols: ShadowTLS, Hysteria, Hysteri2, Naive, TUIC
|
- Other protocols: ShadowTLS, Hysteria, Hysteria2, Naive, TUIC
|
||||||
- Supports XTLS protocols
|
- Supports XTLS protocols
|
||||||
- An advanced interface for routing traffic, incorporating PROXY Protocol, External, and Transparent Proxy, SSL Certificate, and Port
|
- An advanced interface for routing traffic, incorporating PROXY Protocol, External, and Transparent Proxy, SSL Certificate, and Port
|
||||||
- An advanced interface for inbound and outbound configuration
|
- An advanced interface for inbound and outbound configuration
|
||||||
@@ -113,10 +191,18 @@ docker build -t s-ui .
|
|||||||
|
|
||||||
## Recommended OS
|
## Recommended OS
|
||||||
|
|
||||||
|
- Ubuntu 20.04+
|
||||||
|
- Debian 11+
|
||||||
- CentOS 8+
|
- CentOS 8+
|
||||||
- Ubuntu 20+
|
|
||||||
- Debian 10+
|
|
||||||
- Fedora 36+
|
- Fedora 36+
|
||||||
|
- Arch Linux
|
||||||
|
- Parch Linux
|
||||||
|
- Manjaro
|
||||||
|
- Armbian
|
||||||
|
- AlmaLinux 9+
|
||||||
|
- Rocky Linux 9+
|
||||||
|
- Oracle Linux 8+
|
||||||
|
- OpenSUSE Tubleweed
|
||||||
|
|
||||||
## Environment Variables
|
## Environment Variables
|
||||||
|
|
||||||
@@ -153,5 +239,4 @@ certbot certonly --standalone --register-unsafely-without-email --non-interactiv
|
|||||||
</details>
|
</details>
|
||||||
|
|
||||||
## Stargazers over Time
|
## Stargazers over Time
|
||||||
|
|
||||||
[](https://starchart.cc/alireza0/s-ui)
|
[](https://starchart.cc/alireza0/s-ui)
|
||||||
|
|||||||
@@ -0,0 +1,100 @@
|
|||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"s-ui/util/common"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
type APIHandler struct {
|
||||||
|
ApiService
|
||||||
|
apiv2 *APIv2Handler
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewAPIHandler(g *gin.RouterGroup, a2 *APIv2Handler) {
|
||||||
|
a := &APIHandler{
|
||||||
|
apiv2: a2,
|
||||||
|
}
|
||||||
|
a.initRouter(g)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *APIHandler) initRouter(g *gin.RouterGroup) {
|
||||||
|
g.Use(func(c *gin.Context) {
|
||||||
|
path := c.Request.URL.Path
|
||||||
|
if !strings.HasSuffix(path, "login") && !strings.HasSuffix(path, "logout") {
|
||||||
|
checkLogin(c)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
g.POST("/:postAction", a.postHandler)
|
||||||
|
g.GET("/:getAction", a.getHandler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *APIHandler) postHandler(c *gin.Context) {
|
||||||
|
loginUser := GetLoginUser(c)
|
||||||
|
action := c.Param("postAction")
|
||||||
|
|
||||||
|
switch action {
|
||||||
|
case "login":
|
||||||
|
a.ApiService.Login(c)
|
||||||
|
case "changePass":
|
||||||
|
a.ApiService.ChangePass(c)
|
||||||
|
case "save":
|
||||||
|
a.ApiService.Save(c, loginUser)
|
||||||
|
case "restartApp":
|
||||||
|
a.ApiService.RestartApp(c)
|
||||||
|
case "restartSb":
|
||||||
|
a.ApiService.RestartSb(c)
|
||||||
|
case "linkConvert":
|
||||||
|
a.ApiService.LinkConvert(c)
|
||||||
|
case "importdb":
|
||||||
|
a.ApiService.ImportDb(c)
|
||||||
|
case "addToken":
|
||||||
|
a.ApiService.AddToken(c)
|
||||||
|
a.apiv2.ReloadTokens()
|
||||||
|
case "deleteToken":
|
||||||
|
a.ApiService.DeleteToken(c)
|
||||||
|
a.apiv2.ReloadTokens()
|
||||||
|
default:
|
||||||
|
jsonMsg(c, "failed", common.NewError("unknown action: ", action))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *APIHandler) getHandler(c *gin.Context) {
|
||||||
|
action := c.Param("getAction")
|
||||||
|
|
||||||
|
switch action {
|
||||||
|
case "logout":
|
||||||
|
a.ApiService.Logout(c)
|
||||||
|
case "load":
|
||||||
|
a.ApiService.LoadData(c)
|
||||||
|
case "inbounds", "outbounds", "endpoints", "tls", "clients", "config":
|
||||||
|
err := a.ApiService.LoadPartialData(c, []string{action})
|
||||||
|
if err != nil {
|
||||||
|
jsonMsg(c, action, err)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
case "users":
|
||||||
|
a.ApiService.GetUsers(c)
|
||||||
|
case "settings":
|
||||||
|
a.ApiService.GetSettings(c)
|
||||||
|
case "stats":
|
||||||
|
a.ApiService.GetStats(c)
|
||||||
|
case "status":
|
||||||
|
a.ApiService.GetStatus(c)
|
||||||
|
case "onlines":
|
||||||
|
a.ApiService.GetOnlines(c)
|
||||||
|
case "logs":
|
||||||
|
a.ApiService.GetLogs(c)
|
||||||
|
case "changes":
|
||||||
|
a.ApiService.CheckChanges(c)
|
||||||
|
case "keypairs":
|
||||||
|
a.ApiService.GetKeypairs(c)
|
||||||
|
case "getdb":
|
||||||
|
a.ApiService.GetDb(c)
|
||||||
|
case "tokens":
|
||||||
|
a.ApiService.GetTokens(c)
|
||||||
|
default:
|
||||||
|
jsonMsg(c, "failed", common.NewError("unknown action: ", action))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,363 @@
|
|||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"s-ui/database"
|
||||||
|
"s-ui/logger"
|
||||||
|
"s-ui/service"
|
||||||
|
"s-ui/util"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ApiService struct {
|
||||||
|
service.SettingService
|
||||||
|
service.UserService
|
||||||
|
service.ConfigService
|
||||||
|
service.ClientService
|
||||||
|
service.TlsService
|
||||||
|
service.InboundService
|
||||||
|
service.OutboundService
|
||||||
|
service.EndpointService
|
||||||
|
service.PanelService
|
||||||
|
service.StatsService
|
||||||
|
service.ServerService
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *ApiService) LoadData(c *gin.Context) {
|
||||||
|
data, err := a.getData(c)
|
||||||
|
if err != nil {
|
||||||
|
jsonMsg(c, "", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
jsonObj(c, data, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *ApiService) getData(c *gin.Context) (interface{}, error) {
|
||||||
|
data := make(map[string]interface{}, 0)
|
||||||
|
lu := c.Query("lu")
|
||||||
|
isUpdated, err := a.ConfigService.CheckChanges(lu)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
onlines, err := a.StatsService.GetOnlines()
|
||||||
|
|
||||||
|
sysInfo := a.ServerService.GetSingboxInfo()
|
||||||
|
if sysInfo["running"] == false {
|
||||||
|
logs := a.ServerService.GetLogs("1", "debug")
|
||||||
|
if len(logs) > 0 {
|
||||||
|
data["lastLog"] = logs[0]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
if isUpdated {
|
||||||
|
config, err := a.SettingService.GetConfig()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
clients, err := a.ClientService.GetAll()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
tlsConfigs, err := a.TlsService.GetAll()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
inbounds, err := a.InboundService.GetAll()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
outbounds, err := a.OutboundService.GetAll()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
endpoints, err := a.EndpointService.GetAll()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
subURI, err := a.SettingService.GetFinalSubURI(strings.Split(c.Request.Host, ":")[0])
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
data["config"] = json.RawMessage(config)
|
||||||
|
data["clients"] = clients
|
||||||
|
data["tls"] = tlsConfigs
|
||||||
|
data["inbounds"] = inbounds
|
||||||
|
data["outbounds"] = outbounds
|
||||||
|
data["endpoints"] = endpoints
|
||||||
|
data["subURI"] = subURI
|
||||||
|
data["onlines"] = onlines
|
||||||
|
} else {
|
||||||
|
data["onlines"] = onlines
|
||||||
|
}
|
||||||
|
|
||||||
|
return data, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *ApiService) LoadPartialData(c *gin.Context, objs []string) error {
|
||||||
|
data := make(map[string]interface{}, 0)
|
||||||
|
id := c.Query("id")
|
||||||
|
|
||||||
|
for _, obj := range objs {
|
||||||
|
switch obj {
|
||||||
|
case "inbounds":
|
||||||
|
inbounds, err := a.InboundService.Get(id)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
data[obj] = inbounds
|
||||||
|
case "outbounds":
|
||||||
|
outbounds, err := a.OutboundService.GetAll()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
data[obj] = outbounds
|
||||||
|
case "endpoints":
|
||||||
|
endpoints, err := a.EndpointService.GetAll()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
data[obj] = endpoints
|
||||||
|
case "tls":
|
||||||
|
tlsConfigs, err := a.TlsService.GetAll()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
data[obj] = tlsConfigs
|
||||||
|
case "clients":
|
||||||
|
clients, err := a.ClientService.Get(id)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
data[obj] = clients
|
||||||
|
case "config":
|
||||||
|
config, err := a.SettingService.GetConfig()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
data[obj] = json.RawMessage(config)
|
||||||
|
case "settings":
|
||||||
|
settings, err := a.SettingService.GetAllSetting()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
data[obj] = settings
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
jsonObj(c, data, nil)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *ApiService) GetUsers(c *gin.Context) {
|
||||||
|
users, err := a.UserService.GetUsers()
|
||||||
|
if err != nil {
|
||||||
|
jsonMsg(c, "", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
jsonObj(c, *users, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *ApiService) GetSettings(c *gin.Context) {
|
||||||
|
data, err := a.SettingService.GetAllSetting()
|
||||||
|
if err != nil {
|
||||||
|
jsonMsg(c, "", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
jsonObj(c, data, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *ApiService) GetStats(c *gin.Context) {
|
||||||
|
resource := c.Query("resource")
|
||||||
|
tag := c.Query("tag")
|
||||||
|
limit, err := strconv.Atoi(c.Query("limit"))
|
||||||
|
if err != nil {
|
||||||
|
limit = 100
|
||||||
|
}
|
||||||
|
data, err := a.StatsService.GetStats(resource, tag, limit)
|
||||||
|
if err != nil {
|
||||||
|
jsonMsg(c, "", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
jsonObj(c, data, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *ApiService) GetStatus(c *gin.Context) {
|
||||||
|
request := c.Query("r")
|
||||||
|
result := a.ServerService.GetStatus(request)
|
||||||
|
jsonObj(c, result, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *ApiService) GetOnlines(c *gin.Context) {
|
||||||
|
onlines, err := a.StatsService.GetOnlines()
|
||||||
|
jsonObj(c, onlines, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *ApiService) GetLogs(c *gin.Context) {
|
||||||
|
count := c.Query("c")
|
||||||
|
level := c.Query("l")
|
||||||
|
logs := a.ServerService.GetLogs(count, level)
|
||||||
|
jsonObj(c, logs, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *ApiService) CheckChanges(c *gin.Context) {
|
||||||
|
actor := c.Query("a")
|
||||||
|
chngKey := c.Query("k")
|
||||||
|
count := c.Query("c")
|
||||||
|
changes := a.ConfigService.GetChanges(actor, chngKey, count)
|
||||||
|
jsonObj(c, changes, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *ApiService) GetKeypairs(c *gin.Context) {
|
||||||
|
kType := c.Query("k")
|
||||||
|
options := c.Query("o")
|
||||||
|
keypair := a.ServerService.GenKeypair(kType, options)
|
||||||
|
jsonObj(c, keypair, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *ApiService) GetDb(c *gin.Context) {
|
||||||
|
exclude := c.Query("exclude")
|
||||||
|
db, err := database.GetDb(exclude)
|
||||||
|
if err != nil {
|
||||||
|
jsonMsg(c, "", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.Header("Content-Type", "application/octet-stream")
|
||||||
|
c.Header("Content-Disposition", "attachment; filename=s-ui_"+time.Now().Format("20060102-150405")+".db")
|
||||||
|
c.Writer.Write(db)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *ApiService) postActions(c *gin.Context) (string, json.RawMessage, error) {
|
||||||
|
var data map[string]json.RawMessage
|
||||||
|
err := c.ShouldBind(&data)
|
||||||
|
if err != nil {
|
||||||
|
return "", nil, err
|
||||||
|
}
|
||||||
|
return string(data["action"]), data["data"], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *ApiService) Login(c *gin.Context) {
|
||||||
|
remoteIP := getRemoteIp(c)
|
||||||
|
loginUser, err := a.UserService.Login(c.Request.FormValue("user"), c.Request.FormValue("pass"), remoteIP)
|
||||||
|
if err != nil {
|
||||||
|
jsonMsg(c, "", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
sessionMaxAge, err := a.SettingService.GetSessionMaxAge()
|
||||||
|
if err != nil {
|
||||||
|
logger.Infof("Unable to get session's max age from DB")
|
||||||
|
}
|
||||||
|
|
||||||
|
err = SetLoginUser(c, loginUser, sessionMaxAge)
|
||||||
|
if err == nil {
|
||||||
|
logger.Info("user ", loginUser, " login success")
|
||||||
|
} else {
|
||||||
|
logger.Warning("login failed: ", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
jsonMsg(c, "", nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *ApiService) ChangePass(c *gin.Context) {
|
||||||
|
id := c.Request.FormValue("id")
|
||||||
|
oldPass := c.Request.FormValue("oldPass")
|
||||||
|
newUsername := c.Request.FormValue("newUsername")
|
||||||
|
newPass := c.Request.FormValue("newPass")
|
||||||
|
err := a.UserService.ChangePass(id, oldPass, newUsername, newPass)
|
||||||
|
if err == nil {
|
||||||
|
logger.Info("change user credentials success")
|
||||||
|
jsonMsg(c, "save", nil)
|
||||||
|
} else {
|
||||||
|
logger.Warning("change user credentials failed:", err)
|
||||||
|
jsonMsg(c, "", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *ApiService) Save(c *gin.Context, loginUser string) {
|
||||||
|
hostname := getHostname(c)
|
||||||
|
obj := c.Request.FormValue("object")
|
||||||
|
act := c.Request.FormValue("action")
|
||||||
|
data := c.Request.FormValue("data")
|
||||||
|
initUsers := c.Request.FormValue("initUsers")
|
||||||
|
objs, err := a.ConfigService.Save(obj, act, json.RawMessage(data), initUsers, loginUser, hostname)
|
||||||
|
if err != nil {
|
||||||
|
jsonMsg(c, "save", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = a.LoadPartialData(c, objs)
|
||||||
|
if err != nil {
|
||||||
|
jsonMsg(c, obj, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *ApiService) RestartApp(c *gin.Context) {
|
||||||
|
err := a.PanelService.RestartPanel(3)
|
||||||
|
jsonMsg(c, "restartApp", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *ApiService) RestartSb(c *gin.Context) {
|
||||||
|
err := a.ConfigService.RestartCore()
|
||||||
|
jsonMsg(c, "restartSb", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *ApiService) LinkConvert(c *gin.Context) {
|
||||||
|
link := c.Request.FormValue("link")
|
||||||
|
result, _, err := util.GetOutbound(link, 0)
|
||||||
|
jsonObj(c, result, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *ApiService) ImportDb(c *gin.Context) {
|
||||||
|
file, _, err := c.Request.FormFile("db")
|
||||||
|
if err != nil {
|
||||||
|
jsonMsg(c, "", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
err = database.ImportDB(file)
|
||||||
|
jsonMsg(c, "", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *ApiService) Logout(c *gin.Context) {
|
||||||
|
loginUser := GetLoginUser(c)
|
||||||
|
if loginUser != "" {
|
||||||
|
logger.Infof("user %s logout", loginUser)
|
||||||
|
}
|
||||||
|
ClearSession(c)
|
||||||
|
jsonMsg(c, "", nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *ApiService) LoadTokens() ([]byte, error) {
|
||||||
|
return a.UserService.LoadTokens()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *ApiService) GetTokens(c *gin.Context) {
|
||||||
|
loginUser := GetLoginUser(c)
|
||||||
|
tokens, err := a.UserService.GetUserTokens(loginUser)
|
||||||
|
jsonObj(c, tokens, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *ApiService) AddToken(c *gin.Context) {
|
||||||
|
loginUser := GetLoginUser(c)
|
||||||
|
expiry := c.Request.FormValue("expiry")
|
||||||
|
expiryInt, err := strconv.ParseInt(expiry, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
jsonMsg(c, "", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
desc := c.Request.FormValue("desc")
|
||||||
|
token, err := a.UserService.AddToken(loginUser, expiryInt, desc)
|
||||||
|
jsonObj(c, token, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *ApiService) DeleteToken(c *gin.Context) {
|
||||||
|
tokenId := c.Request.FormValue("id")
|
||||||
|
err := a.UserService.DeleteToken(tokenId)
|
||||||
|
jsonMsg(c, "", err)
|
||||||
|
}
|
||||||
@@ -0,0 +1,129 @@
|
|||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"s-ui/logger"
|
||||||
|
"s-ui/util/common"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
type TokenInMemory struct {
|
||||||
|
Token string
|
||||||
|
Expiry int64
|
||||||
|
Username string
|
||||||
|
}
|
||||||
|
|
||||||
|
type APIv2Handler struct {
|
||||||
|
ApiService
|
||||||
|
tokens *[]TokenInMemory
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewAPIv2Handler(g *gin.RouterGroup) *APIv2Handler {
|
||||||
|
a := &APIv2Handler{}
|
||||||
|
a.ReloadTokens()
|
||||||
|
a.initRouter(g)
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *APIv2Handler) initRouter(g *gin.RouterGroup) {
|
||||||
|
g.Use(func(c *gin.Context) {
|
||||||
|
a.checkToken(c)
|
||||||
|
})
|
||||||
|
g.POST("/:postAction", a.postHandler)
|
||||||
|
g.GET("/:getAction", a.getHandler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *APIv2Handler) postHandler(c *gin.Context) {
|
||||||
|
username := a.findUsername(c)
|
||||||
|
action := c.Param("postAction")
|
||||||
|
|
||||||
|
switch action {
|
||||||
|
case "save":
|
||||||
|
a.ApiService.Save(c, username)
|
||||||
|
case "restartApp":
|
||||||
|
a.ApiService.RestartApp(c)
|
||||||
|
case "restartSb":
|
||||||
|
a.ApiService.RestartSb(c)
|
||||||
|
case "linkConvert":
|
||||||
|
a.ApiService.LinkConvert(c)
|
||||||
|
case "importdb":
|
||||||
|
a.ApiService.ImportDb(c)
|
||||||
|
default:
|
||||||
|
jsonMsg(c, "failed", common.NewError("unknown action: ", action))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *APIv2Handler) getHandler(c *gin.Context) {
|
||||||
|
action := c.Param("getAction")
|
||||||
|
|
||||||
|
switch action {
|
||||||
|
case "load":
|
||||||
|
a.ApiService.LoadData(c)
|
||||||
|
case "inbounds", "outbounds", "endpoints", "tls", "clients", "config":
|
||||||
|
err := a.ApiService.LoadPartialData(c, []string{action})
|
||||||
|
if err != nil {
|
||||||
|
jsonMsg(c, action, err)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
case "users":
|
||||||
|
a.ApiService.GetUsers(c)
|
||||||
|
case "settings":
|
||||||
|
a.ApiService.GetSettings(c)
|
||||||
|
case "stats":
|
||||||
|
a.ApiService.GetStats(c)
|
||||||
|
case "status":
|
||||||
|
a.ApiService.GetStatus(c)
|
||||||
|
case "onlines":
|
||||||
|
a.ApiService.GetOnlines(c)
|
||||||
|
case "logs":
|
||||||
|
a.ApiService.GetLogs(c)
|
||||||
|
case "changes":
|
||||||
|
a.ApiService.CheckChanges(c)
|
||||||
|
case "keypairs":
|
||||||
|
a.ApiService.GetKeypairs(c)
|
||||||
|
case "getdb":
|
||||||
|
a.ApiService.GetDb(c)
|
||||||
|
default:
|
||||||
|
jsonMsg(c, "failed", common.NewError("unknown action: ", action))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *APIv2Handler) findUsername(c *gin.Context) string {
|
||||||
|
token := c.Request.Header.Get("Token")
|
||||||
|
for index, t := range *a.tokens {
|
||||||
|
if t.Expiry > 0 && t.Expiry < time.Now().Unix() {
|
||||||
|
(*a.tokens) = append((*a.tokens)[:index], (*a.tokens)[index+1:]...)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if t.Token == token {
|
||||||
|
return t.Username
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *APIv2Handler) checkToken(c *gin.Context) {
|
||||||
|
username := a.findUsername(c)
|
||||||
|
if username != "" {
|
||||||
|
c.Next()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
jsonMsg(c, "", common.NewError("invalid token"))
|
||||||
|
c.Abort()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *APIv2Handler) ReloadTokens() {
|
||||||
|
tokens, err := a.ApiService.LoadTokens()
|
||||||
|
if err == nil {
|
||||||
|
var newTokens []TokenInMemory
|
||||||
|
err = json.Unmarshal(tokens, &newTokens)
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("unable to load tokens: ", err)
|
||||||
|
}
|
||||||
|
a.tokens = &newTokens
|
||||||
|
} else {
|
||||||
|
logger.Error("unable to load tokens: ", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,7 +4,7 @@ import (
|
|||||||
"encoding/gob"
|
"encoding/gob"
|
||||||
"s-ui/database/model"
|
"s-ui/database/model"
|
||||||
|
|
||||||
sessions "github.com/Calidity/gin-sessions"
|
"github.com/gin-contrib/sessions"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -16,17 +16,26 @@ func init() {
|
|||||||
gob.Register(model.User{})
|
gob.Register(model.User{})
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetLoginUser(c *gin.Context, userName string) error {
|
func SetLoginUser(c *gin.Context, userName string, maxAge int) error {
|
||||||
|
options := sessions.Options{
|
||||||
|
Path: "/",
|
||||||
|
Secure: false,
|
||||||
|
}
|
||||||
|
if maxAge > 0 {
|
||||||
|
options.MaxAge = maxAge * 60
|
||||||
|
}
|
||||||
|
|
||||||
s := sessions.Default(c)
|
s := sessions.Default(c)
|
||||||
s.Set(loginUser, userName)
|
s.Set(loginUser, userName)
|
||||||
|
s.Options(options)
|
||||||
|
|
||||||
return s.Save()
|
return s.Save()
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetMaxAge(c *gin.Context, maxAge int) error {
|
func SetMaxAge(c *gin.Context) error {
|
||||||
s := sessions.Default(c)
|
s := sessions.Default(c)
|
||||||
s.Options(sessions.Options{
|
s.Options(sessions.Options{
|
||||||
Path: "/",
|
Path: "/",
|
||||||
MaxAge: maxAge,
|
|
||||||
})
|
})
|
||||||
return s.Save()
|
return s.Save()
|
||||||
}
|
}
|
||||||
@@ -27,6 +27,14 @@ func getRemoteIp(c *gin.Context) string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getHostname(c *gin.Context) string {
|
||||||
|
host := c.Request.Host
|
||||||
|
if colonIndex := strings.LastIndex(host, ":"); colonIndex != -1 {
|
||||||
|
host, _, _ = net.SplitHostPort(c.Request.Host)
|
||||||
|
}
|
||||||
|
return host
|
||||||
|
}
|
||||||
|
|
||||||
func jsonMsg(c *gin.Context, msg string, err error) {
|
func jsonMsg(c *gin.Context, msg string, err error) {
|
||||||
jsonMsgObj(c, msg, nil, err)
|
jsonMsgObj(c, msg, nil, err)
|
||||||
}
|
}
|
||||||
@@ -46,7 +54,7 @@ func jsonMsgObj(c *gin.Context, msg string, obj interface{}, err error) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
m.Success = false
|
m.Success = false
|
||||||
m.Msg = msg + err.Error()
|
m.Msg = msg + ": " + err.Error()
|
||||||
logger.Warning("failed :", err)
|
logger.Warning("failed :", err)
|
||||||
}
|
}
|
||||||
c.JSON(http.StatusOK, m)
|
c.JSON(http.StatusOK, m)
|
||||||
@@ -3,6 +3,7 @@ package app
|
|||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
"s-ui/config"
|
"s-ui/config"
|
||||||
|
"s-ui/core"
|
||||||
"s-ui/cronjob"
|
"s-ui/cronjob"
|
||||||
"s-ui/database"
|
"s-ui/database"
|
||||||
"s-ui/logger"
|
"s-ui/logger"
|
||||||
@@ -15,9 +16,12 @@ import (
|
|||||||
|
|
||||||
type APP struct {
|
type APP struct {
|
||||||
service.SettingService
|
service.SettingService
|
||||||
webServer *web.Server
|
configService *service.ConfigService
|
||||||
subServer *sub.Server
|
webServer *web.Server
|
||||||
cronJob *cronjob.CronJob
|
subServer *sub.Server
|
||||||
|
cronJob *cronjob.CronJob
|
||||||
|
logger *logging.Logger
|
||||||
|
core *core.Core
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewApp() *APP {
|
func NewApp() *APP {
|
||||||
@@ -34,15 +38,17 @@ func (a *APP) Init() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Init Setting
|
||||||
|
a.SettingService.GetAllSetting()
|
||||||
|
|
||||||
|
a.core = core.NewCore()
|
||||||
|
|
||||||
a.cronJob = cronjob.NewCronJob()
|
a.cronJob = cronjob.NewCronJob()
|
||||||
a.webServer = web.NewServer()
|
a.webServer = web.NewServer()
|
||||||
a.subServer = sub.NewServer()
|
a.subServer = sub.NewServer()
|
||||||
|
|
||||||
configService := service.NewConfigService()
|
a.configService = service.NewConfigService(a.core)
|
||||||
err = configService.InitConfig()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,7 +57,13 @@ func (a *APP) Start() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err = a.cronJob.Start(loc)
|
|
||||||
|
trafficAge, err := a.SettingService.GetTrafficAge()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = a.cronJob.Start(loc, trafficAge)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -66,6 +78,11 @@ func (a *APP) Start() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = a.configService.StartCore("")
|
||||||
|
if err != nil {
|
||||||
|
logger.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,6 +96,10 @@ func (a *APP) Stop() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Warning("stop Web Server err:", err)
|
logger.Warning("stop Web Server err:", err)
|
||||||
}
|
}
|
||||||
|
err = a.configService.StopCore()
|
||||||
|
if err != nil {
|
||||||
|
logger.Warning("stop Core err:", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *APP) initLog() {
|
func (a *APP) initLog() {
|
||||||
@@ -100,3 +121,7 @@ func (a *APP) RestartApp() {
|
|||||||
a.Stop()
|
a.Stop()
|
||||||
a.Start()
|
a.Start()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *APP) GetCore() *core.Core {
|
||||||
|
return a.core
|
||||||
|
}
|
||||||
@@ -1,189 +0,0 @@
|
|||||||
package api
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"s-ui/logger"
|
|
||||||
"s-ui/service"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
)
|
|
||||||
|
|
||||||
type APIHandler struct {
|
|
||||||
service.SettingService
|
|
||||||
service.UserService
|
|
||||||
service.ConfigService
|
|
||||||
service.ClientService
|
|
||||||
service.PanelService
|
|
||||||
service.StatsService
|
|
||||||
service.ServerService
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewAPIHandler(g *gin.RouterGroup) {
|
|
||||||
a := &APIHandler{}
|
|
||||||
a.initRouter(g)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *APIHandler) initRouter(g *gin.RouterGroup) {
|
|
||||||
g.Use(func(c *gin.Context) {
|
|
||||||
path := c.Request.URL.Path
|
|
||||||
if !strings.HasSuffix(path, "login") && !strings.HasSuffix(path, "logout") {
|
|
||||||
checkLogin(c)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
g.POST("/:postAction", a.postHandler)
|
|
||||||
g.GET("/:getAction", a.getHandler)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *APIHandler) postHandler(c *gin.Context) {
|
|
||||||
var err error
|
|
||||||
action := c.Param("postAction")
|
|
||||||
remoteIP := getRemoteIp(c)
|
|
||||||
|
|
||||||
switch action {
|
|
||||||
case "login":
|
|
||||||
loginUser, err := a.UserService.Login(c.Request.FormValue("user"), c.Request.FormValue("pass"), remoteIP)
|
|
||||||
if err != nil {
|
|
||||||
jsonMsg(c, "", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
sessionMaxAge, err := a.SettingService.GetSessionMaxAge()
|
|
||||||
if err != nil {
|
|
||||||
logger.Infof("Unable to get session's max age from DB")
|
|
||||||
}
|
|
||||||
|
|
||||||
if sessionMaxAge > 0 {
|
|
||||||
err = SetMaxAge(c, sessionMaxAge*60)
|
|
||||||
if err != nil {
|
|
||||||
logger.Infof("Unable to set session's max age")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
err = SetLoginUser(c, loginUser)
|
|
||||||
if err == nil {
|
|
||||||
logger.Info("user ", loginUser, " login success")
|
|
||||||
} else {
|
|
||||||
logger.Warning("login failed: ", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
jsonMsg(c, "", nil)
|
|
||||||
case "changePass":
|
|
||||||
id := c.Request.FormValue("id")
|
|
||||||
oldPass := c.Request.FormValue("oldPass")
|
|
||||||
newUsername := c.Request.FormValue("newUsername")
|
|
||||||
newPass := c.Request.FormValue("newPass")
|
|
||||||
err = a.UserService.ChangePass(id, oldPass, newUsername, newPass)
|
|
||||||
if err == nil {
|
|
||||||
logger.Info("change user credentials success")
|
|
||||||
jsonMsg(c, "save", nil)
|
|
||||||
} else {
|
|
||||||
logger.Warning("change user credentials failed:", err)
|
|
||||||
jsonMsg(c, "", err)
|
|
||||||
}
|
|
||||||
case "save":
|
|
||||||
loginUser := GetLoginUser(c)
|
|
||||||
data := map[string]string{}
|
|
||||||
err = c.ShouldBind(&data)
|
|
||||||
if err == nil {
|
|
||||||
err = a.ConfigService.SaveChanges(data, loginUser)
|
|
||||||
}
|
|
||||||
jsonMsg(c, "save", err)
|
|
||||||
case "restartApp":
|
|
||||||
err = a.PanelService.RestartPanel(3)
|
|
||||||
jsonMsg(c, "restartApp", err)
|
|
||||||
default:
|
|
||||||
jsonMsg(c, "API call", nil)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *APIHandler) getHandler(c *gin.Context) {
|
|
||||||
action := c.Param("getAction")
|
|
||||||
|
|
||||||
switch action {
|
|
||||||
case "logout":
|
|
||||||
loginUser := GetLoginUser(c)
|
|
||||||
if loginUser != "" {
|
|
||||||
logger.Infof("user %s logout", loginUser)
|
|
||||||
}
|
|
||||||
ClearSession(c)
|
|
||||||
jsonMsg(c, "", nil)
|
|
||||||
case "load":
|
|
||||||
data, err := a.loadData(c)
|
|
||||||
if err != nil {
|
|
||||||
jsonMsg(c, "", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
jsonObj(c, data, nil)
|
|
||||||
case "users":
|
|
||||||
users, err := a.UserService.GetUsers()
|
|
||||||
if err != nil {
|
|
||||||
jsonMsg(c, "", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
jsonObj(c, *users, nil)
|
|
||||||
case "setting":
|
|
||||||
data, err := a.SettingService.GetAllSetting()
|
|
||||||
if err != nil {
|
|
||||||
jsonMsg(c, "", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
jsonObj(c, data, err)
|
|
||||||
case "stats":
|
|
||||||
resource := c.Query("resource")
|
|
||||||
tag := c.Query("tag")
|
|
||||||
limit, err := strconv.Atoi(c.Query("limit"))
|
|
||||||
if err != nil {
|
|
||||||
limit = 100
|
|
||||||
}
|
|
||||||
data, err := a.StatsService.GetStats(resource, tag, limit)
|
|
||||||
if err != nil {
|
|
||||||
jsonMsg(c, "", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
jsonObj(c, data, err)
|
|
||||||
case "status":
|
|
||||||
request := c.Query("r")
|
|
||||||
result := a.ServerService.GetStatus(request)
|
|
||||||
jsonObj(c, result, nil)
|
|
||||||
case "onlines":
|
|
||||||
onlines, err := a.StatsService.GetOnlines()
|
|
||||||
jsonObj(c, onlines, err)
|
|
||||||
default:
|
|
||||||
jsonMsg(c, "API call", nil)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *APIHandler) loadData(c *gin.Context) (string, error) {
|
|
||||||
var data string
|
|
||||||
lu := c.Query("lu")
|
|
||||||
isUpdated, err := a.ConfigService.CheckChnages(lu)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
onlines, err := a.StatsService.GetOnlines()
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
if isUpdated {
|
|
||||||
config, err := a.ConfigService.GetConfig()
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
clients, err := a.ClientService.GetAll()
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
subURI, err := a.SettingService.GetFinalSubURI(strings.Split(c.Request.Host, ":")[0])
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
data = fmt.Sprintf(`{"config": %s,"clients": %s,"subURI": "%s", "onlines": %s}`, string(*config), clients, subURI, onlines)
|
|
||||||
} else {
|
|
||||||
data = fmt.Sprintf(`{"onlines": %s}`, onlines)
|
|
||||||
}
|
|
||||||
|
|
||||||
return data, nil
|
|
||||||
}
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
{
|
|
||||||
"log": {
|
|
||||||
"level": "info"
|
|
||||||
},
|
|
||||||
"dns": {},
|
|
||||||
"inbounds": [],
|
|
||||||
"outbounds": [
|
|
||||||
{
|
|
||||||
"tag": "direct",
|
|
||||||
"type": "direct"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "dns",
|
|
||||||
"tag": "dns-out"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"route": {
|
|
||||||
"rules": [
|
|
||||||
{
|
|
||||||
"protocol": "dns",
|
|
||||||
"outbound": "dns-out"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"experimental": {
|
|
||||||
"v2ray_api": {
|
|
||||||
"listen": "127.0.0.1:1080",
|
|
||||||
"stats": {
|
|
||||||
"enabled": true,
|
|
||||||
"inbounds": [],
|
|
||||||
"outbounds": [
|
|
||||||
"direct"
|
|
||||||
],
|
|
||||||
"users": []
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
0.0.2
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
package model
|
|
||||||
|
|
||||||
import "encoding/json"
|
|
||||||
|
|
||||||
type Setting struct {
|
|
||||||
Id uint `json:"id" form:"id" gorm:"primaryKey;autoIncrement"`
|
|
||||||
Key string `json:"key" form:"key"`
|
|
||||||
Value string `json:"value" form:"value"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type User struct {
|
|
||||||
Id uint `json:"id" form:"id" gorm:"primaryKey;autoIncrement"`
|
|
||||||
Username string `json:"username" form:"username"`
|
|
||||||
Password string `json:"password" form:"password"`
|
|
||||||
LastLogins string `json:"lastLogin"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Client struct {
|
|
||||||
Id uint `json:"id" form:"id" gorm:"primaryKey;autoIncrement"`
|
|
||||||
Enable bool `json:"enable" form:"enable"`
|
|
||||||
Name string `json:"name" form:"name"`
|
|
||||||
Config string `json:"config" form:"config"`
|
|
||||||
Inbounds string `json:"inbounds" form:"inbounds"`
|
|
||||||
Links string `json:"links" form:"links"`
|
|
||||||
Volume int64 `json:"volume" form:"volume"`
|
|
||||||
Expiry int64 `json:"expiry" form:"expiry"`
|
|
||||||
Down int64 `json:"down" form:"down"`
|
|
||||||
Up int64 `json:"up" form:"up"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Stats struct {
|
|
||||||
Id uint64 `json:"id" gorm:"primaryKey;autoIncrement"`
|
|
||||||
DateTime int64 `json:"dateTime"`
|
|
||||||
Resource string `json:"resource"`
|
|
||||||
Tag string `json:"tag"`
|
|
||||||
Direction bool `json:"direction"`
|
|
||||||
Traffic int64 `json:"traffic"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Changes struct {
|
|
||||||
Id uint64 `json:"id" gorm:"primaryKey;autoIncrement"`
|
|
||||||
DateTime int64 `json:"dateTime"`
|
|
||||||
Actor string `json:"Actor"`
|
|
||||||
Key string `json:"key" form:"key"`
|
|
||||||
Action string `json:"action" form:"action"`
|
|
||||||
Index uint `json:"index" form:"index"`
|
|
||||||
Obj json.RawMessage `json:"obj" form:"obj"`
|
|
||||||
}
|
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
module s-ui
|
|
||||||
|
|
||||||
go 1.22.0
|
|
||||||
|
|
||||||
require (
|
|
||||||
github.com/gin-contrib/gzip v0.0.6
|
|
||||||
github.com/gin-gonic/gin v1.9.1
|
|
||||||
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7
|
|
||||||
github.com/v2fly/v2ray-core/v5 v5.13.0
|
|
||||||
gorm.io/driver/sqlite v1.5.5
|
|
||||||
gorm.io/gorm v1.25.7
|
|
||||||
)
|
|
||||||
|
|
||||||
require (
|
|
||||||
github.com/adrg/xdg v0.4.0 // indirect
|
|
||||||
github.com/bytedance/sonic v1.11.1 // indirect
|
|
||||||
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
|
|
||||||
github.com/chenzhuoyu/iasm v0.9.1 // indirect
|
|
||||||
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
|
|
||||||
github.com/go-ole/go-ole v1.3.0 // indirect
|
|
||||||
github.com/go-playground/locales v0.14.1 // indirect
|
|
||||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
|
||||||
github.com/goccy/go-json v0.10.2 // indirect
|
|
||||||
github.com/golang/protobuf v1.5.3 // indirect
|
|
||||||
github.com/gorilla/context v1.1.2 // indirect
|
|
||||||
github.com/gorilla/securecookie v1.1.2 // indirect
|
|
||||||
github.com/gorilla/sessions v1.2.2 // indirect
|
|
||||||
github.com/json-iterator/go v1.1.12 // indirect
|
|
||||||
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
|
|
||||||
github.com/leodido/go-urn v1.4.0 // indirect
|
|
||||||
github.com/lufia/plan9stats v0.0.0-20240226150601-1dcf7310316a // indirect
|
|
||||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
|
||||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
|
||||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
|
||||||
github.com/pires/go-proxyproto v0.7.0 // indirect
|
|
||||||
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect
|
|
||||||
github.com/shoenig/go-m1cpu v0.1.6 // indirect
|
|
||||||
github.com/tklauser/go-sysconf v0.3.13 // indirect
|
|
||||||
github.com/tklauser/numcpus v0.7.0 // indirect
|
|
||||||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
|
||||||
github.com/ugorji/go/codec v1.2.12 // indirect
|
|
||||||
github.com/yusufpapurcu/wmi v1.2.4 // indirect
|
|
||||||
golang.org/x/arch v0.7.0 // indirect
|
|
||||||
golang.org/x/crypto v0.20.0 // indirect
|
|
||||||
golang.org/x/net v0.21.0 // indirect
|
|
||||||
golang.org/x/sys v0.17.0 // indirect
|
|
||||||
golang.org/x/text v0.14.0 // indirect
|
|
||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240221002015-b0ce06bbee7c // indirect
|
|
||||||
google.golang.org/protobuf v1.32.0 // indirect
|
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
|
||||||
)
|
|
||||||
|
|
||||||
require (
|
|
||||||
github.com/Calidity/gin-sessions v1.3.1
|
|
||||||
github.com/gin-contrib/sse v0.1.0 // indirect
|
|
||||||
github.com/go-playground/validator/v10 v10.18.0 // indirect
|
|
||||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
|
||||||
github.com/jinzhu/now v1.1.5 // indirect
|
|
||||||
github.com/mattn/go-sqlite3 v2.0.3+incompatible // indirect
|
|
||||||
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
|
|
||||||
github.com/robfig/cron/v3 v3.0.1
|
|
||||||
github.com/shirou/gopsutil/v3 v3.24.1
|
|
||||||
google.golang.org/grpc v1.62.0
|
|
||||||
)
|
|
||||||
-311
@@ -1,311 +0,0 @@
|
|||||||
github.com/Calidity/gin-sessions v1.3.1 h1:nF3dCBWa7TZ4j26iYLwGRmzZy9YODhWoOS3fmi+snyE=
|
|
||||||
github.com/Calidity/gin-sessions v1.3.1/go.mod h1:I0+QE6qkO50TeN/n6If6novvxHk4Isvr23U8EdvPdns=
|
|
||||||
github.com/adrg/xdg v0.4.0 h1:RzRqFcjH4nE5C6oTAxhBtoE2IRyjBSa62SCbyPidvls=
|
|
||||||
github.com/adrg/xdg v0.4.0/go.mod h1:N6ag73EX4wyxeaoeHctc1mas01KZgsj5tYiAIwqJE/E=
|
|
||||||
github.com/aead/cmac v0.0.0-20160719120800-7af84192f0b1 h1:+JkXLHME8vLJafGhOH4aoV2Iu8bR55nU6iKMVfYVLjY=
|
|
||||||
github.com/aead/cmac v0.0.0-20160719120800-7af84192f0b1/go.mod h1:nuudZmJhzWtx2212z+pkuy7B6nkBqa+xwNXZHL1j8cg=
|
|
||||||
github.com/ajg/form v1.5.1 h1:t9c7v8JUKu/XxOGBU0yjNpaMloxGEJhUkqFRq0ibGeU=
|
|
||||||
github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY=
|
|
||||||
github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs=
|
|
||||||
github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
|
|
||||||
github.com/boljen/go-bitmap v0.0.0-20151001105940-23cd2fb0ce7d h1:zsO4lp+bjv5XvPTF58Vq+qgmZEYZttJK+CWtSZhKenI=
|
|
||||||
github.com/boljen/go-bitmap v0.0.0-20151001105940-23cd2fb0ce7d/go.mod h1:f1iKL6ZhUWvbk7PdWVmOaak10o86cqMUYEmn1CZNGEI=
|
|
||||||
github.com/bufbuild/protocompile v0.6.0 h1:Uu7WiSQ6Yj9DbkdnOe7U4mNKp58y9WDMKDn28/ZlunY=
|
|
||||||
github.com/bufbuild/protocompile v0.6.0/go.mod h1:YNP35qEYoYGme7QMtz5SBCoN4kL4g12jTtjuzRNdjpE=
|
|
||||||
github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM=
|
|
||||||
github.com/bytedance/sonic v1.10.0-rc/go.mod h1:ElCzW+ufi8qKqNW0FY314xriJhyJhuoJ3gFZdAHF7NM=
|
|
||||||
github.com/bytedance/sonic v1.11.1 h1:JC0+6c9FoWYYxakaoa+c5QTtJeiSZNeByOBhXtAFSn4=
|
|
||||||
github.com/bytedance/sonic v1.11.1/go.mod h1:iZcSUejdk5aukTND/Eu/ivjQuEL0Cu9/rf50Hi0u/g4=
|
|
||||||
github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY=
|
|
||||||
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk=
|
|
||||||
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d h1:77cEq6EriyTZ0g/qfRdp61a3Uu/AWrgIq2s0ClJV1g0=
|
|
||||||
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d/go.mod h1:8EPpVsBuRksnlj1mLy4AWzRNQYxauNi62uWcE3to6eA=
|
|
||||||
github.com/chenzhuoyu/iasm v0.9.0/go.mod h1:Xjy2NpN3h7aUqeqM+woSuuvxmIe6+DDsiNLIrkAmYog=
|
|
||||||
github.com/chenzhuoyu/iasm v0.9.1 h1:tUHQJXo3NhBqw6s33wkGn9SP3bvrWLdlVIJ3hQBL7P0=
|
|
||||||
github.com/chenzhuoyu/iasm v0.9.1/go.mod h1:Xjy2NpN3h7aUqeqM+woSuuvxmIe6+DDsiNLIrkAmYog=
|
|
||||||
github.com/cloudflare/circl v1.3.3 h1:fE/Qz0QdIGqeWfnwq0RE0R7MI51s0M2E4Ga9kq5AEMs=
|
|
||||||
github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA=
|
|
||||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
|
||||||
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/dgryski/go-metro v0.0.0-20211217172704-adc40b04c140 h1:y7y0Oa6UawqTFPCDw9JG6pdKt4F9pAhHv0B7FMGaGD0=
|
|
||||||
github.com/dgryski/go-metro v0.0.0-20211217172704-adc40b04c140/go.mod h1:c9O8+fpSOX1DM8cPNSkX/qsBWdkD4yd2dpciOWQjpBw=
|
|
||||||
github.com/ebfe/bcrypt_pbkdf v0.0.0-20140212075826-3c8d2dcb253a h1:YtdtTUN1iH97s+6PUjLnaiKSQj4oG1/EZ3N9bx6g4kU=
|
|
||||||
github.com/ebfe/bcrypt_pbkdf v0.0.0-20140212075826-3c8d2dcb253a/go.mod h1:/CZpbhAusDOobpcb9yubw46kdYjq0zRC0Wpg9a9zFQM=
|
|
||||||
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
|
|
||||||
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
|
|
||||||
github.com/gaukas/godicttls v0.0.4 h1:NlRaXb3J6hAnTmWdsEKb9bcSBD6BvcIjdGdeb0zfXbk=
|
|
||||||
github.com/gaukas/godicttls v0.0.4/go.mod h1:l6EenT4TLWgTdwslVb4sEMOCf7Bv0JAK67deKr9/NCI=
|
|
||||||
github.com/gin-contrib/gzip v0.0.6 h1:NjcunTcGAj5CO1gn4N8jHOSIeRFHIbn51z6K+xaN4d4=
|
|
||||||
github.com/gin-contrib/gzip v0.0.6/go.mod h1:QOJlmV2xmayAjkNS2Y8NQsMneuRShOU/kjovCXNuzzk=
|
|
||||||
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
|
|
||||||
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
|
|
||||||
github.com/gin-gonic/gin v1.8.1/go.mod h1:ji8BvRH1azfM+SYow9zQ6SZMvR8qOMZHmsCuWR9tTTk=
|
|
||||||
github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg=
|
|
||||||
github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU=
|
|
||||||
github.com/go-chi/chi/v5 v5.0.10 h1:rLz5avzKpjqxrYwXNfmjkrYYXOyLJd37pz53UFHC6vk=
|
|
||||||
github.com/go-chi/chi/v5 v5.0.10/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
|
|
||||||
github.com/go-chi/render v1.0.3 h1:AsXqd2a1/INaIfUSKq3G5uA8weYx20FOsM7uSoCyyt4=
|
|
||||||
github.com/go-chi/render v1.0.3/go.mod h1:/gr3hVkmYR0YlEy3LxCuVRFzEu9Ruok+gFqbIofjao0=
|
|
||||||
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
|
|
||||||
github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE=
|
|
||||||
github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78=
|
|
||||||
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
|
|
||||||
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
|
|
||||||
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
|
|
||||||
github.com/go-playground/locales v0.14.0/go.mod h1:sawfccIbzZTqEDETgFXqTho0QybSa7l++s0DH+LDiLs=
|
|
||||||
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
|
|
||||||
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
|
|
||||||
github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA=
|
|
||||||
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
|
|
||||||
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
|
|
||||||
github.com/go-playground/validator/v10 v10.10.0/go.mod h1:74x4gJWsvQexRdW8Pn3dXSGrTK4nAUsbPlLADvpJkos=
|
|
||||||
github.com/go-playground/validator/v10 v10.18.0 h1:BvolUXjp4zuvkZ5YN5t7ebzbhlUtPsPm2S9NAZ5nl9U=
|
|
||||||
github.com/go-playground/validator/v10 v10.18.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
|
|
||||||
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
|
|
||||||
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls=
|
|
||||||
github.com/goccy/go-json v0.9.7/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
|
|
||||||
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
|
|
||||||
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
|
|
||||||
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
|
|
||||||
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
|
|
||||||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
|
||||||
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
|
|
||||||
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
|
||||||
github.com/google/btree v1.1.2 h1:xf4v41cLI2Z6FxbKm+8Bu+m8ifhj15JuZ9sa0jZCMUU=
|
|
||||||
github.com/google/btree v1.1.2/go.mod h1:qOPhT0dTNdNzV6Z/lhRX0YXUafgPLFUh+gZMl761Gm4=
|
|
||||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
|
||||||
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
|
||||||
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
|
||||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
|
||||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
|
||||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
|
||||||
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
|
|
||||||
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
|
||||||
github.com/google/gopacket v1.1.19 h1:ves8RnFZPGiFnTS0uPQStjwru6uO6h+nlr9j6fL7kF8=
|
|
||||||
github.com/google/gopacket v1.1.19/go.mod h1:iJ8V8n6KS+z2U1A8pUwu8bW5SyEMkXJB8Yo/Vo+TKTo=
|
|
||||||
github.com/google/pprof v0.0.0-20230602150820-91b7bce49751 h1:hR7/MlvK23p6+lIw9SN1TigNLn9ZnF3W4SYRKq2gAHs=
|
|
||||||
github.com/google/pprof v0.0.0-20230602150820-91b7bce49751/go.mod h1:Jh3hGz2jkYak8qXPD19ryItVnUgpgeqzdkY/D0EaeuA=
|
|
||||||
github.com/gorilla/context v1.1.2 h1:WRkNAv2uoa03QNIc1A6u4O7DAGMUVoopZhkiXWA2V1o=
|
|
||||||
github.com/gorilla/context v1.1.2/go.mod h1:KDPwT9i/MeWHiLl90fuTgrt4/wPcv75vFAZLaOOcbxM=
|
|
||||||
github.com/gorilla/securecookie v1.1.2 h1:YCIWL56dvtr73r6715mJs5ZvhtnY73hBvEF8kXD8ePA=
|
|
||||||
github.com/gorilla/securecookie v1.1.2/go.mod h1:NfCASbcHqRSY+3a8tlWJwsQap2VX5pwzwo4h3eOamfo=
|
|
||||||
github.com/gorilla/sessions v1.2.2 h1:lqzMYz6bOfvn2WriPUjNByzeXIlVzURcPmgMczkmTjY=
|
|
||||||
github.com/gorilla/sessions v1.2.2/go.mod h1:ePLdVu+jbEgHH+KWw8I1z2wqd0BAdAQh/8LRvBeoNcQ=
|
|
||||||
github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY=
|
|
||||||
github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY=
|
|
||||||
github.com/jhump/protoreflect v1.15.3 h1:6SFRuqU45u9hIZPJAoZ8c28T3nK64BNdp9w6jFonzls=
|
|
||||||
github.com/jhump/protoreflect v1.15.3/go.mod h1:4ORHmSBmlCW8fh3xHmJMGyul1zNqZK4Elxc8qKP+p1k=
|
|
||||||
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
|
|
||||||
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
|
|
||||||
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
|
|
||||||
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
|
|
||||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
|
||||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
|
||||||
github.com/klauspost/compress v1.16.7 h1:2mk3MPGNzKyxErAw8YaohYh69+pa4sIQSC0fPGCFR9I=
|
|
||||||
github.com/klauspost/compress v1.16.7/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
|
|
||||||
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
|
|
||||||
github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM=
|
|
||||||
github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
|
|
||||||
github.com/klauspost/reedsolomon v1.11.7 h1:9uaHU0slncktTEEg4+7Vl7q7XUNMBUOK4R9gnKhMjAU=
|
|
||||||
github.com/klauspost/reedsolomon v1.11.7/go.mod h1:4bXRN+cVzMdml6ti7qLouuYi32KHJ5MGv0Qd8a47h6A=
|
|
||||||
github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M=
|
|
||||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
|
||||||
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
|
||||||
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
|
|
||||||
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
|
|
||||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
|
||||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
|
||||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
|
||||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
|
||||||
github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY=
|
|
||||||
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
|
|
||||||
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
|
|
||||||
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I=
|
|
||||||
github.com/lufia/plan9stats v0.0.0-20240226150601-1dcf7310316a h1:3Bm7EwfUQUvhNeKIkUct/gl9eod1TcXuj8stxvi/GoI=
|
|
||||||
github.com/lufia/plan9stats v0.0.0-20240226150601-1dcf7310316a/go.mod h1:ilwx/Dta8jXAgpFYFvSWEMwxmbWXyiUHkd5FwyKhb5k=
|
|
||||||
github.com/lunixbochs/struc v0.0.0-20200707160740-784aaebc1d40 h1:EnfXoSqDfSNJv0VBNqY/88RNnhSGYkrHaO0mmFGbVsc=
|
|
||||||
github.com/lunixbochs/struc v0.0.0-20200707160740-784aaebc1d40/go.mod h1:vy1vK6wD6j7xX6O6hXe621WabdtNkou2h7uRtTfRMyg=
|
|
||||||
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
|
|
||||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
|
||||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
|
||||||
github.com/mattn/go-sqlite3 v2.0.3+incompatible h1:gXHsfypPkaMZrKbD5209QV9jbUTJKjyR5WD3HYQSd+U=
|
|
||||||
github.com/mattn/go-sqlite3 v2.0.3+incompatible/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
|
|
||||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
|
||||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
|
|
||||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
|
||||||
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
|
||||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
|
||||||
github.com/mustafaturan/bus v1.0.2 h1:2x3ErwZ0uUPwwZ5ZZoknEQprdaxr68Yl3mY8jDye1Ws=
|
|
||||||
github.com/mustafaturan/bus v1.0.2/go.mod h1:h7gfehm8TThv4Dcaa+wDQG7r7j6p74v+7ftr0Rq9i1Q=
|
|
||||||
github.com/mustafaturan/monoton v1.0.0 h1:8SCej+JiNn0lyps7V+Jzc1CRAkDR4EZPWrTupQ61YCQ=
|
|
||||||
github.com/mustafaturan/monoton v1.0.0/go.mod h1:FOnE7NV3s3EWPXb8/7+/OSdiMBbdlkV0Lz8p1dc+vy8=
|
|
||||||
github.com/onsi/ginkgo/v2 v2.10.0 h1:sfUl4qgLdvkChZrWCYndY2EAu9BRIw1YphNAzy1VNWs=
|
|
||||||
github.com/onsi/ginkgo/v2 v2.10.0/go.mod h1:UDQOh5wbQUlMnkLfVaIUMtQ1Vus92oM+P2JX1aulgcE=
|
|
||||||
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7 h1:lDH9UUVJtmYCjyT0CI4q8xvlXPxeZ0gYCVvWbmPlp88=
|
|
||||||
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk=
|
|
||||||
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
|
|
||||||
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
|
|
||||||
github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8=
|
|
||||||
github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
|
|
||||||
github.com/pelletier/go-toml/v2 v2.0.1/go.mod h1:r9LEWfGN8R5k0VXJ+0BkIe7MYkRdwZOjgMj2KwnJFUo=
|
|
||||||
github.com/pelletier/go-toml/v2 v2.1.1 h1:LWAJwfNvjQZCFIDKWYQaM62NcYeYViCmWIwmOStowAI=
|
|
||||||
github.com/pelletier/go-toml/v2 v2.1.1/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
|
|
||||||
github.com/pion/dtls/v2 v2.2.7 h1:cSUBsETxepsCSFSxC3mc/aDo14qQLMSL+O6IjG28yV8=
|
|
||||||
github.com/pion/dtls/v2 v2.2.7/go.mod h1:8WiMkebSHFD0T+dIU+UeBaoV7kDhOW5oDCzZ7WZ/F9s=
|
|
||||||
github.com/pion/logging v0.2.2 h1:M9+AIj/+pxNsDfAT64+MAVgJO0rsyLnoJKCqf//DoeY=
|
|
||||||
github.com/pion/logging v0.2.2/go.mod h1:k0/tDVsRCX2Mb2ZEmTqNa7CWsQPc+YYCB7Q+5pahoms=
|
|
||||||
github.com/pion/randutil v0.1.0 h1:CFG1UdESneORglEsnimhUjf33Rwjubwj6xfiOXBa3mA=
|
|
||||||
github.com/pion/randutil v0.1.0/go.mod h1:XcJrSMMbbMRhASFVOlj/5hQial/Y8oH/HVo7TBZq+j8=
|
|
||||||
github.com/pion/sctp v1.8.7 h1:JnABvFakZueGAn4KU/4PSKg+GWbF6QWbKTWZOSGJjXw=
|
|
||||||
github.com/pion/sctp v1.8.7/go.mod h1:g1Ul+ARqZq5JEmoFy87Q/4CePtKnTJ1QCL9dBBdN6AU=
|
|
||||||
github.com/pion/transport/v2 v2.2.4 h1:41JJK6DZQYSeVLxILA2+F4ZkKb4Xd/tFJZRFZQ9QAlo=
|
|
||||||
github.com/pion/transport/v2 v2.2.4/go.mod h1:q2U/tf9FEfnSBGSW6w5Qp5PFWRLRj3NjLhCCgpRK4p0=
|
|
||||||
github.com/pires/go-proxyproto v0.7.0 h1:IukmRewDQFWC7kfnb66CSomk2q/seBuilHBYFwyq0Hs=
|
|
||||||
github.com/pires/go-proxyproto v0.7.0/go.mod h1:Vz/1JPY/OACxWGQNIRY2BeyDmpoaWmEP40O9LbuiFR4=
|
|
||||||
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
|
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
|
||||||
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE=
|
|
||||||
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 h1:o4JXh1EVt9k/+g42oCprj/FisM4qX9L3sZB3upGN2ZU=
|
|
||||||
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE=
|
|
||||||
github.com/quic-go/qtls-go1-20 v0.4.1 h1:D33340mCNDAIKBqXuAvexTNMUByrYmFYVfKfDN5nfFs=
|
|
||||||
github.com/quic-go/qtls-go1-20 v0.4.1/go.mod h1:X9Nh97ZL80Z+bX/gUXMbipO6OxdiDi58b/fMC9mAL+k=
|
|
||||||
github.com/quic-go/quic-go v0.40.0 h1:GYd1iznlKm7dpHD7pOVpUvItgMPo/jrMgDWZhMCecqw=
|
|
||||||
github.com/quic-go/quic-go v0.40.0/go.mod h1:PeN7kuVJ4xZbxSv/4OX6S1USOX8MJvydwpTx31vx60c=
|
|
||||||
github.com/refraction-networking/utls v1.5.4 h1:9k6EO2b8TaOGsQ7Pl7p9w6PUhx18/ZCeT0WNTZ7Uw4o=
|
|
||||||
github.com/refraction-networking/utls v1.5.4/go.mod h1:SPuDbBmgLGp8s+HLNc83FuavwZCFoMmExj+ltUHiHUw=
|
|
||||||
github.com/riobard/go-bloom v0.0.0-20200614022211-cdc8013cb5b3 h1:f/FNXud6gA3MNr8meMVVGxhp+QBTqY91tM8HjEuMjGg=
|
|
||||||
github.com/riobard/go-bloom v0.0.0-20200614022211-cdc8013cb5b3/go.mod h1:HgjTstvQsPGkxUsCd2KWxErBblirPizecHcpD3ffK+s=
|
|
||||||
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
|
|
||||||
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
|
|
||||||
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
|
|
||||||
github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8=
|
|
||||||
github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
|
|
||||||
github.com/secure-io/siv-go v0.0.0-20180922214919-5ff40651e2c4 h1:zOjq+1/uLzn/Xo40stbvjIY/yehG0+mfmlsiEmc0xmQ=
|
|
||||||
github.com/secure-io/siv-go v0.0.0-20180922214919-5ff40651e2c4/go.mod h1:aI+8yClBW+1uovkHw6HM01YXnYB8vohtB9C83wzx34E=
|
|
||||||
github.com/seiflotfy/cuckoofilter v0.0.0-20220411075957-e3b120b3f5fb h1:XfLJSPIOUX+osiMraVgIrMR27uMXnRJWGm1+GL8/63U=
|
|
||||||
github.com/seiflotfy/cuckoofilter v0.0.0-20220411075957-e3b120b3f5fb/go.mod h1:bR6DqgcAl1zTcOX8/pE2Qkj9XO00eCNqmKb7lXP8EAg=
|
|
||||||
github.com/shirou/gopsutil/v3 v3.24.1 h1:R3t6ondCEvmARp3wxODhXMTLC/klMa87h2PHUw5m7QI=
|
|
||||||
github.com/shirou/gopsutil/v3 v3.24.1/go.mod h1:UU7a2MSBQa+kW1uuDq8DeEBS8kmrnQwsv2b5O513rwU=
|
|
||||||
github.com/shoenig/go-m1cpu v0.1.6 h1:nxdKQNcEB6vzgA2E2bvzKIYRuNj7XNJ4S/aRSwKzFtM=
|
|
||||||
github.com/shoenig/go-m1cpu v0.1.6/go.mod h1:1JJMcUBvfNwpq05QDQVAnx3gUHr9IYF7GNg9SUEw2VQ=
|
|
||||||
github.com/shoenig/test v0.6.4 h1:kVTaSd7WLz5WZ2IaoM0RSzRsUD+m8wRR+5qvntpn4LU=
|
|
||||||
github.com/shoenig/test v0.6.4/go.mod h1:byHiCGXqrVaflBLAMq/srcZIHynQPQgeyvkvXnjqq0k=
|
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
|
||||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
|
||||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
|
||||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
|
||||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
|
||||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
|
||||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
|
||||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
|
||||||
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
|
||||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
|
||||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
|
||||||
github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI=
|
|
||||||
github.com/tklauser/go-sysconf v0.3.13 h1:GBUpcahXSpR2xN01jhkNAbTLRk2Yzgggk8IM08lq3r4=
|
|
||||||
github.com/tklauser/go-sysconf v0.3.13/go.mod h1:zwleP4Q4OehZHGn4CYZDipCgg9usW5IJePewFCGVEa0=
|
|
||||||
github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY=
|
|
||||||
github.com/tklauser/numcpus v0.7.0 h1:yjuerZP127QG9m5Zh/mSO4wqurYil27tHrqwRoRjpr4=
|
|
||||||
github.com/tklauser/numcpus v0.7.0/go.mod h1:bb6dMVcj8A42tSE7i32fsIUCbQNllK5iDguyOZRUzAY=
|
|
||||||
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
|
|
||||||
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
|
|
||||||
github.com/ugorji/go v1.2.7/go.mod h1:nF9osbDWLy6bDVv/Rtoh6QgnvNDpmCalQV5urGCCS6M=
|
|
||||||
github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY=
|
|
||||||
github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE=
|
|
||||||
github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
|
|
||||||
github.com/v2fly/BrowserBridge v0.0.0-20210430233438-0570fc1d7d08 h1:4Yh46CVE3k/lPq6hUbEdbB1u1anRBXLewm3k+L0iOMc=
|
|
||||||
github.com/v2fly/BrowserBridge v0.0.0-20210430233438-0570fc1d7d08/go.mod h1:KAuQNm+LWQCOFqdBcUgihPzRpVXRKzGbTNhfEfRZ4wY=
|
|
||||||
github.com/v2fly/VSign v0.0.0-20201108000810-e2adc24bf848 h1:p1UzXK6VAutXFFQMnre66h7g1BjRKUnLv0HfmmRoz7w=
|
|
||||||
github.com/v2fly/VSign v0.0.0-20201108000810-e2adc24bf848/go.mod h1:p80Bv154ZtrGpXMN15slDCqc9UGmfBuUzheDFBYaW/M=
|
|
||||||
github.com/v2fly/ss-bloomring v0.0.0-20210312155135-28617310f63e h1:5QefA066A1tF8gHIiADmOVOV5LS43gt3ONnlEl3xkwI=
|
|
||||||
github.com/v2fly/ss-bloomring v0.0.0-20210312155135-28617310f63e/go.mod h1:5t19P9LBIrNamL6AcMQOncg/r10y3Pc01AbHeMhwlpU=
|
|
||||||
github.com/v2fly/v2ray-core/v5 v5.13.0 h1:BDJfi3Ftx1NpQlZZPpeWJe3RDqRNyIVBs+YGG4RRMDU=
|
|
||||||
github.com/v2fly/v2ray-core/v5 v5.13.0/go.mod h1:Bc3gmQWLr8UR7xBSCYI9FbfKuVvqA9lbkeBTWNRRAS4=
|
|
||||||
github.com/vincent-petithory/dataurl v1.0.0 h1:cXw+kPto8NLuJtlMsI152irrVw9fRDX8AbShPRpg2CI=
|
|
||||||
github.com/vincent-petithory/dataurl v1.0.0/go.mod h1:FHafX5vmDzyP+1CQATJn7WFKc9CvnvxyvZy6I1MrG/U=
|
|
||||||
github.com/xiaokangwang/VLite v0.0.0-20220418190619-cff95160a432 h1:I/ATawgO2RerCq9ACwL0wBB8xNXZdE3J+93MCEHReRs=
|
|
||||||
github.com/xiaokangwang/VLite v0.0.0-20220418190619-cff95160a432/go.mod h1:QN7Go2ftTVfx0aCTh9RXHV8pkpi0FtmbwQw40dy61wQ=
|
|
||||||
github.com/xtaci/smux v1.5.24 h1:77emW9dtnOxxOQ5ltR+8BbsX1kzcOxQ5gB+aaV9hXOY=
|
|
||||||
github.com/xtaci/smux v1.5.24/go.mod h1:OMlQbT5vcgl2gb49mFkYo6SMf+zP3rcjcwQz7ZU7IGY=
|
|
||||||
github.com/yusufpapurcu/wmi v1.2.3/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
|
|
||||||
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
|
|
||||||
github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
|
|
||||||
go.starlark.net v0.0.0-20230612165344-9532f5667272 h1:2/wtqS591wZyD2OsClsVBKRPEvBsQt/Js+fsCiYhwu8=
|
|
||||||
go.starlark.net v0.0.0-20230612165344-9532f5667272/go.mod h1:jxU+3+j+71eXOW14274+SmmuW82qJzl6iZSeqEtTGds=
|
|
||||||
go.uber.org/mock v0.3.0 h1:3mUxI1No2/60yUYax92Pt8eNOEecx2D3lcXZh2NEZJo=
|
|
||||||
go.uber.org/mock v0.3.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc=
|
|
||||||
go4.org/netipx v0.0.0-20230303233057-f1b76eb4bb35 h1:nJAwRlGWZZDOD+6wni9KVUNHMpHko/OnRwsrCYeAzPo=
|
|
||||||
go4.org/netipx v0.0.0-20230303233057-f1b76eb4bb35/go.mod h1:TQvodOM+hJTioNQJilmLXu08JNb8i+ccq418+KWu1/Y=
|
|
||||||
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
|
|
||||||
golang.org/x/arch v0.7.0 h1:pskyeJh/3AmoQ8CPE95vxHLqp1G1GfGNXTmcl9NEKTc=
|
|
||||||
golang.org/x/arch v0.7.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
|
|
||||||
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
|
||||||
golang.org/x/crypto v0.20.0 h1:jmAMJJZXr5KiCw05dfYK9QnqaqKLYXijU23lsEdcQqg=
|
|
||||||
golang.org/x/crypto v0.20.0/go.mod h1:Xwo95rrVNIoSMx9wa1JroENMToLWn3RNVrTBpLHgZPQ=
|
|
||||||
golang.org/x/exp v0.0.0-20230725093048-515e97ebf090 h1:Di6/M8l0O2lCLc6VVRWhgCiApHV8MnQurBnFSHsQtNY=
|
|
||||||
golang.org/x/exp v0.0.0-20230725093048-515e97ebf090/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc=
|
|
||||||
golang.org/x/mod v0.13.0 h1:I/DsJXRlw/8l/0c24sM9yb0T4z9liZTduXvdAWYiysY=
|
|
||||||
golang.org/x/mod v0.13.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
|
|
||||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
|
||||||
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
|
|
||||||
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
|
|
||||||
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
|
|
||||||
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
|
||||||
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
|
||||||
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
|
|
||||||
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
|
||||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
|
||||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
|
||||||
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
|
|
||||||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
|
||||||
golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4=
|
|
||||||
golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
|
||||||
golang.org/x/tools v0.14.0 h1:jvNa2pY0M4r62jkRQ6RwEZZyPcymeL9XZMLBbV7U2nc=
|
|
||||||
golang.org/x/tools v0.14.0/go.mod h1:uYBEerGOWcJyEORxN+Ek8+TT266gXkNlHdJBwexUsBg=
|
|
||||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
|
||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240221002015-b0ce06bbee7c h1:NUsgEN92SQQqzfA+YtqYNqYmB3DMMYLlIwUZAQFVFbo=
|
|
||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240221002015-b0ce06bbee7c/go.mod h1:H4O17MA/PE9BsGx3w+a+W2VOLLD1Qf7oJneAoU6WktY=
|
|
||||||
google.golang.org/grpc v1.62.0 h1:HQKZ/fa1bXkX1oFOvSjmZEUL8wLSaZTjCcLAlmZRtdk=
|
|
||||||
google.golang.org/grpc v1.62.0/go.mod h1:IWTG0VlJLCh1SkC58F7np9ka9mx/WNkjl4PGJaiq+QE=
|
|
||||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
|
||||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
|
||||||
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
|
||||||
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
|
|
||||||
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
|
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
|
||||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
|
||||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
|
||||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
|
||||||
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
|
|
||||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
|
||||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
|
||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
|
||||||
gorm.io/driver/sqlite v1.5.5 h1:7MDMtUZhV065SilG62E0MquljeArQZNfJnjd9i9gx3E=
|
|
||||||
gorm.io/driver/sqlite v1.5.5/go.mod h1:6NgQ7sQWAIFsPrJJl1lSNSu2TABh0ZZ/zm5fosATavE=
|
|
||||||
gorm.io/gorm v1.25.7 h1:VsD6acwRjz2zFxGO50gPO6AkNs7KKnvfzUjHQhZDz/A=
|
|
||||||
gorm.io/gorm v1.25.7/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
|
|
||||||
gvisor.dev/gvisor v0.0.0-20231020174304-b8a429915ff1 h1:qDCwdCWECGnwQSQC01Dpnp09fRHxJs9PbktotUqG+hs=
|
|
||||||
gvisor.dev/gvisor v0.0.0-20231020174304-b8a429915ff1/go.mod h1:8hmigyCdYtw5xJGfQDJzSH5Ju8XEIDBnpyi8+O6GRt8=
|
|
||||||
lukechampine.com/blake3 v1.2.1 h1:YuqqRuaqsGV71BV/nm9xlI0MKUv4QC54jQnBChWbGnI=
|
|
||||||
lukechampine.com/blake3 v1.2.1/go.mod h1:0OFRp7fBtAylGVCO40o87sbupkyIGgbpv1+M1k1LM6k=
|
|
||||||
nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=
|
|
||||||
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
|
|
||||||
@@ -1,93 +0,0 @@
|
|||||||
package service
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"s-ui/database"
|
|
||||||
"s-ui/database/model"
|
|
||||||
"s-ui/logger"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"gorm.io/gorm"
|
|
||||||
)
|
|
||||||
|
|
||||||
type ClientService struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *ClientService) GetAll() (string, error) {
|
|
||||||
db := database.GetDB()
|
|
||||||
clients := []model.Client{}
|
|
||||||
err := db.Model(model.Client{}).Scan(&clients).Error
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
data, err := json.Marshal(clients)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
return string(data), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *ClientService) Save(tx *gorm.DB, changes []model.Changes) error {
|
|
||||||
var err error
|
|
||||||
for _, change := range changes {
|
|
||||||
client := model.Client{}
|
|
||||||
err = json.Unmarshal(change.Obj, &client)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
switch change.Action {
|
|
||||||
case "new":
|
|
||||||
err = tx.Create(&client).Error
|
|
||||||
case "del":
|
|
||||||
err = tx.Where("id = ?", change.Index).Delete(model.Client{}).Error
|
|
||||||
default:
|
|
||||||
err = tx.Save(client).Error
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *ClientService) DepleteClients() ([]string, []string, error) {
|
|
||||||
var err error
|
|
||||||
var clients []model.Client
|
|
||||||
var changes []model.Changes
|
|
||||||
now := time.Now().Unix()
|
|
||||||
db := database.GetDB()
|
|
||||||
err = db.Model(model.Client{}).Where("enable = true AND ((volume >0 AND up+down > volume) OR (expiry > 0 AND expiry < ?))", now).Scan(&clients).Error
|
|
||||||
if err != nil {
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var users, inbounds []string
|
|
||||||
for _, client := range clients {
|
|
||||||
logger.Debug("Client ", client.Name, " is going to be disabled")
|
|
||||||
users = append(users, client.Name)
|
|
||||||
userInbounds := strings.Split(client.Inbounds, ",")
|
|
||||||
inbounds = append(inbounds, userInbounds...)
|
|
||||||
changes = append(changes, model.Changes{
|
|
||||||
DateTime: time.Now().Unix(),
|
|
||||||
Actor: "DepleteJob",
|
|
||||||
Key: "clients",
|
|
||||||
Action: "disable",
|
|
||||||
Obj: json.RawMessage(client.Name),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save changes
|
|
||||||
if len(changes) > 0 {
|
|
||||||
err = db.Model(model.Client{}).Where("enable = true AND ((volume >0 AND up+down > volume) OR (expiry > 0 AND expiry < ?))", now).Update("enable", false).Error
|
|
||||||
if err != nil {
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
err = db.Model(model.Changes{}).Create(&changes).Error
|
|
||||||
if err != nil {
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return users, inbounds, nil
|
|
||||||
}
|
|
||||||
@@ -1,322 +0,0 @@
|
|||||||
package service
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"os"
|
|
||||||
"s-ui/config"
|
|
||||||
"s-ui/database"
|
|
||||||
"s-ui/database/model"
|
|
||||||
"s-ui/singbox"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
var ApiAddr string
|
|
||||||
|
|
||||||
type ConfigService struct {
|
|
||||||
ClientService
|
|
||||||
singbox.Controller
|
|
||||||
SettingService
|
|
||||||
}
|
|
||||||
|
|
||||||
type SingBoxConfig struct {
|
|
||||||
Log json.RawMessage `json:"log"`
|
|
||||||
Dns json.RawMessage `json:"dns"`
|
|
||||||
Ntp json.RawMessage `json:"ntp"`
|
|
||||||
Inbounds []json.RawMessage `json:"inbounds"`
|
|
||||||
Outbounds []json.RawMessage `json:"outbounds"`
|
|
||||||
Route json.RawMessage `json:"route"`
|
|
||||||
Experimental json.RawMessage `json:"experimental"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewConfigService() *ConfigService {
|
|
||||||
return &ConfigService{}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *ConfigService) InitConfig() error {
|
|
||||||
configPath := config.GetBinFolderPath()
|
|
||||||
data, err := os.ReadFile(configPath + "/config.json")
|
|
||||||
if err != nil {
|
|
||||||
if os.IsNotExist(err) {
|
|
||||||
defaultConfig := []byte(config.GetDefaultConfig())
|
|
||||||
err = os.MkdirAll(configPath, 01764)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
err = os.WriteFile(configPath+"/config.json", defaultConfig, 0764)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
data = defaultConfig
|
|
||||||
} else {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return s.RefreshApiAddr(&data)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *ConfigService) GetConfig() (*[]byte, error) {
|
|
||||||
configPath := config.GetBinFolderPath()
|
|
||||||
data, err := os.ReadFile(configPath + "/config.json")
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &data, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *ConfigService) SaveChanges(changes map[string]string, loginUser string) error {
|
|
||||||
var err error
|
|
||||||
var clientChanges, settingChanges, configChanges []model.Changes
|
|
||||||
if _, ok := changes["clients"]; ok {
|
|
||||||
err = json.Unmarshal([]byte(changes["clients"]), &clientChanges)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if _, ok := changes["settings"]; ok {
|
|
||||||
err = json.Unmarshal([]byte(changes["settings"]), &settingChanges)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if _, ok := changes["config"]; ok {
|
|
||||||
err = json.Unmarshal([]byte(changes["config"]), &configChanges)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
db := database.GetDB()
|
|
||||||
tx := db.Begin()
|
|
||||||
defer func() {
|
|
||||||
if err == nil {
|
|
||||||
tx.Commit()
|
|
||||||
} else {
|
|
||||||
tx.Rollback()
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
if len(clientChanges) > 0 {
|
|
||||||
err = s.ClientService.Save(tx, clientChanges)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if len(settingChanges) > 0 {
|
|
||||||
err = s.SettingService.Save(tx, settingChanges)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if len(configChanges) > 0 {
|
|
||||||
singboxConfig, err := s.GetConfig()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
newConfig := SingBoxConfig{}
|
|
||||||
err = json.Unmarshal(*singboxConfig, &newConfig)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
for _, change := range configChanges {
|
|
||||||
rawObject := change.Obj
|
|
||||||
switch change.Key {
|
|
||||||
case "all":
|
|
||||||
err = json.Unmarshal(rawObject, &newConfig)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
case "log":
|
|
||||||
newConfig.Log = rawObject
|
|
||||||
case "dns":
|
|
||||||
newConfig.Dns = rawObject
|
|
||||||
case "ntp":
|
|
||||||
newConfig.Ntp = rawObject
|
|
||||||
case "route":
|
|
||||||
newConfig.Route = rawObject
|
|
||||||
case "experimental":
|
|
||||||
newConfig.Experimental = rawObject
|
|
||||||
case "inbounds":
|
|
||||||
if change.Action == "edit" {
|
|
||||||
newConfig.Inbounds[change.Index] = rawObject
|
|
||||||
} else if change.Action == "del" {
|
|
||||||
newConfig.Inbounds = append(newConfig.Inbounds[:change.Index], newConfig.Inbounds[change.Index+1:]...)
|
|
||||||
} else {
|
|
||||||
newConfig.Inbounds = append(newConfig.Inbounds, rawObject)
|
|
||||||
}
|
|
||||||
case "outbounds":
|
|
||||||
if change.Action == "edit" {
|
|
||||||
newConfig.Outbounds[change.Index] = rawObject
|
|
||||||
} else {
|
|
||||||
newConfig.Outbounds = append(newConfig.Outbounds, rawObject)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save to config.json
|
|
||||||
data, err := json.MarshalIndent(newConfig, "", " ")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
err = s.Save(&data)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Log changes
|
|
||||||
dt := time.Now().Unix()
|
|
||||||
allChanges := append(append(clientChanges, settingChanges...), configChanges...)
|
|
||||||
for index := range allChanges {
|
|
||||||
allChanges[index].DateTime = dt
|
|
||||||
allChanges[index].Actor = loginUser
|
|
||||||
}
|
|
||||||
err = tx.Model(model.Changes{}).Create(&allChanges).Error
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *ConfigService) CheckChnages(lu string) (bool, error) {
|
|
||||||
if lu == "" {
|
|
||||||
return true, nil
|
|
||||||
}
|
|
||||||
db := database.GetDB()
|
|
||||||
var count int64
|
|
||||||
err := db.Model(model.Changes{}).Where("date_time > " + lu).Count(&count).Error
|
|
||||||
return count > 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *ConfigService) Save(data *[]byte) error {
|
|
||||||
configPath := config.GetBinFolderPath()
|
|
||||||
_, err := os.Stat(configPath + "/config.json")
|
|
||||||
if os.IsNotExist(err) {
|
|
||||||
err = os.MkdirAll(configPath, 01764)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
} else if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = os.WriteFile(configPath+"/config.json", *data, 0764)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
s.RefreshApiAddr(data)
|
|
||||||
s.Controller.Restart()
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *ConfigService) RefreshApiAddr(data *[]byte) error {
|
|
||||||
Env_API := config.GetEnvApi()
|
|
||||||
if len(Env_API) > 0 {
|
|
||||||
ApiAddr = Env_API
|
|
||||||
} else {
|
|
||||||
var err error
|
|
||||||
if data == nil {
|
|
||||||
data, err = s.GetConfig()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
singboxConfig := SingBoxConfig{}
|
|
||||||
err = json.Unmarshal(*data, &singboxConfig)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
var experimental struct {
|
|
||||||
V2rayApi struct {
|
|
||||||
Listen string `json:"listen"`
|
|
||||||
Stats interface{} `jaon:"stats"`
|
|
||||||
} `json:"v2ray_api"`
|
|
||||||
}
|
|
||||||
err = json.Unmarshal(singboxConfig.Experimental, &experimental)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
ApiAddr = experimental.V2rayApi.Listen
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *ConfigService) DepleteClients() error {
|
|
||||||
users, inbounds, err := s.ClientService.DepleteClients()
|
|
||||||
if err != nil || len(users) == 0 || len(inbounds) == 0 {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
singboxConfig, err := s.GetConfig()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
newConfig := SingBoxConfig{}
|
|
||||||
err = json.Unmarshal(*singboxConfig, &newConfig)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
for inbound_index, inbound := range newConfig.Inbounds {
|
|
||||||
var inboundJson map[string]interface{}
|
|
||||||
json.Unmarshal(inbound, &inboundJson)
|
|
||||||
if s.contains(inbounds, inboundJson["tag"].(string)) {
|
|
||||||
inbound_users, ok := inboundJson["users"].([]interface{})
|
|
||||||
if ok {
|
|
||||||
var updatedUsers []interface{}
|
|
||||||
for _, user := range inbound_users {
|
|
||||||
userMap, ok := user.(map[string]interface{})
|
|
||||||
if ok {
|
|
||||||
name, exists := userMap["name"].(string)
|
|
||||||
if exists && s.contains(users, name) {
|
|
||||||
// Skip the user exists
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
username, exists := userMap["username"].(string)
|
|
||||||
if exists && s.contains(users, username) {
|
|
||||||
// Skip the username exists
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
updatedUsers = append(updatedUsers, user)
|
|
||||||
}
|
|
||||||
// Exception for Naive and ShadowTLSv3
|
|
||||||
if len(updatedUsers) == 0 {
|
|
||||||
if inboundJson["type"].(string) == "naive" ||
|
|
||||||
(inboundJson["type"].(string) == "shadowtls" &&
|
|
||||||
inboundJson["version"].(float64) == 3) {
|
|
||||||
updatedUsers = append(updatedUsers, make(map[string]interface{}))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inboundJson["users"] = updatedUsers
|
|
||||||
}
|
|
||||||
}
|
|
||||||
modifiedInbound, err := json.MarshalIndent(inboundJson, "", " ")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
newConfig.Inbounds[inbound_index] = modifiedInbound
|
|
||||||
}
|
|
||||||
modifiedConfig, err := json.MarshalIndent(newConfig, "", " ")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
err = s.Save(&modifiedConfig)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *ConfigService) contains(slice []string, item string) bool {
|
|
||||||
for _, str := range slice {
|
|
||||||
if str == item {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
@@ -1,137 +0,0 @@
|
|||||||
package service
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
"runtime"
|
|
||||||
"s-ui/config"
|
|
||||||
"s-ui/logger"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/shirou/gopsutil/v3/cpu"
|
|
||||||
"github.com/shirou/gopsutil/v3/host"
|
|
||||||
"github.com/shirou/gopsutil/v3/mem"
|
|
||||||
"github.com/shirou/gopsutil/v3/net"
|
|
||||||
)
|
|
||||||
|
|
||||||
type ServerService struct {
|
|
||||||
SingBoxService
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *ServerService) GetStatus(request string) *map[string]interface{} {
|
|
||||||
status := make(map[string]interface{}, 0)
|
|
||||||
requests := strings.Split(request, ",")
|
|
||||||
for _, req := range requests {
|
|
||||||
switch req {
|
|
||||||
case "cpu":
|
|
||||||
status["cpu"] = s.GetCpuPercent()
|
|
||||||
case "mem":
|
|
||||||
status["mem"] = s.GetMemInfo()
|
|
||||||
case "net":
|
|
||||||
status["net"] = s.GetNetInfo()
|
|
||||||
case "sys":
|
|
||||||
status["uptime"] = s.GetUptime()
|
|
||||||
status["sys"] = s.GetSystemInfo()
|
|
||||||
case "sbd":
|
|
||||||
status["sbd"] = s.GetSingboxInfo()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return &status
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *ServerService) GetCpuPercent() float64 {
|
|
||||||
percents, err := cpu.Percent(0, false)
|
|
||||||
if err != nil {
|
|
||||||
logger.Warning("get cpu percent failed:", err)
|
|
||||||
return 0
|
|
||||||
} else {
|
|
||||||
return percents[0]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *ServerService) GetUptime() uint64 {
|
|
||||||
upTime, err := host.Uptime()
|
|
||||||
if err != nil {
|
|
||||||
logger.Warning("get uptime failed:", err)
|
|
||||||
return 0
|
|
||||||
} else {
|
|
||||||
return upTime
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *ServerService) GetMemInfo() map[string]interface{} {
|
|
||||||
info := make(map[string]interface{}, 0)
|
|
||||||
memInfo, err := mem.VirtualMemory()
|
|
||||||
if err != nil {
|
|
||||||
logger.Warning("get virtual memory failed:", err)
|
|
||||||
} else {
|
|
||||||
info["current"] = memInfo.Used
|
|
||||||
info["total"] = memInfo.Total
|
|
||||||
}
|
|
||||||
return info
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *ServerService) GetNetInfo() map[string]interface{} {
|
|
||||||
info := make(map[string]interface{}, 0)
|
|
||||||
ioStats, err := net.IOCounters(false)
|
|
||||||
if err != nil {
|
|
||||||
logger.Warning("get io counters failed:", err)
|
|
||||||
} else if len(ioStats) > 0 {
|
|
||||||
ioStat := ioStats[0]
|
|
||||||
info["sent"] = ioStat.BytesSent
|
|
||||||
info["recv"] = ioStat.BytesRecv
|
|
||||||
info["psent"] = ioStat.PacketsSent
|
|
||||||
info["precv"] = ioStat.PacketsRecv
|
|
||||||
} else {
|
|
||||||
logger.Warning("can not find io counters")
|
|
||||||
}
|
|
||||||
return info
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *ServerService) GetSingboxInfo() map[string]interface{} {
|
|
||||||
info := make(map[string]interface{}, 0)
|
|
||||||
if s.SingBoxService.IsRunning() {
|
|
||||||
info["running"] = true
|
|
||||||
sysStats, _ := s.SingBoxService.GetSysStats()
|
|
||||||
info["stats"] = sysStats
|
|
||||||
} else {
|
|
||||||
info["running"] = false
|
|
||||||
}
|
|
||||||
return info
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *ServerService) GetSystemInfo() map[string]interface{} {
|
|
||||||
info := make(map[string]interface{}, 0)
|
|
||||||
var rtm runtime.MemStats
|
|
||||||
runtime.ReadMemStats(&rtm)
|
|
||||||
|
|
||||||
info["appMem"] = rtm.Sys
|
|
||||||
info["appThreads"] = uint32(runtime.NumGoroutine())
|
|
||||||
cpuInfo, err := cpu.Info()
|
|
||||||
if err == nil {
|
|
||||||
info["cpuType"] = cpuInfo[0].ModelName
|
|
||||||
}
|
|
||||||
info["cpuCount"] = runtime.NumCPU()
|
|
||||||
info["hostName"], _ = os.Hostname()
|
|
||||||
info["appVersion"] = config.GetVersion()
|
|
||||||
ipv4 := make([]string, 0)
|
|
||||||
ipv6 := make([]string, 0)
|
|
||||||
// get ip address
|
|
||||||
netInterfaces, _ := net.Interfaces()
|
|
||||||
for i := 0; i < len(netInterfaces); i++ {
|
|
||||||
if len(netInterfaces[i].Flags) > 2 && netInterfaces[i].Flags[0] == "up" && netInterfaces[i].Flags[1] != "loopback" {
|
|
||||||
addrs := netInterfaces[i].Addrs
|
|
||||||
|
|
||||||
for _, address := range addrs {
|
|
||||||
if strings.Contains(address.Addr, ".") {
|
|
||||||
ipv4 = append(ipv4, address.Addr)
|
|
||||||
} else if address.Addr[0:6] != "fe80::" {
|
|
||||||
ipv6 = append(ipv6, address.Addr)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
info["ipv4"] = ipv4
|
|
||||||
info["ipv6"] = ipv6
|
|
||||||
|
|
||||||
return info
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
package service
|
|
||||||
|
|
||||||
import (
|
|
||||||
"s-ui/singbox"
|
|
||||||
)
|
|
||||||
|
|
||||||
type SingBoxService struct {
|
|
||||||
singbox.V2rayAPI
|
|
||||||
singbox.Controller
|
|
||||||
StatsService
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *SingBoxService) GetStats() error {
|
|
||||||
s.V2rayAPI.Init(ApiAddr)
|
|
||||||
defer s.V2rayAPI.Close()
|
|
||||||
stats, err := s.V2rayAPI.GetStats(true)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
err = s.StatsService.SaveStats(stats)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *SingBoxService) GetSysStats() (*map[string]interface{}, error) {
|
|
||||||
s.V2rayAPI.Init(ApiAddr)
|
|
||||||
defer s.V2rayAPI.Close()
|
|
||||||
resp, err := s.V2rayAPI.GetSysStats()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
result := make(map[string]interface{})
|
|
||||||
result["NumGoroutine"] = resp.NumGoroutine
|
|
||||||
result["Alloc"] = resp.Alloc
|
|
||||||
result["Uptime"] = resp.Uptime
|
|
||||||
|
|
||||||
return &result, nil
|
|
||||||
}
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
package singbox
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"io/fs"
|
|
||||||
"os"
|
|
||||||
"os/exec"
|
|
||||||
"s-ui/config"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
var serviceName = "sing-box"
|
|
||||||
|
|
||||||
type Controller struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Controller) GetBinaryName() string {
|
|
||||||
return "sing-box"
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Controller) GetBinaryPath() string {
|
|
||||||
return config.GetBinFolderPath() + "/" + s.GetBinaryName()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Controller) GetConfigPath() string {
|
|
||||||
return config.GetBinFolderPath() + "/config.json"
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Controller) IsRunning() bool {
|
|
||||||
cmd := exec.Command("pgrep", "sing-box")
|
|
||||||
output, err := cmd.Output()
|
|
||||||
if err != nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// If pgrep found the Controller, its output will not be empty
|
|
||||||
return strings.TrimSpace(string(output)) != ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Controller) signalSingbox(signal string) error {
|
|
||||||
return os.WriteFile(config.GetBinFolderPath()+"/signal", []byte(signal), fs.ModePerm)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Controller) Restart() error {
|
|
||||||
return s.signalSingbox("restart")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Controller) Stop() error {
|
|
||||||
if !s.IsRunning() {
|
|
||||||
return errors.New("Sing-Box is not running")
|
|
||||||
}
|
|
||||||
|
|
||||||
return s.signalSingbox("stop")
|
|
||||||
}
|
|
||||||
@@ -1,95 +0,0 @@
|
|||||||
package singbox
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"regexp"
|
|
||||||
"s-ui/database/model"
|
|
||||||
"s-ui/util/common"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
statsService "github.com/v2fly/v2ray-core/v5/app/stats/command"
|
|
||||||
"google.golang.org/grpc"
|
|
||||||
)
|
|
||||||
|
|
||||||
type V2rayAPI struct {
|
|
||||||
StatsServiceClient *statsService.StatsServiceClient
|
|
||||||
grpcClient *grpc.ClientConn
|
|
||||||
isConnected bool
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *V2rayAPI) Init(ApiAddr string) (err error) {
|
|
||||||
if len(ApiAddr) == 0 {
|
|
||||||
return common.NewError("The api address is wrong: ", ApiAddr)
|
|
||||||
}
|
|
||||||
v.grpcClient, err = grpc.Dial(ApiAddr, grpc.WithInsecure())
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
v.isConnected = true
|
|
||||||
|
|
||||||
ssClient := statsService.NewStatsServiceClient(v.grpcClient)
|
|
||||||
|
|
||||||
v.StatsServiceClient = &ssClient
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *V2rayAPI) Close() {
|
|
||||||
v.grpcClient.Close()
|
|
||||||
v.StatsServiceClient = nil
|
|
||||||
v.isConnected = false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *V2rayAPI) GetStats(reset bool) ([]*model.Stats, error) {
|
|
||||||
if v.grpcClient == nil {
|
|
||||||
return nil, common.NewError("v2ray api is not initialized")
|
|
||||||
}
|
|
||||||
var trafficRegex = regexp.MustCompile("(inbound|outbound|user)>>>([^>]+)>>>traffic>>>(downlink|uplink)")
|
|
||||||
|
|
||||||
client := *v.StatsServiceClient
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
|
|
||||||
defer cancel()
|
|
||||||
request := &statsService.QueryStatsRequest{
|
|
||||||
Reset_: reset,
|
|
||||||
}
|
|
||||||
resp, err := client.QueryStats(ctx, request)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
dt := time.Now().Unix()
|
|
||||||
stats := make([]*model.Stats, 0)
|
|
||||||
for _, stat := range resp.GetStat() {
|
|
||||||
if stat.Value > 0 {
|
|
||||||
matchs := trafficRegex.FindStringSubmatch(stat.Name)
|
|
||||||
if len(matchs) > 3 {
|
|
||||||
stat := model.Stats{
|
|
||||||
DateTime: dt,
|
|
||||||
Resource: matchs[1],
|
|
||||||
Tag: matchs[2],
|
|
||||||
Direction: matchs[3] == "uplink",
|
|
||||||
Traffic: stat.Value,
|
|
||||||
}
|
|
||||||
stats = append(stats, &stat)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return stats, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *V2rayAPI) GetSysStats() (*statsService.SysStatsResponse, error) {
|
|
||||||
if v.grpcClient == nil {
|
|
||||||
return nil, common.NewError("v2ray api is not initialized")
|
|
||||||
}
|
|
||||||
client := *v.StatsServiceClient
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
|
|
||||||
defer cancel()
|
|
||||||
request := &statsService.SysStatsRequest{}
|
|
||||||
resp, err := client.GetSysStats(ctx, request)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return resp, nil
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
package sub
|
|
||||||
|
|
||||||
import (
|
|
||||||
"s-ui/logger"
|
|
||||||
"s-ui/service"
|
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
)
|
|
||||||
|
|
||||||
type SubHandler struct {
|
|
||||||
service.SettingService
|
|
||||||
SubService
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewSubHandler(g *gin.RouterGroup) {
|
|
||||||
a := &SubHandler{}
|
|
||||||
a.initRouter(g)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *SubHandler) initRouter(g *gin.RouterGroup) {
|
|
||||||
g.GET("/:subid", s.subs)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *SubHandler) subs(c *gin.Context) {
|
|
||||||
subId := c.Param("subid")
|
|
||||||
result, headers, err := s.SubService.GetSubs(subId)
|
|
||||||
if err != nil || result == nil {
|
|
||||||
logger.Error(err)
|
|
||||||
c.String(400, "Error!")
|
|
||||||
} else {
|
|
||||||
|
|
||||||
// Add headers
|
|
||||||
c.Writer.Header().Set("Subscription-Userinfo", headers[0])
|
|
||||||
c.Writer.Header().Set("Profile-Update-Interval", headers[1])
|
|
||||||
c.Writer.Header().Set("Profile-Title", headers[2])
|
|
||||||
|
|
||||||
c.String(200, *result)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,181 +0,0 @@
|
|||||||
package sub
|
|
||||||
|
|
||||||
import (
|
|
||||||
"crypto/tls"
|
|
||||||
"encoding/base64"
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"net/http"
|
|
||||||
"s-ui/database"
|
|
||||||
"s-ui/database/model"
|
|
||||||
"s-ui/logger"
|
|
||||||
"s-ui/service"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
type SubService struct {
|
|
||||||
service.SettingService
|
|
||||||
}
|
|
||||||
|
|
||||||
type Link struct {
|
|
||||||
Type string `json:"type"`
|
|
||||||
Remark string `json:"remark"`
|
|
||||||
Uri string `json:"uri"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *SubService) GetSubs(subId string) (*string, []string, error) {
|
|
||||||
var err error
|
|
||||||
|
|
||||||
db := database.GetDB()
|
|
||||||
client := &model.Client{}
|
|
||||||
err = db.Model(model.Client{}).Where("enable = true and name = ?", subId).First(client).Error
|
|
||||||
if err != nil {
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
links := []Link{}
|
|
||||||
err = json.Unmarshal([]byte(client.Links), &links)
|
|
||||||
if err != nil {
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
clientInfo := ""
|
|
||||||
subShowInfo, _ := s.SettingService.GetSubShowInfo()
|
|
||||||
if subShowInfo {
|
|
||||||
clientInfo = s.getClientInfo(client)
|
|
||||||
}
|
|
||||||
|
|
||||||
var result string
|
|
||||||
for _, link := range links {
|
|
||||||
switch link.Type {
|
|
||||||
case "external":
|
|
||||||
result += fmt.Sprintln(link.Uri)
|
|
||||||
case "sub":
|
|
||||||
result += s.getExternalSub(link.Uri)
|
|
||||||
case "local":
|
|
||||||
result += fmt.Sprintln(s.addClientInfo(link.Uri, clientInfo))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var headers []string
|
|
||||||
updateInterval, _ := s.SettingService.GetSubUpdates()
|
|
||||||
headers = append(headers, fmt.Sprintf("upload=%d; download=%d; total=%d; expire=%d", client.Up, client.Down, client.Volume, client.Expiry))
|
|
||||||
headers = append(headers, fmt.Sprintf("%d", updateInterval))
|
|
||||||
headers = append(headers, subId)
|
|
||||||
|
|
||||||
subEncode, _ := s.SettingService.GetSubEncode()
|
|
||||||
if subEncode {
|
|
||||||
result = base64.StdEncoding.EncodeToString([]byte(result))
|
|
||||||
}
|
|
||||||
|
|
||||||
return &result, headers, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *SubService) getClientInfo(c *model.Client) string {
|
|
||||||
now := time.Now().Unix()
|
|
||||||
|
|
||||||
var result []string
|
|
||||||
if vol := c.Volume - (c.Up + c.Down); vol > 0 {
|
|
||||||
result = append(result, fmt.Sprintf("%s%s", s.formatTraffic(vol), "📊"))
|
|
||||||
}
|
|
||||||
if c.Expiry > 0 {
|
|
||||||
result = append(result, fmt.Sprintf("%d%s⏳", (c.Expiry-now)/86400, "Days"))
|
|
||||||
}
|
|
||||||
if len(result) > 0 {
|
|
||||||
return " " + strings.Join(result, " ")
|
|
||||||
} else {
|
|
||||||
return " ♾"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *SubService) addClientInfo(uri string, clientInfo string) string {
|
|
||||||
protocol := strings.Split(uri, "://")
|
|
||||||
if len(protocol) < 2 {
|
|
||||||
return uri
|
|
||||||
}
|
|
||||||
switch protocol[0] {
|
|
||||||
case "vmess":
|
|
||||||
var vmessJson map[string]interface{}
|
|
||||||
config, err := base64.StdEncoding.DecodeString(protocol[1])
|
|
||||||
if err != nil {
|
|
||||||
logger.Warning("sub: Error decoding vmess content:", err)
|
|
||||||
return uri
|
|
||||||
}
|
|
||||||
err = json.Unmarshal(config, &vmessJson)
|
|
||||||
if err != nil {
|
|
||||||
logger.Warning("sub: Error decoding vmess content:", err)
|
|
||||||
return uri
|
|
||||||
}
|
|
||||||
vmessJson["ps"] = vmessJson["ps"].(string) + clientInfo
|
|
||||||
result, err := json.MarshalIndent(vmessJson, "", " ")
|
|
||||||
if err != nil {
|
|
||||||
logger.Warning("sub: Error decoding vmess + clientInfo content:", err)
|
|
||||||
return uri
|
|
||||||
}
|
|
||||||
return "vmess://" + base64.StdEncoding.EncodeToString(result)
|
|
||||||
default:
|
|
||||||
return uri + clientInfo
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *SubService) getExternalSub(url string) string {
|
|
||||||
tr := &http.Transport{
|
|
||||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
|
||||||
}
|
|
||||||
|
|
||||||
client := &http.Client{Transport: tr}
|
|
||||||
|
|
||||||
// Make the HTTP request
|
|
||||||
response, err := client.Get(url)
|
|
||||||
if err != nil {
|
|
||||||
logger.Warning("sub: Error making HTTP request:", err)
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
defer response.Body.Close()
|
|
||||||
|
|
||||||
// Read the response body
|
|
||||||
body, err := io.ReadAll(response.Body)
|
|
||||||
if err != nil {
|
|
||||||
logger.Warning("sub: Error reading response body:", err)
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if the content is Base64 encoded
|
|
||||||
isBase64 := s.isBase64Encoded(string(body))
|
|
||||||
if isBase64 {
|
|
||||||
// Decode Base64 content
|
|
||||||
decodedText, err := base64.StdEncoding.DecodeString(string(body))
|
|
||||||
if err != nil {
|
|
||||||
logger.Warning("sub: Error decoding Base64 content:", err)
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
return string(decodedText)
|
|
||||||
} else {
|
|
||||||
return string(body)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Function to check if a string is Base64 encoded
|
|
||||||
func (s *SubService) isBase64Encoded(str string) bool {
|
|
||||||
_, err := base64.StdEncoding.DecodeString(str)
|
|
||||||
return err == nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *SubService) formatTraffic(trafficBytes int64) string {
|
|
||||||
if trafficBytes < 1024 {
|
|
||||||
return fmt.Sprintf("%.2fB", float64(trafficBytes)/float64(1))
|
|
||||||
} else if trafficBytes < (1024 * 1024) {
|
|
||||||
return fmt.Sprintf("%.2fKB", float64(trafficBytes)/float64(1024))
|
|
||||||
} else if trafficBytes < (1024 * 1024 * 1024) {
|
|
||||||
return fmt.Sprintf("%.2fMB", float64(trafficBytes)/float64(1024*1024))
|
|
||||||
} else if trafficBytes < (1024 * 1024 * 1024 * 1024) {
|
|
||||||
return fmt.Sprintf("%.2fGB", float64(trafficBytes)/float64(1024*1024*1024))
|
|
||||||
} else if trafficBytes < (1024 * 1024 * 1024 * 1024 * 1024) {
|
|
||||||
return fmt.Sprintf("%.2fTB", float64(trafficBytes)/float64(1024*1024*1024*1024))
|
|
||||||
} else {
|
|
||||||
return fmt.Sprintf("%.2fEB", float64(trafficBytes)/float64(1024*1024*1024*1024*1024))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
package common
|
|
||||||
|
|
||||||
import "math/rand"
|
|
||||||
|
|
||||||
var allSeq [62]rune
|
|
||||||
|
|
||||||
func Random(n int) string {
|
|
||||||
runes := make([]rune, n)
|
|
||||||
for i := 0; i < n; i++ {
|
|
||||||
runes[i] = allSeq[rand.Intn(len(allSeq))]
|
|
||||||
}
|
|
||||||
return string(runes)
|
|
||||||
}
|
|
||||||
@@ -1,13 +1,14 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
cd frontend
|
cd frontend
|
||||||
|
npm i
|
||||||
npm run build
|
npm run build
|
||||||
|
|
||||||
cd ..
|
cd ..
|
||||||
cd backend
|
|
||||||
echo "Backend"
|
echo "Backend"
|
||||||
|
|
||||||
|
mkdir -p web/html
|
||||||
rm -fr web/html/*
|
rm -fr web/html/*
|
||||||
cp -R ../frontend/dist/ web/html/
|
cp -R frontend/dist/* web/html/
|
||||||
|
|
||||||
go build -o ../sui main.go
|
go build -ldflags "-w -s" -tags "with_quic,with_grpc,with_ech,with_utls,with_reality_server,with_acme,with_gvisor" -o sui main.go
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"s-ui/cmd/migration"
|
||||||
"s-ui/config"
|
"s-ui/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -40,6 +41,8 @@ func ParseCmd() {
|
|||||||
fmt.Println()
|
fmt.Println()
|
||||||
fmt.Println("Commands:")
|
fmt.Println("Commands:")
|
||||||
fmt.Println(" admin set/reset/show first admin credentials")
|
fmt.Println(" admin set/reset/show first admin credentials")
|
||||||
|
fmt.Println(" uri Show panel URI")
|
||||||
|
fmt.Println(" migrate migrate form older version")
|
||||||
fmt.Println(" setting set/reset/show settings")
|
fmt.Println(" setting set/reset/show settings")
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
adminCmd.Usage()
|
adminCmd.Usage()
|
||||||
@@ -70,6 +73,12 @@ func ParseCmd() {
|
|||||||
showAdmin()
|
showAdmin()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case "uri":
|
||||||
|
getPanelURI()
|
||||||
|
|
||||||
|
case "migrate":
|
||||||
|
migration.MigrateDb()
|
||||||
|
|
||||||
case "setting":
|
case "setting":
|
||||||
err := settingCmd.Parse(os.Args[2:])
|
err := settingCmd.Parse(os.Args[2:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
package migration
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"s-ui/database/model"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
func migrateClientSchema(db *gorm.DB) error {
|
||||||
|
rows, err := db.Raw("PRAGMA table_info(clients)").Rows()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
|
||||||
|
for rows.Next() {
|
||||||
|
var (
|
||||||
|
cid int
|
||||||
|
cname string
|
||||||
|
ctype string
|
||||||
|
notnull int
|
||||||
|
dfltValue interface{}
|
||||||
|
pk int
|
||||||
|
)
|
||||||
|
|
||||||
|
rows.Scan(&cid, &cname, &ctype, ¬null, &dfltValue, &pk)
|
||||||
|
if cname == "config" || cname == "inbounds" || cname == "links" {
|
||||||
|
if ctype == "text" {
|
||||||
|
fmt.Printf("Column %s has type TEXT\n", cname)
|
||||||
|
oldData := make([]struct {
|
||||||
|
Id uint
|
||||||
|
Data string
|
||||||
|
}, 0)
|
||||||
|
db.Model(model.Client{}).Select("id", cname+" as data").Scan(&oldData)
|
||||||
|
for _, data := range oldData {
|
||||||
|
var newData []byte
|
||||||
|
switch cname {
|
||||||
|
case "inbounds":
|
||||||
|
inbounds := strings.Split(data.Data, ",")
|
||||||
|
newData, _ = json.MarshalIndent(inbounds, "", " ")
|
||||||
|
case "config":
|
||||||
|
jsonData := map[string]interface{}{}
|
||||||
|
json.Unmarshal([]byte(data.Data), &jsonData)
|
||||||
|
newData, _ = json.MarshalIndent(jsonData, "", " ")
|
||||||
|
case "links":
|
||||||
|
jsonData := make([]interface{}, 0)
|
||||||
|
json.Unmarshal([]byte(data.Data), &jsonData)
|
||||||
|
newData, _ = json.MarshalIndent(jsonData, "", " ")
|
||||||
|
}
|
||||||
|
err = db.Model(model.Client{}).Where("id = ?", data.Id).UpdateColumn(cname, newData).Error
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func deleteOldWebSecret(db *gorm.DB) error {
|
||||||
|
return db.Exec("DELETE FROM settings WHERE key = ?", "webSecret").Error
|
||||||
|
}
|
||||||
|
|
||||||
|
func changesObj(db *gorm.DB) error {
|
||||||
|
return db.Exec("UPDATE changes SET obj = CAST('\"' || CAST(obj AS TEXT) || '\"' AS BLOB) WHERE actor = ? and obj not like ?", "DepleteJob", "\"%\"").Error
|
||||||
|
}
|
||||||
|
|
||||||
|
func to1_1(db *gorm.DB) error {
|
||||||
|
err := migrateClientSchema(db)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = deleteOldWebSecret(db)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = changesObj(db)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,316 @@
|
|||||||
|
package migration
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"s-ui/database/model"
|
||||||
|
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
type InboundData struct {
|
||||||
|
Id uint
|
||||||
|
Tag string
|
||||||
|
Addrs json.RawMessage
|
||||||
|
OutJson json.RawMessage
|
||||||
|
}
|
||||||
|
|
||||||
|
func moveJsonToDb(db *gorm.DB) error {
|
||||||
|
binFolderPath := os.Getenv("SUI_BIN_FOLDER")
|
||||||
|
if binFolderPath == "" {
|
||||||
|
binFolderPath = "bin"
|
||||||
|
}
|
||||||
|
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
configPath := dir + "/" + binFolderPath + "/config.json"
|
||||||
|
if _, err := os.Stat(configPath); errors.Is(err, os.ErrNotExist) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
data, err := os.ReadFile(configPath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
var oldConfig map[string]interface{}
|
||||||
|
err = json.Unmarshal(data, &oldConfig)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
oldInbounds := oldConfig["inbounds"].([]interface{})
|
||||||
|
db.Migrator().DropTable(&model.Inbound{})
|
||||||
|
db.AutoMigrate(&model.Inbound{})
|
||||||
|
for _, inbound := range oldInbounds {
|
||||||
|
inbObj, _ := inbound.(map[string]interface{})
|
||||||
|
tag, _ := inbObj["tag"].(string)
|
||||||
|
if tlsObj, ok := inbObj["tls"]; ok {
|
||||||
|
var tls_id uint
|
||||||
|
err = db.Raw("SELECT id FROM tls WHERE inbounds like ?", `%"`+tag+`"%`).Find(&tls_id).Error
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bind or Create tls_id
|
||||||
|
if tls_id > 0 {
|
||||||
|
inbObj["tls_id"] = tls_id
|
||||||
|
} else {
|
||||||
|
tls_server, _ := json.MarshalIndent(tlsObj, "", " ")
|
||||||
|
if len(tls_server) > 5 {
|
||||||
|
newTls := &model.Tls{
|
||||||
|
Name: tag,
|
||||||
|
Server: tls_server,
|
||||||
|
Client: json.RawMessage("{}"),
|
||||||
|
}
|
||||||
|
err = db.Create(newTls).Error
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
inbObj["tls_id"] = newTls.Id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var inbData InboundData
|
||||||
|
db.Raw("select id,addrs,out_json from inbound_data where tag = ?", tag).Find(&inbData)
|
||||||
|
if inbData.Id > 0 {
|
||||||
|
inbObj["out_json"] = inbData.OutJson
|
||||||
|
var addrs []map[string]interface{}
|
||||||
|
json.Unmarshal(inbData.Addrs, &addrs)
|
||||||
|
for index, addr := range addrs {
|
||||||
|
if tlsEnable, ok := addr["tls"].(bool); ok {
|
||||||
|
newTls := map[string]interface{}{
|
||||||
|
"enabled": tlsEnable,
|
||||||
|
}
|
||||||
|
if insecure, ok := addr["insecure"].(bool); ok {
|
||||||
|
newTls["insecure"] = insecure
|
||||||
|
delete(addrs[index], "insecure")
|
||||||
|
}
|
||||||
|
if sni, ok := addr["server_name"].(string); ok {
|
||||||
|
newTls["server_name"] = sni
|
||||||
|
delete(addrs[index], "server_name")
|
||||||
|
}
|
||||||
|
addrs[index]["tls"] = newTls
|
||||||
|
}
|
||||||
|
}
|
||||||
|
inbObj["addrs"] = addrs
|
||||||
|
} else {
|
||||||
|
inbObj["out_json"] = json.RawMessage("{}")
|
||||||
|
inbObj["addrs"] = json.RawMessage("[]")
|
||||||
|
}
|
||||||
|
// Delete deprecated fields
|
||||||
|
delete(inbObj, "sniff")
|
||||||
|
delete(inbObj, "sniff_override_destination")
|
||||||
|
delete(inbObj, "sniff_timeout")
|
||||||
|
delete(inbObj, "domain_strategy")
|
||||||
|
inbJson, _ := json.Marshal(inbObj)
|
||||||
|
|
||||||
|
var newInbound model.Inbound
|
||||||
|
err = newInbound.UnmarshalJSON(inbJson)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = db.Create(&newInbound).Error
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
delete(oldConfig, "inbounds")
|
||||||
|
|
||||||
|
blockOutboundTags := []string{}
|
||||||
|
dnsOutboundTags := []string{}
|
||||||
|
|
||||||
|
oldOutbounds := oldConfig["outbounds"].([]interface{})
|
||||||
|
db.Migrator().DropTable(&model.Outbound{}, &model.Endpoint{})
|
||||||
|
db.AutoMigrate(&model.Outbound{}, &model.Endpoint{})
|
||||||
|
for _, outbound := range oldOutbounds {
|
||||||
|
outType, _ := outbound.(map[string]interface{})["type"].(string)
|
||||||
|
outboundRaw, _ := json.MarshalIndent(outbound, "", " ")
|
||||||
|
if outType == "wireguard" { // Check if it is Entrypoint
|
||||||
|
var newEntrypoint model.Endpoint
|
||||||
|
err = newEntrypoint.UnmarshalJSON(outboundRaw)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = db.Create(&newEntrypoint).Error
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else { // It is Outbound
|
||||||
|
var newOutbound model.Outbound
|
||||||
|
err = newOutbound.UnmarshalJSON(outboundRaw)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
// Delete deprecated fields
|
||||||
|
if newOutbound.Type == "direct" {
|
||||||
|
var options map[string]interface{}
|
||||||
|
json.Unmarshal(newOutbound.Options, &options)
|
||||||
|
delete(options, "override_address")
|
||||||
|
delete(options, "override_port")
|
||||||
|
newOutbound.Options, _ = json.Marshal(options)
|
||||||
|
}
|
||||||
|
|
||||||
|
switch newOutbound.Type {
|
||||||
|
case "dns":
|
||||||
|
dnsOutboundTags = append(dnsOutboundTags, newOutbound.Tag)
|
||||||
|
case "block":
|
||||||
|
blockOutboundTags = append(blockOutboundTags, newOutbound.Tag)
|
||||||
|
default:
|
||||||
|
err = db.Create(&newOutbound).Error
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
delete(oldConfig, "outbounds")
|
||||||
|
|
||||||
|
// Check routing rules
|
||||||
|
if routingRules, ok := oldConfig["route"].(map[string]interface{}); ok {
|
||||||
|
if rules, hasRules := routingRules["rules"].([]interface{}); hasRules {
|
||||||
|
hasDns := false
|
||||||
|
for index, rule := range rules {
|
||||||
|
ruleObj, _ := rule.(map[string]interface{})
|
||||||
|
isBlock := false
|
||||||
|
isDns := false
|
||||||
|
outboundTag, _ := ruleObj["outbound"].(string)
|
||||||
|
for _, tag := range blockOutboundTags {
|
||||||
|
if tag == outboundTag {
|
||||||
|
isBlock = true
|
||||||
|
delete(ruleObj, "outbound")
|
||||||
|
ruleObj["action"] = "reject"
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, tag := range dnsOutboundTags {
|
||||||
|
if tag == outboundTag {
|
||||||
|
isDns = true
|
||||||
|
hasDns = true
|
||||||
|
delete(ruleObj, "outbound")
|
||||||
|
ruleObj["action"] = "hijack-dns"
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !isBlock && !isDns {
|
||||||
|
ruleObj["action"] = "route"
|
||||||
|
}
|
||||||
|
rules[index] = ruleObj
|
||||||
|
}
|
||||||
|
if hasDns {
|
||||||
|
rules = append(rules, map[string]interface{}{"action": "sniff"})
|
||||||
|
}
|
||||||
|
routingRules["rules"] = rules
|
||||||
|
}
|
||||||
|
oldConfig["route"] = routingRules
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove v2rayapi and clashapi from experimental config
|
||||||
|
experimental := oldConfig["experimental"].(map[string]interface{})
|
||||||
|
delete(experimental, "v2ray_api")
|
||||||
|
delete(experimental, "clash_api")
|
||||||
|
oldConfig["experimental"] = experimental
|
||||||
|
|
||||||
|
// Save the other configs
|
||||||
|
var otherConfigs json.RawMessage
|
||||||
|
otherConfigs, err = json.MarshalIndent(oldConfig, "", " ")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return db.Save(&model.Setting{
|
||||||
|
Key: "config",
|
||||||
|
Value: string(otherConfigs),
|
||||||
|
}).Error
|
||||||
|
}
|
||||||
|
|
||||||
|
func migrateTls(db *gorm.DB) error {
|
||||||
|
if !db.Migrator().HasColumn(&model.Tls{}, "inbounds") {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
err := db.Migrator().DropColumn(&model.Tls{}, "inbounds")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
var tlsConfig []model.Tls
|
||||||
|
err = db.Model(model.Tls{}).Scan(&tlsConfig).Error
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for index, tls := range tlsConfig {
|
||||||
|
var tlsClient map[string]interface{}
|
||||||
|
err = json.Unmarshal(tls.Client, &tlsClient)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
for key := range tlsClient {
|
||||||
|
switch key {
|
||||||
|
case "insecure", "disable_sni", "utls", "ech", "reality":
|
||||||
|
continue
|
||||||
|
default:
|
||||||
|
delete(tlsClient, key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tlsConfig[index].Client, _ = json.MarshalIndent(tlsClient, "", " ")
|
||||||
|
}
|
||||||
|
|
||||||
|
return db.Save(&tlsConfig).Error
|
||||||
|
}
|
||||||
|
|
||||||
|
func dropInboundData(db *gorm.DB) error {
|
||||||
|
if !db.Migrator().HasTable(&InboundData{}) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return db.Migrator().DropTable(&InboundData{})
|
||||||
|
}
|
||||||
|
|
||||||
|
func migrateClients(db *gorm.DB) error {
|
||||||
|
var oldClients []model.Client
|
||||||
|
err := db.Model(model.Client{}).Scan(&oldClients).Error
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for index, oldClient := range oldClients {
|
||||||
|
var old_inbounds []string
|
||||||
|
err = json.Unmarshal(oldClient.Inbounds, &old_inbounds)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
var inbound_ids []uint
|
||||||
|
err = db.Raw("SELECT id FROM inbounds WHERE tag in ?", old_inbounds).Find(&inbound_ids).Error
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
oldClients[index].Inbounds, _ = json.Marshal(inbound_ids)
|
||||||
|
}
|
||||||
|
return db.Save(oldClients).Error
|
||||||
|
}
|
||||||
|
|
||||||
|
func migrateChanges(db *gorm.DB) error {
|
||||||
|
return db.Migrator().DropColumn(&model.Changes{}, "index")
|
||||||
|
}
|
||||||
|
|
||||||
|
func to1_2(db *gorm.DB) error {
|
||||||
|
err := moveJsonToDb(db)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = migrateTls(db)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = dropInboundData(db)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = migrateClients(db)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return migrateChanges(db)
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
package migration
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"s-ui/config"
|
||||||
|
|
||||||
|
"gorm.io/driver/sqlite"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
func MigrateDb() {
|
||||||
|
// void running on first install
|
||||||
|
path := config.GetDBPath()
|
||||||
|
_, err := os.Stat(path)
|
||||||
|
if err != nil {
|
||||||
|
println("Database not found")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
db, err := gorm.Open(sqlite.Open(path))
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
tx := db.Begin()
|
||||||
|
defer func() {
|
||||||
|
if err == nil {
|
||||||
|
tx.Commit()
|
||||||
|
} else {
|
||||||
|
tx.Rollback()
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
currentVersion := config.GetVersion()
|
||||||
|
dbVersion := ""
|
||||||
|
tx.Raw("SELECT value FROM settings WHERE key = ?", "version").Find(&dbVersion)
|
||||||
|
fmt.Println("Current version:", currentVersion, "\nDatabase version:", dbVersion)
|
||||||
|
|
||||||
|
if currentVersion == dbVersion {
|
||||||
|
fmt.Println("Database is up to date, no need to migrate")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("Start migrating database...")
|
||||||
|
|
||||||
|
// Before 1.2
|
||||||
|
if dbVersion == "" {
|
||||||
|
err = to1_1(tx)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("Migration to 1.1 failed: ", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = to1_2(tx)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("Migration to 1.2 failed: ", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set version
|
||||||
|
err = tx.Raw("UPDATE settings SET value = ? WHERE key = ?", currentVersion, "version").Error
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("Update version failed: ", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fmt.Println("Migration done!")
|
||||||
|
}
|
||||||
@@ -2,9 +2,14 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
"s-ui/config"
|
"s-ui/config"
|
||||||
"s-ui/database"
|
"s-ui/database"
|
||||||
"s-ui/service"
|
"s-ui/service"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/shirou/gopsutil/v4/net"
|
||||||
)
|
)
|
||||||
|
|
||||||
func resetSetting() {
|
func resetSetting() {
|
||||||
@@ -103,3 +108,64 @@ func showSetting() {
|
|||||||
fmt.Println("\tSub URI:\t", (*allSetting)["subURI"])
|
fmt.Println("\tSub URI:\t", (*allSetting)["subURI"])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getPanelURI() {
|
||||||
|
err := database.InitDB(config.GetDBPath())
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
settingService := service.SettingService{}
|
||||||
|
Port, _ := settingService.GetPort()
|
||||||
|
BasePath, _ := settingService.GetWebPath()
|
||||||
|
Listen, _ := settingService.GetListen()
|
||||||
|
Domain, _ := settingService.GetWebDomain()
|
||||||
|
KeyFile, _ := settingService.GetKeyFile()
|
||||||
|
CertFile, _ := settingService.GetCertFile()
|
||||||
|
TLS := false
|
||||||
|
if KeyFile != "" && CertFile != "" {
|
||||||
|
TLS = true
|
||||||
|
}
|
||||||
|
Proto := ""
|
||||||
|
if TLS {
|
||||||
|
Proto = "https://"
|
||||||
|
} else {
|
||||||
|
Proto = "http://"
|
||||||
|
}
|
||||||
|
PortText := fmt.Sprintf(":%d", Port)
|
||||||
|
if (Port == 443 && TLS) || (Port == 80 && !TLS) {
|
||||||
|
PortText = ""
|
||||||
|
}
|
||||||
|
if len(Domain) > 0 {
|
||||||
|
fmt.Println(Proto + Domain + PortText + BasePath)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if len(Listen) > 0 {
|
||||||
|
fmt.Println(Proto + Listen + PortText + BasePath)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fmt.Println("Local address:")
|
||||||
|
// get ip address
|
||||||
|
netInterfaces, _ := net.Interfaces()
|
||||||
|
for i := 0; i < len(netInterfaces); i++ {
|
||||||
|
if len(netInterfaces[i].Flags) > 2 && netInterfaces[i].Flags[0] == "up" && netInterfaces[i].Flags[1] != "loopback" {
|
||||||
|
addrs := netInterfaces[i].Addrs
|
||||||
|
for _, address := range addrs {
|
||||||
|
IP := strings.Split(address.Addr, "/")[0]
|
||||||
|
if strings.Contains(address.Addr, ".") {
|
||||||
|
fmt.Println(Proto + IP + PortText + BasePath)
|
||||||
|
} else if address.Addr[0:6] != "fe80::" {
|
||||||
|
fmt.Println(Proto + "[" + IP + "]" + PortText + BasePath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
resp, err := http.Get("https://api.ipify.org?format=text")
|
||||||
|
if err == nil {
|
||||||
|
defer resp.Body.Close()
|
||||||
|
ip, err := io.ReadAll(resp.Body)
|
||||||
|
if err == nil {
|
||||||
|
fmt.Printf("\nGlobal address:\n%s%s%s%s\n", Proto, ip, PortText, BasePath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
_ "embed"
|
_ "embed"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -13,9 +14,6 @@ var version string
|
|||||||
//go:embed name
|
//go:embed name
|
||||||
var name string
|
var name string
|
||||||
|
|
||||||
//go:embed config.json
|
|
||||||
var defaultConfig string
|
|
||||||
|
|
||||||
type LogLevel string
|
type LogLevel string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -48,18 +46,14 @@ func IsDebug() bool {
|
|||||||
return os.Getenv("SUI_DEBUG") == "true"
|
return os.Getenv("SUI_DEBUG") == "true"
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetBinFolderPath() string {
|
|
||||||
binFolderPath := os.Getenv("SUI_BIN_FOLDER")
|
|
||||||
if binFolderPath == "" {
|
|
||||||
binFolderPath = "bin"
|
|
||||||
}
|
|
||||||
return binFolderPath
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetDBFolderPath() string {
|
func GetDBFolderPath() string {
|
||||||
dbFolderPath := os.Getenv("SUI_DB_FOLDER")
|
dbFolderPath := os.Getenv("SUI_DB_FOLDER")
|
||||||
if dbFolderPath == "" {
|
if dbFolderPath == "" {
|
||||||
dbFolderPath = "/usr/local/s-ui/db"
|
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
|
||||||
|
if err != nil {
|
||||||
|
dbFolderPath = "/usr/local/s-ui/db"
|
||||||
|
}
|
||||||
|
dbFolderPath = dir + "/db"
|
||||||
}
|
}
|
||||||
return dbFolderPath
|
return dbFolderPath
|
||||||
}
|
}
|
||||||
@@ -67,11 +61,3 @@ func GetDBFolderPath() string {
|
|||||||
func GetDBPath() string {
|
func GetDBPath() string {
|
||||||
return fmt.Sprintf("%s/%s.db", GetDBFolderPath(), GetName())
|
return fmt.Sprintf("%s/%s.db", GetDBFolderPath(), GetName())
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetDefaultConfig() string {
|
|
||||||
return defaultConfig
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetEnvApi() string {
|
|
||||||
return os.Getenv("SINGBOX_API")
|
|
||||||
}
|
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
1.2.0-rc0
|
||||||
+408
@@ -0,0 +1,408 @@
|
|||||||
|
package core
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
"s-ui/util/common"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/sagernet/sing-box/adapter"
|
||||||
|
"github.com/sagernet/sing-box/adapter/endpoint"
|
||||||
|
"github.com/sagernet/sing-box/adapter/inbound"
|
||||||
|
"github.com/sagernet/sing-box/adapter/outbound"
|
||||||
|
"github.com/sagernet/sing-box/common/dialer"
|
||||||
|
"github.com/sagernet/sing-box/common/taskmonitor"
|
||||||
|
C "github.com/sagernet/sing-box/constant"
|
||||||
|
"github.com/sagernet/sing-box/experimental/cachefile"
|
||||||
|
"github.com/sagernet/sing-box/experimental/libbox/platform"
|
||||||
|
"github.com/sagernet/sing-box/log"
|
||||||
|
"github.com/sagernet/sing-box/option"
|
||||||
|
"github.com/sagernet/sing-box/protocol/direct"
|
||||||
|
"github.com/sagernet/sing-box/route"
|
||||||
|
sbCommon "github.com/sagernet/sing/common"
|
||||||
|
F "github.com/sagernet/sing/common/format"
|
||||||
|
"github.com/sagernet/sing/common/ntp"
|
||||||
|
"github.com/sagernet/sing/service"
|
||||||
|
"github.com/sagernet/sing/service/pause"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ adapter.Service = (*Box)(nil)
|
||||||
|
|
||||||
|
type Box struct {
|
||||||
|
createdAt time.Time
|
||||||
|
logFactory log.Factory
|
||||||
|
logger log.ContextLogger
|
||||||
|
network *route.NetworkManager
|
||||||
|
endpoint *endpoint.Manager
|
||||||
|
inbound *inbound.Manager
|
||||||
|
outbound *outbound.Manager
|
||||||
|
connection *route.ConnectionManager
|
||||||
|
router *route.Router
|
||||||
|
services []adapter.LifecycleService
|
||||||
|
connTracker *ConnTracker
|
||||||
|
done chan struct{}
|
||||||
|
}
|
||||||
|
|
||||||
|
type Options struct {
|
||||||
|
option.Options
|
||||||
|
Context context.Context
|
||||||
|
}
|
||||||
|
|
||||||
|
func Context(
|
||||||
|
ctx context.Context,
|
||||||
|
inboundRegistry adapter.InboundRegistry,
|
||||||
|
outboundRegistry adapter.OutboundRegistry,
|
||||||
|
endpointRegistry adapter.EndpointRegistry,
|
||||||
|
) context.Context {
|
||||||
|
if service.FromContext[option.InboundOptionsRegistry](ctx) == nil ||
|
||||||
|
service.FromContext[adapter.InboundRegistry](ctx) == nil {
|
||||||
|
ctx = service.ContextWith[option.InboundOptionsRegistry](ctx, inboundRegistry)
|
||||||
|
ctx = service.ContextWith[adapter.InboundRegistry](ctx, inboundRegistry)
|
||||||
|
}
|
||||||
|
if service.FromContext[option.OutboundOptionsRegistry](ctx) == nil ||
|
||||||
|
service.FromContext[adapter.OutboundRegistry](ctx) == nil {
|
||||||
|
ctx = service.ContextWith[option.OutboundOptionsRegistry](ctx, outboundRegistry)
|
||||||
|
ctx = service.ContextWith[adapter.OutboundRegistry](ctx, outboundRegistry)
|
||||||
|
}
|
||||||
|
if service.FromContext[option.EndpointOptionsRegistry](ctx) == nil ||
|
||||||
|
service.FromContext[adapter.EndpointRegistry](ctx) == nil {
|
||||||
|
ctx = service.ContextWith[option.EndpointOptionsRegistry](ctx, endpointRegistry)
|
||||||
|
ctx = service.ContextWith[adapter.EndpointRegistry](ctx, endpointRegistry)
|
||||||
|
}
|
||||||
|
return ctx
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewBox(options Options) (*Box, error) {
|
||||||
|
var err error
|
||||||
|
createdAt := time.Now()
|
||||||
|
ctx := options.Context
|
||||||
|
if ctx == nil {
|
||||||
|
ctx = context.Background()
|
||||||
|
}
|
||||||
|
ctx = service.ContextWithDefaultRegistry(ctx)
|
||||||
|
|
||||||
|
endpointRegistry := service.FromContext[adapter.EndpointRegistry](ctx)
|
||||||
|
inboundRegistry := service.FromContext[adapter.InboundRegistry](ctx)
|
||||||
|
outboundRegistry := service.FromContext[adapter.OutboundRegistry](ctx)
|
||||||
|
|
||||||
|
if endpointRegistry == nil {
|
||||||
|
return nil, common.NewError("missing endpoint registry in context")
|
||||||
|
}
|
||||||
|
if inboundRegistry == nil {
|
||||||
|
return nil, common.NewError("missing inbound registry in context")
|
||||||
|
}
|
||||||
|
if outboundRegistry == nil {
|
||||||
|
return nil, common.NewError("missing outbound registry in context")
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx = pause.WithDefaultManager(ctx)
|
||||||
|
experimentalOptions := sbCommon.PtrValueOrDefault(options.Experimental)
|
||||||
|
var needCacheFile bool
|
||||||
|
if experimentalOptions.CacheFile != nil && experimentalOptions.CacheFile.Enabled {
|
||||||
|
needCacheFile = true
|
||||||
|
}
|
||||||
|
platformInterface := service.FromContext[platform.Interface](ctx)
|
||||||
|
var defaultLogWriter io.Writer
|
||||||
|
if platformInterface != nil {
|
||||||
|
defaultLogWriter = io.Discard
|
||||||
|
}
|
||||||
|
var logFactory log.Factory
|
||||||
|
logFactory, err = NewFactory(log.Options{
|
||||||
|
Context: ctx,
|
||||||
|
Options: sbCommon.PtrValueOrDefault(options.Log),
|
||||||
|
DefaultWriter: defaultLogWriter,
|
||||||
|
BaseTime: createdAt,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, common.NewError("create log factory", err)
|
||||||
|
}
|
||||||
|
factory = logFactory
|
||||||
|
|
||||||
|
routeOptions := sbCommon.PtrValueOrDefault(options.Route)
|
||||||
|
endpointManager := endpoint.NewManager(logFactory.NewLogger("endpoint"), endpointRegistry)
|
||||||
|
inboundManager := inbound.NewManager(logFactory.NewLogger("inbound"), inboundRegistry, endpointManager)
|
||||||
|
outboundManager := outbound.NewManager(logFactory.NewLogger("outbound"), outboundRegistry, endpointManager, routeOptions.Final)
|
||||||
|
service.MustRegister[adapter.EndpointManager](ctx, endpointManager)
|
||||||
|
service.MustRegister[adapter.InboundManager](ctx, inboundManager)
|
||||||
|
service.MustRegister[adapter.OutboundManager](ctx, outboundManager)
|
||||||
|
|
||||||
|
networkManager, err := route.NewNetworkManager(ctx, logFactory.NewLogger("network"), routeOptions)
|
||||||
|
if err != nil {
|
||||||
|
return nil, common.NewError("initialize network manager", err)
|
||||||
|
}
|
||||||
|
service.MustRegister[adapter.NetworkManager](ctx, networkManager)
|
||||||
|
connectionManager := route.NewConnectionManager(logFactory.NewLogger("connection"))
|
||||||
|
service.MustRegister[adapter.ConnectionManager](ctx, connectionManager)
|
||||||
|
router, err := route.NewRouter(ctx, logFactory, routeOptions, sbCommon.PtrValueOrDefault(options.DNS))
|
||||||
|
if err != nil {
|
||||||
|
return nil, common.NewError("initialize router", err)
|
||||||
|
}
|
||||||
|
for i, endpointOptions := range options.Endpoints {
|
||||||
|
var tag string
|
||||||
|
if endpointOptions.Tag != "" {
|
||||||
|
tag = endpointOptions.Tag
|
||||||
|
} else {
|
||||||
|
tag = F.ToString(i)
|
||||||
|
}
|
||||||
|
err = endpointManager.Create(ctx,
|
||||||
|
router,
|
||||||
|
logFactory.NewLogger(F.ToString("endpoint/", endpointOptions.Type, "[", tag, "]")),
|
||||||
|
tag,
|
||||||
|
endpointOptions.Type,
|
||||||
|
endpointOptions.Options,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return nil, common.NewError("initialize endpoint["+F.ToString(i)+"] "+tag, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for i, inboundOptions := range options.Inbounds {
|
||||||
|
var tag string
|
||||||
|
if inboundOptions.Tag != "" {
|
||||||
|
tag = inboundOptions.Tag
|
||||||
|
} else {
|
||||||
|
tag = F.ToString(i)
|
||||||
|
}
|
||||||
|
err = inboundManager.Create(ctx,
|
||||||
|
router,
|
||||||
|
logFactory.NewLogger(F.ToString("inbound/", inboundOptions.Type, "[", tag, "]")),
|
||||||
|
tag,
|
||||||
|
inboundOptions.Type,
|
||||||
|
inboundOptions.Options,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return nil, common.NewError("initialize inbound[", i, "] ", tag, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for i, outboundOptions := range options.Outbounds {
|
||||||
|
var tag string
|
||||||
|
if outboundOptions.Tag != "" {
|
||||||
|
tag = outboundOptions.Tag
|
||||||
|
} else {
|
||||||
|
tag = F.ToString(i)
|
||||||
|
}
|
||||||
|
outboundCtx := ctx
|
||||||
|
if tag != "" {
|
||||||
|
// TODO: remove this
|
||||||
|
outboundCtx = adapter.WithContext(outboundCtx, &adapter.InboundContext{
|
||||||
|
Outbound: tag,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
err = outboundManager.Create(
|
||||||
|
outboundCtx,
|
||||||
|
router,
|
||||||
|
logFactory.NewLogger(F.ToString("outbound/", outboundOptions.Type, "[", tag, "]")),
|
||||||
|
tag,
|
||||||
|
outboundOptions.Type,
|
||||||
|
outboundOptions.Options,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return nil, common.NewError("initialize outbound["+F.ToString(i)+"] "+tag, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
outboundManager.Initialize(sbCommon.Must1(
|
||||||
|
direct.NewOutbound(
|
||||||
|
ctx,
|
||||||
|
router,
|
||||||
|
logFactory.NewLogger("outbound/direct"),
|
||||||
|
"direct",
|
||||||
|
option.DirectOutboundOptions{},
|
||||||
|
),
|
||||||
|
))
|
||||||
|
if platformInterface != nil {
|
||||||
|
err = platformInterface.Initialize(networkManager)
|
||||||
|
if err != nil {
|
||||||
|
return nil, common.NewError("initialize platform interface", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if connTracker == nil {
|
||||||
|
connTracker = NewConnTracker()
|
||||||
|
}
|
||||||
|
router.SetTracker(connTracker)
|
||||||
|
|
||||||
|
var services []adapter.LifecycleService
|
||||||
|
|
||||||
|
if needCacheFile {
|
||||||
|
cacheFile := cachefile.New(ctx, sbCommon.PtrValueOrDefault(experimentalOptions.CacheFile))
|
||||||
|
service.MustRegister[adapter.CacheFile](ctx, cacheFile)
|
||||||
|
services = append(services, cacheFile)
|
||||||
|
}
|
||||||
|
ntpOptions := sbCommon.PtrValueOrDefault(options.NTP)
|
||||||
|
if ntpOptions.Enabled {
|
||||||
|
ntpDialer, err := dialer.New(ctx, ntpOptions.DialerOptions)
|
||||||
|
if err != nil {
|
||||||
|
return nil, common.NewError(err, "create NTP service")
|
||||||
|
}
|
||||||
|
timeService := ntp.NewService(ntp.Options{
|
||||||
|
Context: ctx,
|
||||||
|
Dialer: ntpDialer,
|
||||||
|
Logger: logFactory.NewLogger("ntp"),
|
||||||
|
Server: ntpOptions.ServerOptions.Build(),
|
||||||
|
Interval: time.Duration(ntpOptions.Interval),
|
||||||
|
WriteToSystem: ntpOptions.WriteToSystem,
|
||||||
|
})
|
||||||
|
service.MustRegister[ntp.TimeService](ctx, timeService)
|
||||||
|
services = append(services, adapter.NewLifecycleService(timeService, "ntp service"))
|
||||||
|
}
|
||||||
|
return &Box{
|
||||||
|
network: networkManager,
|
||||||
|
endpoint: endpointManager,
|
||||||
|
inbound: inboundManager,
|
||||||
|
outbound: outboundManager,
|
||||||
|
connection: connectionManager,
|
||||||
|
router: router,
|
||||||
|
createdAt: createdAt,
|
||||||
|
logFactory: logFactory,
|
||||||
|
logger: logFactory.Logger(),
|
||||||
|
services: services,
|
||||||
|
connTracker: connTracker,
|
||||||
|
done: make(chan struct{}),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Box) PreStart() error {
|
||||||
|
err := s.preStart()
|
||||||
|
if err != nil {
|
||||||
|
// TODO: remove catch error
|
||||||
|
defer func() {
|
||||||
|
v := recover()
|
||||||
|
if v != nil {
|
||||||
|
s.logger.Error(err.Error())
|
||||||
|
s.logger.Error("panic on early close: " + fmt.Sprint(v))
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
s.Close()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
s.logger.Info("sing-box pre-started (", F.Seconds(time.Since(s.createdAt).Seconds()), "s)")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Box) Start() error {
|
||||||
|
err := s.start()
|
||||||
|
if err != nil {
|
||||||
|
// TODO: remove catch error
|
||||||
|
defer func() {
|
||||||
|
v := recover()
|
||||||
|
if v != nil {
|
||||||
|
s.logger.Debug(err.Error())
|
||||||
|
s.logger.Error("panic on early start: " + fmt.Sprint(v))
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
s.Close()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
s.logger.Info("sing-box started (", F.Seconds(time.Since(s.createdAt).Seconds()), "s)")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Box) preStart() error {
|
||||||
|
monitor := taskmonitor.New(s.logger, C.StartTimeout)
|
||||||
|
monitor.Start("start logger")
|
||||||
|
err := s.logFactory.Start()
|
||||||
|
monitor.Finish()
|
||||||
|
if err != nil {
|
||||||
|
return common.NewError(err, "start logger")
|
||||||
|
}
|
||||||
|
err = adapter.StartNamed(adapter.StartStateInitialize, s.services) // cache-file
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = adapter.Start(adapter.StartStateInitialize, s.network, s.connection, s.router, s.outbound, s.inbound, s.endpoint)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = adapter.Start(adapter.StartStateStart, s.outbound, s.network, s.connection, s.router)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Box) start() error {
|
||||||
|
err := s.preStart()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = adapter.StartNamed(adapter.StartStateStart, s.services)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = s.inbound.Start(adapter.StartStateStart)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = adapter.Start(adapter.StartStateStart, s.endpoint)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = adapter.Start(adapter.StartStatePostStart, s.outbound, s.network, s.connection, s.router, s.inbound, s.endpoint)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = adapter.StartNamed(adapter.StartStatePostStart, s.services)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = adapter.Start(adapter.StartStateStarted, s.network, s.connection, s.router, s.outbound, s.inbound, s.endpoint)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = adapter.StartNamed(adapter.StartStateStarted, s.services)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Box) Close() error {
|
||||||
|
select {
|
||||||
|
case <-s.done:
|
||||||
|
return os.ErrClosed
|
||||||
|
default:
|
||||||
|
close(s.done)
|
||||||
|
}
|
||||||
|
err := sbCommon.Close(
|
||||||
|
s.endpoint, s.inbound, s.outbound, s.router, s.connection, s.network,
|
||||||
|
)
|
||||||
|
for _, lifecycleService := range s.services {
|
||||||
|
err1 := lifecycleService.Close()
|
||||||
|
if err1 != nil {
|
||||||
|
s.logger.Debug(lifecycleService.Name(), " close error: ", err1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
err1 := s.logFactory.Close()
|
||||||
|
if err1 != nil {
|
||||||
|
s.logger.Debug("logger close error: ", err1)
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Box) Uptime() uint32 {
|
||||||
|
return uint32(time.Now().Sub(s.createdAt).Seconds())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Box) Network() adapter.NetworkManager {
|
||||||
|
return s.network
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Box) Router() adapter.Router {
|
||||||
|
return s.router
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Box) Inbound() adapter.InboundManager {
|
||||||
|
return s.inbound
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Box) Outbound() adapter.OutboundManager {
|
||||||
|
return s.outbound
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Box) Endpoint() adapter.EndpointManager {
|
||||||
|
return s.endpoint
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Box) ConnTracker() *ConnTracker {
|
||||||
|
return s.connTracker
|
||||||
|
}
|
||||||
@@ -0,0 +1,145 @@
|
|||||||
|
package core
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net"
|
||||||
|
"s-ui/database/model"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/sagernet/sing-box/adapter"
|
||||||
|
"github.com/sagernet/sing/common/atomic"
|
||||||
|
"github.com/sagernet/sing/common/bufio"
|
||||||
|
"github.com/sagernet/sing/common/network"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Counter struct {
|
||||||
|
read *atomic.Int64
|
||||||
|
write *atomic.Int64
|
||||||
|
}
|
||||||
|
|
||||||
|
type ConnTracker struct {
|
||||||
|
access sync.Mutex
|
||||||
|
createdAt time.Time
|
||||||
|
inbounds map[string]Counter
|
||||||
|
outbounds map[string]Counter
|
||||||
|
users map[string]Counter
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewConnTracker() *ConnTracker {
|
||||||
|
return &ConnTracker{
|
||||||
|
createdAt: time.Now(),
|
||||||
|
inbounds: make(map[string]Counter),
|
||||||
|
outbounds: make(map[string]Counter),
|
||||||
|
users: make(map[string]Counter),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *ConnTracker) getReadCounters(inbound string, outbound string, user string) ([]*atomic.Int64, []*atomic.Int64) {
|
||||||
|
var readCounter []*atomic.Int64
|
||||||
|
var writeCounter []*atomic.Int64
|
||||||
|
c.access.Lock()
|
||||||
|
if inbound != "" {
|
||||||
|
readCounter = append(readCounter, c.loadOrCreateCounter(&c.inbounds, inbound).read)
|
||||||
|
writeCounter = append(writeCounter, c.inbounds[inbound].write)
|
||||||
|
}
|
||||||
|
if outbound != "" {
|
||||||
|
readCounter = append(readCounter, c.loadOrCreateCounter(&c.outbounds, outbound).read)
|
||||||
|
writeCounter = append(writeCounter, c.outbounds[outbound].write)
|
||||||
|
}
|
||||||
|
if user != "" {
|
||||||
|
readCounter = append(readCounter, c.loadOrCreateCounter(&c.users, user).read)
|
||||||
|
writeCounter = append(writeCounter, c.users[user].write)
|
||||||
|
}
|
||||||
|
c.access.Unlock()
|
||||||
|
return readCounter, writeCounter
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *ConnTracker) loadOrCreateCounter(obj *map[string]Counter, name string) Counter {
|
||||||
|
counter, loaded := (*obj)[name]
|
||||||
|
if loaded {
|
||||||
|
return counter
|
||||||
|
}
|
||||||
|
counter = Counter{read: &atomic.Int64{}, write: &atomic.Int64{}}
|
||||||
|
(*obj)[name] = counter
|
||||||
|
return counter
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *ConnTracker) RoutedConnection(ctx context.Context, conn net.Conn, metadata adapter.InboundContext, matchedRule adapter.Rule, matchOutbound adapter.Outbound) net.Conn {
|
||||||
|
readCounter, writeCounter := c.getReadCounters(metadata.Inbound, matchOutbound.Tag(), metadata.User)
|
||||||
|
return bufio.NewInt64CounterConn(conn, readCounter, writeCounter)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *ConnTracker) RoutedPacketConnection(ctx context.Context, conn network.PacketConn, metadata adapter.InboundContext, matchedRule adapter.Rule, matchOutbound adapter.Outbound) network.PacketConn {
|
||||||
|
readCounter, writeCounter := c.getReadCounters(metadata.Inbound, matchOutbound.Tag(), metadata.User)
|
||||||
|
return bufio.NewInt64CounterPacketConn(conn, readCounter, writeCounter)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *ConnTracker) GetStats() *[]model.Stats {
|
||||||
|
c.access.Lock()
|
||||||
|
defer c.access.Unlock()
|
||||||
|
|
||||||
|
dt := time.Now().Unix()
|
||||||
|
|
||||||
|
s := []model.Stats{}
|
||||||
|
for inbound, counter := range c.inbounds {
|
||||||
|
down := counter.write.Swap(0)
|
||||||
|
up := counter.read.Swap(0)
|
||||||
|
if down > 0 || up > 0 {
|
||||||
|
s = append(s, model.Stats{
|
||||||
|
DateTime: dt,
|
||||||
|
Resource: "inbound",
|
||||||
|
Tag: inbound,
|
||||||
|
Direction: false,
|
||||||
|
Traffic: down,
|
||||||
|
}, model.Stats{
|
||||||
|
DateTime: dt,
|
||||||
|
Resource: "inbound",
|
||||||
|
Tag: inbound,
|
||||||
|
Direction: true,
|
||||||
|
Traffic: up,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for outbound, counter := range c.outbounds {
|
||||||
|
down := counter.write.Swap(0)
|
||||||
|
up := counter.read.Swap(0)
|
||||||
|
if down > 0 || up > 0 {
|
||||||
|
s = append(s, model.Stats{
|
||||||
|
DateTime: dt,
|
||||||
|
Resource: "outbound",
|
||||||
|
Tag: outbound,
|
||||||
|
Direction: false,
|
||||||
|
Traffic: down,
|
||||||
|
}, model.Stats{
|
||||||
|
DateTime: dt,
|
||||||
|
Resource: "outbound",
|
||||||
|
Tag: outbound,
|
||||||
|
Direction: true,
|
||||||
|
Traffic: up,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for user, counter := range c.users {
|
||||||
|
down := counter.write.Swap(0)
|
||||||
|
up := counter.read.Swap(0)
|
||||||
|
if down > 0 || up > 0 {
|
||||||
|
s = append(s, model.Stats{
|
||||||
|
DateTime: dt,
|
||||||
|
Resource: "user",
|
||||||
|
Tag: user,
|
||||||
|
Direction: false,
|
||||||
|
Traffic: down,
|
||||||
|
}, model.Stats{
|
||||||
|
DateTime: dt,
|
||||||
|
Resource: "user",
|
||||||
|
Tag: user,
|
||||||
|
Direction: true,
|
||||||
|
Traffic: up,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return &s
|
||||||
|
}
|
||||||
@@ -0,0 +1,109 @@
|
|||||||
|
package core
|
||||||
|
|
||||||
|
import (
|
||||||
|
"s-ui/logger"
|
||||||
|
"s-ui/util/common"
|
||||||
|
|
||||||
|
"github.com/sagernet/sing-box/option"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (c *Core) AddInbound(config []byte) error {
|
||||||
|
if !c.isRunning {
|
||||||
|
return common.NewError("sing-box is not running")
|
||||||
|
}
|
||||||
|
var err error
|
||||||
|
var inbound_config option.Inbound
|
||||||
|
err = inbound_config.UnmarshalJSONContext(globalCtx, config)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = inbound_manager.Create(
|
||||||
|
globalCtx,
|
||||||
|
router,
|
||||||
|
factory.NewLogger("inbound/"+inbound_config.Type+"["+inbound_config.Tag+"]"),
|
||||||
|
inbound_config.Tag,
|
||||||
|
inbound_config.Type,
|
||||||
|
inbound_config.Options)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Core) RemoveInbound(tag string) error {
|
||||||
|
if !c.isRunning {
|
||||||
|
return common.NewError("sing-box is not running")
|
||||||
|
}
|
||||||
|
logger.Info("remove inbound: ", tag)
|
||||||
|
return inbound_manager.Remove(tag)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Core) AddOutbound(config []byte) error {
|
||||||
|
if !c.isRunning {
|
||||||
|
return common.NewError("sing-box is not running")
|
||||||
|
}
|
||||||
|
var err error
|
||||||
|
var outbound_config option.Outbound
|
||||||
|
|
||||||
|
err = outbound_config.UnmarshalJSONContext(globalCtx, config)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = outbound_manager.Create(
|
||||||
|
globalCtx,
|
||||||
|
router,
|
||||||
|
factory.NewLogger("outbound/"+outbound_config.Type+"["+outbound_config.Tag+"]"),
|
||||||
|
outbound_config.Tag,
|
||||||
|
outbound_config.Type,
|
||||||
|
outbound_config.Options)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Core) RemoveOutbound(tag string) error {
|
||||||
|
if !c.isRunning {
|
||||||
|
return common.NewError("sing-box is not running")
|
||||||
|
}
|
||||||
|
logger.Info("remove outbound: ", tag)
|
||||||
|
return outbound_manager.Remove(tag)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Core) AddEndpoint(config []byte) error {
|
||||||
|
if !c.isRunning {
|
||||||
|
return common.NewError("sing-box is not running")
|
||||||
|
}
|
||||||
|
var err error
|
||||||
|
var endpoint_config option.Endpoint
|
||||||
|
|
||||||
|
err = endpoint_config.UnmarshalJSONContext(globalCtx, config)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = endpoint_manager.Create(
|
||||||
|
globalCtx,
|
||||||
|
router,
|
||||||
|
factory.NewLogger("endpoint/"+endpoint_config.Type+"["+endpoint_config.Tag+"]"),
|
||||||
|
endpoint_config.Tag,
|
||||||
|
endpoint_config.Type,
|
||||||
|
endpoint_config.Options)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Core) RemoveEndpoint(tag string) error {
|
||||||
|
if !c.isRunning {
|
||||||
|
return common.NewError("sing-box is not running")
|
||||||
|
}
|
||||||
|
logger.Info("remove endpoint: ", tag)
|
||||||
|
return endpoint_manager.Remove(tag)
|
||||||
|
}
|
||||||
+236
@@ -0,0 +1,236 @@
|
|||||||
|
package core
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
suiLog "s-ui/logger"
|
||||||
|
|
||||||
|
"github.com/sagernet/sing-box/log"
|
||||||
|
"github.com/sagernet/sing/common"
|
||||||
|
F "github.com/sagernet/sing/common/format"
|
||||||
|
"github.com/sagernet/sing/common/observable"
|
||||||
|
"github.com/sagernet/sing/service/filemanager"
|
||||||
|
)
|
||||||
|
|
||||||
|
type PlatformWriter struct{}
|
||||||
|
|
||||||
|
func (p PlatformWriter) DisableColors() bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
func (p PlatformWriter) WriteMessage(level log.Level, message string) {
|
||||||
|
switch level {
|
||||||
|
case log.LevelInfo:
|
||||||
|
suiLog.Info(message)
|
||||||
|
case log.LevelWarn:
|
||||||
|
suiLog.Warning(message)
|
||||||
|
case log.LevelPanic:
|
||||||
|
case log.LevelFatal:
|
||||||
|
case log.LevelError:
|
||||||
|
suiLog.Error(message)
|
||||||
|
default:
|
||||||
|
suiLog.Debug(message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewFactory(options log.Options) (log.Factory, error) {
|
||||||
|
logOptions := options.Options
|
||||||
|
|
||||||
|
if logOptions.Disabled {
|
||||||
|
return log.NewNOPFactory(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var logWriter io.Writer
|
||||||
|
var logFilePath string
|
||||||
|
|
||||||
|
switch logOptions.Output {
|
||||||
|
case "":
|
||||||
|
logWriter = options.DefaultWriter
|
||||||
|
if logWriter == nil {
|
||||||
|
logWriter = os.Stderr
|
||||||
|
}
|
||||||
|
case "stderr":
|
||||||
|
logWriter = os.Stderr
|
||||||
|
case "stdout":
|
||||||
|
logWriter = os.Stdout
|
||||||
|
default:
|
||||||
|
logFilePath = logOptions.Output
|
||||||
|
}
|
||||||
|
logFormatter := log.Formatter{
|
||||||
|
BaseTime: options.BaseTime,
|
||||||
|
DisableColors: logOptions.DisableColor || logFilePath != "",
|
||||||
|
DisableTimestamp: !logOptions.Timestamp && logFilePath != "",
|
||||||
|
FullTimestamp: logOptions.Timestamp,
|
||||||
|
TimestampFormat: "-0700 2006-01-02 15:04:05",
|
||||||
|
}
|
||||||
|
factory := NewDefaultFactory(
|
||||||
|
options.Context,
|
||||||
|
logFormatter,
|
||||||
|
logWriter,
|
||||||
|
logFilePath,
|
||||||
|
)
|
||||||
|
if logOptions.Level != "" {
|
||||||
|
logLevel, err := log.ParseLevel(logOptions.Level)
|
||||||
|
if err != nil {
|
||||||
|
return nil, common.Error("parse log level", err)
|
||||||
|
}
|
||||||
|
factory.SetLevel(logLevel)
|
||||||
|
} else {
|
||||||
|
factory.SetLevel(log.LevelTrace)
|
||||||
|
}
|
||||||
|
return factory, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ log.Factory = (*defaultFactory)(nil)
|
||||||
|
|
||||||
|
type defaultFactory struct {
|
||||||
|
ctx context.Context
|
||||||
|
formatter log.Formatter
|
||||||
|
writer io.Writer
|
||||||
|
file *os.File
|
||||||
|
filePath string
|
||||||
|
level log.Level
|
||||||
|
subscriber *observable.Subscriber[log.Entry]
|
||||||
|
observer *observable.Observer[log.Entry]
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewDefaultFactory(
|
||||||
|
ctx context.Context,
|
||||||
|
formatter log.Formatter,
|
||||||
|
writer io.Writer,
|
||||||
|
filePath string,
|
||||||
|
) log.ObservableFactory {
|
||||||
|
factory := &defaultFactory{
|
||||||
|
ctx: ctx,
|
||||||
|
formatter: formatter,
|
||||||
|
writer: writer,
|
||||||
|
filePath: filePath,
|
||||||
|
level: log.LevelTrace,
|
||||||
|
subscriber: observable.NewSubscriber[log.Entry](128),
|
||||||
|
}
|
||||||
|
return factory
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *defaultFactory) Start() error {
|
||||||
|
if f.filePath != "" {
|
||||||
|
logFile, err := filemanager.OpenFile(f.ctx, f.filePath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o644)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
f.writer = logFile
|
||||||
|
f.file = logFile
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *defaultFactory) Close() error {
|
||||||
|
return common.Close(
|
||||||
|
common.PtrOrNil(f.file),
|
||||||
|
f.subscriber,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *defaultFactory) Level() log.Level {
|
||||||
|
return f.level
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *defaultFactory) SetLevel(level log.Level) {
|
||||||
|
f.level = level
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *defaultFactory) Logger() log.ContextLogger {
|
||||||
|
return f.NewLogger("")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *defaultFactory) NewLogger(tag string) log.ContextLogger {
|
||||||
|
return &observableLogger{f, tag}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *defaultFactory) Subscribe() (subscription observable.Subscription[log.Entry], done <-chan struct{}, err error) {
|
||||||
|
return f.observer.Subscribe()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *defaultFactory) UnSubscribe(sub observable.Subscription[log.Entry]) {
|
||||||
|
f.observer.UnSubscribe(sub)
|
||||||
|
}
|
||||||
|
|
||||||
|
type observableLogger struct {
|
||||||
|
*defaultFactory
|
||||||
|
tag string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *observableLogger) Log(ctx context.Context, level log.Level, args []any) {
|
||||||
|
level = log.OverrideLevelFromContext(level, ctx)
|
||||||
|
if level > l.level {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
msg := F.ToString(args...)
|
||||||
|
switch level {
|
||||||
|
case log.LevelInfo:
|
||||||
|
suiLog.Info(l.tag, msg)
|
||||||
|
case log.LevelWarn:
|
||||||
|
suiLog.Warning(l.tag, msg)
|
||||||
|
case log.LevelPanic:
|
||||||
|
case log.LevelFatal:
|
||||||
|
case log.LevelError:
|
||||||
|
suiLog.Error(l.tag, msg)
|
||||||
|
default:
|
||||||
|
suiLog.Debug(l.tag, msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *observableLogger) Trace(args ...any) {
|
||||||
|
l.TraceContext(context.Background(), args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *observableLogger) Debug(args ...any) {
|
||||||
|
l.DebugContext(context.Background(), args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *observableLogger) Info(args ...any) {
|
||||||
|
l.InfoContext(context.Background(), args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *observableLogger) Warn(args ...any) {
|
||||||
|
l.WarnContext(context.Background(), args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *observableLogger) Error(args ...any) {
|
||||||
|
l.ErrorContext(context.Background(), args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *observableLogger) Fatal(args ...any) {
|
||||||
|
l.FatalContext(context.Background(), args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *observableLogger) Panic(args ...any) {
|
||||||
|
l.PanicContext(context.Background(), args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *observableLogger) TraceContext(ctx context.Context, args ...any) {
|
||||||
|
l.Log(ctx, log.LevelTrace, args)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *observableLogger) DebugContext(ctx context.Context, args ...any) {
|
||||||
|
l.Log(ctx, log.LevelDebug, args)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *observableLogger) InfoContext(ctx context.Context, args ...any) {
|
||||||
|
l.Log(ctx, log.LevelInfo, args)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *observableLogger) WarnContext(ctx context.Context, args ...any) {
|
||||||
|
l.Log(ctx, log.LevelWarn, args)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *observableLogger) ErrorContext(ctx context.Context, args ...any) {
|
||||||
|
l.Log(ctx, log.LevelError, args)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *observableLogger) FatalContext(ctx context.Context, args ...any) {
|
||||||
|
l.Log(ctx, log.LevelFatal, args)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *observableLogger) PanicContext(ctx context.Context, args ...any) {
|
||||||
|
l.Log(ctx, log.LevelPanic, args)
|
||||||
|
}
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
package core
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"s-ui/logger"
|
||||||
|
|
||||||
|
sb "github.com/sagernet/sing-box"
|
||||||
|
"github.com/sagernet/sing-box/adapter"
|
||||||
|
_ "github.com/sagernet/sing-box/experimental/clashapi"
|
||||||
|
_ "github.com/sagernet/sing-box/experimental/v2rayapi"
|
||||||
|
"github.com/sagernet/sing-box/log"
|
||||||
|
"github.com/sagernet/sing-box/option"
|
||||||
|
_ "github.com/sagernet/sing-box/transport/v2rayquic"
|
||||||
|
_ "github.com/sagernet/sing-dns/quic"
|
||||||
|
"github.com/sagernet/sing/service"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
globalCtx context.Context
|
||||||
|
inbound_manager adapter.InboundManager
|
||||||
|
outbound_manager adapter.OutboundManager
|
||||||
|
endpoint_manager adapter.EndpointManager
|
||||||
|
router adapter.Router
|
||||||
|
connTracker *ConnTracker
|
||||||
|
factory log.Factory
|
||||||
|
)
|
||||||
|
|
||||||
|
type Core struct {
|
||||||
|
isRunning bool
|
||||||
|
instance *Box
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewCore() *Core {
|
||||||
|
globalCtx = context.Background()
|
||||||
|
globalCtx = sb.Context(globalCtx, inboundRegistry(), outboundRegistry(), EndpointRegistry())
|
||||||
|
return &Core{
|
||||||
|
isRunning: false,
|
||||||
|
instance: nil,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Core) GetCtx() context.Context {
|
||||||
|
return globalCtx
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Core) GetInstance() *Box {
|
||||||
|
return c.instance
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Core) Start(sbConfig []byte) error {
|
||||||
|
var opt option.Options
|
||||||
|
err := opt.UnmarshalJSONContext(globalCtx, sbConfig)
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("Unmarshal config err:", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
c.instance, err = NewBox(Options{
|
||||||
|
Context: globalCtx,
|
||||||
|
Options: opt,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = c.instance.Start()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
globalCtx = service.ContextWith(globalCtx, c)
|
||||||
|
inbound_manager = service.FromContext[adapter.InboundManager](globalCtx)
|
||||||
|
outbound_manager = service.FromContext[adapter.OutboundManager](globalCtx)
|
||||||
|
endpoint_manager = service.FromContext[adapter.EndpointManager](globalCtx)
|
||||||
|
router = service.FromContext[adapter.Router](globalCtx)
|
||||||
|
|
||||||
|
c.isRunning = true
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Core) Stop() error {
|
||||||
|
if c.isRunning {
|
||||||
|
c.isRunning = false
|
||||||
|
return c.instance.Close()
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Core) IsRunning() bool {
|
||||||
|
return c.isRunning
|
||||||
|
}
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
package core
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/sagernet/sing-box/adapter/endpoint"
|
||||||
|
"github.com/sagernet/sing-box/adapter/inbound"
|
||||||
|
"github.com/sagernet/sing-box/adapter/outbound"
|
||||||
|
"github.com/sagernet/sing-box/protocol/block"
|
||||||
|
"github.com/sagernet/sing-box/protocol/direct"
|
||||||
|
"github.com/sagernet/sing-box/protocol/dns"
|
||||||
|
"github.com/sagernet/sing-box/protocol/group"
|
||||||
|
"github.com/sagernet/sing-box/protocol/http"
|
||||||
|
"github.com/sagernet/sing-box/protocol/hysteria"
|
||||||
|
"github.com/sagernet/sing-box/protocol/hysteria2"
|
||||||
|
"github.com/sagernet/sing-box/protocol/mixed"
|
||||||
|
"github.com/sagernet/sing-box/protocol/naive"
|
||||||
|
_ "github.com/sagernet/sing-box/protocol/naive/quic"
|
||||||
|
"github.com/sagernet/sing-box/protocol/redirect"
|
||||||
|
"github.com/sagernet/sing-box/protocol/shadowsocks"
|
||||||
|
"github.com/sagernet/sing-box/protocol/shadowtls"
|
||||||
|
"github.com/sagernet/sing-box/protocol/socks"
|
||||||
|
"github.com/sagernet/sing-box/protocol/ssh"
|
||||||
|
"github.com/sagernet/sing-box/protocol/tor"
|
||||||
|
"github.com/sagernet/sing-box/protocol/trojan"
|
||||||
|
"github.com/sagernet/sing-box/protocol/tuic"
|
||||||
|
"github.com/sagernet/sing-box/protocol/tun"
|
||||||
|
"github.com/sagernet/sing-box/protocol/vless"
|
||||||
|
"github.com/sagernet/sing-box/protocol/vmess"
|
||||||
|
"github.com/sagernet/sing-box/protocol/wireguard"
|
||||||
|
_ "github.com/sagernet/sing-box/transport/v2rayquic"
|
||||||
|
_ "github.com/sagernet/sing-dns/quic"
|
||||||
|
)
|
||||||
|
|
||||||
|
func inboundRegistry() *inbound.Registry {
|
||||||
|
registry := inbound.NewRegistry()
|
||||||
|
|
||||||
|
tun.RegisterInbound(registry)
|
||||||
|
redirect.RegisterRedirect(registry)
|
||||||
|
redirect.RegisterTProxy(registry)
|
||||||
|
direct.RegisterInbound(registry)
|
||||||
|
|
||||||
|
socks.RegisterInbound(registry)
|
||||||
|
http.RegisterInbound(registry)
|
||||||
|
mixed.RegisterInbound(registry)
|
||||||
|
|
||||||
|
shadowsocks.RegisterInbound(registry)
|
||||||
|
vmess.RegisterInbound(registry)
|
||||||
|
trojan.RegisterInbound(registry)
|
||||||
|
naive.RegisterInbound(registry)
|
||||||
|
shadowtls.RegisterInbound(registry)
|
||||||
|
vless.RegisterInbound(registry)
|
||||||
|
|
||||||
|
hysteria.RegisterInbound(registry)
|
||||||
|
tuic.RegisterInbound(registry)
|
||||||
|
hysteria2.RegisterInbound(registry)
|
||||||
|
|
||||||
|
return registry
|
||||||
|
}
|
||||||
|
|
||||||
|
func outboundRegistry() *outbound.Registry {
|
||||||
|
registry := outbound.NewRegistry()
|
||||||
|
|
||||||
|
direct.RegisterOutbound(registry)
|
||||||
|
|
||||||
|
block.RegisterOutbound(registry)
|
||||||
|
dns.RegisterOutbound(registry)
|
||||||
|
|
||||||
|
group.RegisterSelector(registry)
|
||||||
|
group.RegisterURLTest(registry)
|
||||||
|
|
||||||
|
socks.RegisterOutbound(registry)
|
||||||
|
http.RegisterOutbound(registry)
|
||||||
|
shadowsocks.RegisterOutbound(registry)
|
||||||
|
vmess.RegisterOutbound(registry)
|
||||||
|
trojan.RegisterOutbound(registry)
|
||||||
|
tor.RegisterOutbound(registry)
|
||||||
|
ssh.RegisterOutbound(registry)
|
||||||
|
shadowtls.RegisterOutbound(registry)
|
||||||
|
vless.RegisterOutbound(registry)
|
||||||
|
|
||||||
|
hysteria.RegisterOutbound(registry)
|
||||||
|
tuic.RegisterOutbound(registry)
|
||||||
|
hysteria2.RegisterOutbound(registry)
|
||||||
|
wireguard.RegisterOutbound(registry)
|
||||||
|
|
||||||
|
return registry
|
||||||
|
}
|
||||||
|
|
||||||
|
func EndpointRegistry() *endpoint.Registry {
|
||||||
|
registry := endpoint.NewRegistry()
|
||||||
|
|
||||||
|
wireguard.RegisterEndpoint(registry)
|
||||||
|
|
||||||
|
return registry
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package cronjob
|
||||||
|
|
||||||
|
import (
|
||||||
|
"s-ui/service"
|
||||||
|
)
|
||||||
|
|
||||||
|
type CheckCoreJob struct {
|
||||||
|
service.ConfigService
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewCheckCoreJob() *CheckCoreJob {
|
||||||
|
return &CheckCoreJob{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *CheckCoreJob) Run() {
|
||||||
|
s.ConfigService.StartCore("")
|
||||||
|
}
|
||||||
@@ -14,7 +14,7 @@ func NewCronJob() *CronJob {
|
|||||||
return &CronJob{}
|
return &CronJob{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *CronJob) Start(loc *time.Location) error {
|
func (c *CronJob) Start(loc *time.Location, trafficAge int) error {
|
||||||
c.cron = cron.New(cron.WithLocation(loc), cron.WithSeconds())
|
c.cron = cron.New(cron.WithLocation(loc), cron.WithSeconds())
|
||||||
c.cron.Start()
|
c.cron.Start()
|
||||||
|
|
||||||
@@ -24,7 +24,9 @@ func (c *CronJob) Start(loc *time.Location) error {
|
|||||||
// Start expiry job
|
// Start expiry job
|
||||||
c.cron.AddJob("@every 1m", NewDepleteJob())
|
c.cron.AddJob("@every 1m", NewDepleteJob())
|
||||||
// Start deleting old stats
|
// Start deleting old stats
|
||||||
c.cron.AddJob("@daily", NewDelStatsJob())
|
c.cron.AddJob("@daily", NewDelStatsJob(trafficAge))
|
||||||
|
// Start core if it is not running
|
||||||
|
c.cron.AddJob("@every 5s", NewCheckCoreJob())
|
||||||
}()
|
}()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -7,16 +7,20 @@ import (
|
|||||||
|
|
||||||
type DelStatsJob struct {
|
type DelStatsJob struct {
|
||||||
service.StatsService
|
service.StatsService
|
||||||
|
trafficAge int
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDelStatsJob() *DelStatsJob {
|
func NewDelStatsJob(ta int) *DelStatsJob {
|
||||||
return &DelStatsJob{}
|
return &DelStatsJob{
|
||||||
|
trafficAge: ta,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DelStatsJob) Run() {
|
func (s *DelStatsJob) Run() {
|
||||||
err := s.StatsService.DelOldStats(30)
|
err := s.StatsService.DelOldStats(s.trafficAge)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Warning("Deleting old statistics failed: ", err)
|
logger.Warning("Deleting old statistics failed: ", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
logger.Debug("Stats older than ", s.trafficAge, " days were deleted")
|
||||||
}
|
}
|
||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type DepleteJob struct {
|
type DepleteJob struct {
|
||||||
service.ConfigService
|
service.ClientService
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDepleteJob() *DepleteJob {
|
func NewDepleteJob() *DepleteJob {
|
||||||
@@ -14,7 +14,7 @@ func NewDepleteJob() *DepleteJob {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *DepleteJob) Run() {
|
func (s *DepleteJob) Run() {
|
||||||
err := s.ConfigService.DepleteClients()
|
err := s.ClientService.DepleteClients()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Warning("Disable depleted users failed: ", err)
|
logger.Warning("Disable depleted users failed: ", err)
|
||||||
return
|
return
|
||||||
@@ -6,15 +6,15 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type StatsJob struct {
|
type StatsJob struct {
|
||||||
service.SingBoxService
|
service.StatsService
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewStatsJob() *StatsJob {
|
func NewStatsJob() *StatsJob {
|
||||||
return new(StatsJob)
|
return &StatsJob{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StatsJob) Run() {
|
func (s *StatsJob) Run() {
|
||||||
err := s.SingBoxService.GetStats()
|
err := s.StatsService.SaveStats()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Warning("Get stats failed: ", err)
|
logger.Warning("Get stats failed: ", err)
|
||||||
return
|
return
|
||||||
@@ -0,0 +1,275 @@
|
|||||||
|
package database
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"mime/multipart"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"s-ui/cmd/migration"
|
||||||
|
"s-ui/config"
|
||||||
|
"s-ui/database/model"
|
||||||
|
"s-ui/logger"
|
||||||
|
"s-ui/util/common"
|
||||||
|
"strings"
|
||||||
|
"syscall"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"gorm.io/driver/sqlite"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetDb(exclude string) ([]byte, error) {
|
||||||
|
exclude_changes, exclude_stats := false, false
|
||||||
|
for _, table := range strings.Split(exclude, ",") {
|
||||||
|
if table == "changes" {
|
||||||
|
exclude_changes = true
|
||||||
|
} else if table == "stats" {
|
||||||
|
exclude_stats = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
dbPath := dir + config.GetName() + "_" + time.Now().Format("20060102-200203") + ".db"
|
||||||
|
|
||||||
|
backupDb, err := gorm.Open(sqlite.Open(dbPath), &gorm.Config{})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = backupDb.AutoMigrate(
|
||||||
|
&model.Setting{},
|
||||||
|
&model.Tls{},
|
||||||
|
&model.Inbound{},
|
||||||
|
&model.Outbound{},
|
||||||
|
&model.Endpoint{},
|
||||||
|
&model.User{},
|
||||||
|
&model.Stats{},
|
||||||
|
&model.Client{},
|
||||||
|
&model.Changes{},
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var settings []model.Setting
|
||||||
|
var tls []model.Tls
|
||||||
|
var inbound []model.Inbound
|
||||||
|
var outbound []model.Outbound
|
||||||
|
var endpoint []model.Endpoint
|
||||||
|
var users []model.User
|
||||||
|
var clients []model.Client
|
||||||
|
var stats []model.Stats
|
||||||
|
var changes []model.Changes
|
||||||
|
|
||||||
|
// Perform scans and handle errors
|
||||||
|
if err := db.Model(&model.Setting{}).Scan(&settings).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := db.Model(&model.Tls{}).Scan(&tls).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := db.Model(&model.Inbound{}).Scan(&inbound).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := db.Model(&model.Outbound{}).Scan(&outbound).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := db.Model(&model.Endpoint{}).Scan(&endpoint).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := db.Model(&model.User{}).Scan(&users).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := db.Model(&model.Client{}).Scan(&clients).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save each model
|
||||||
|
for _, mdl := range []interface{}{settings, tls, inbound, outbound, endpoint, users, clients} {
|
||||||
|
if err := backupDb.Save(mdl).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !exclude_stats {
|
||||||
|
if err := db.Model(&model.Stats{}).Scan(&stats).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(stats) > 0 {
|
||||||
|
if err := backupDb.Save(stats).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !exclude_changes {
|
||||||
|
if err := db.Model(&model.Changes{}).Scan(&changes).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(changes) > 0 {
|
||||||
|
if err := backupDb.Save(changes).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update WAL
|
||||||
|
err = backupDb.Exec("PRAGMA wal_checkpoint;").Error
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
bdb, _ := backupDb.DB()
|
||||||
|
bdb.Close()
|
||||||
|
|
||||||
|
// Open the file for reading
|
||||||
|
file, err := os.Open(dbPath)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
defer os.Remove(dbPath)
|
||||||
|
|
||||||
|
// Read the file contents
|
||||||
|
fileContents, err := io.ReadAll(file)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return fileContents, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func ImportDB(file multipart.File) error {
|
||||||
|
// Check if the file is a SQLite database
|
||||||
|
isValidDb, err := IsSQLiteDB(file)
|
||||||
|
if err != nil {
|
||||||
|
return common.NewErrorf("Error checking db file format: %v", err)
|
||||||
|
}
|
||||||
|
if !isValidDb {
|
||||||
|
return common.NewError("Invalid db file format")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset the file reader to the beginning
|
||||||
|
_, err = file.Seek(0, 0)
|
||||||
|
if err != nil {
|
||||||
|
return common.NewErrorf("Error resetting file reader: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save the file as temporary file
|
||||||
|
tempPath := fmt.Sprintf("%s.temp", config.GetDBPath())
|
||||||
|
// Remove the existing fallback file (if any) before creating one
|
||||||
|
_, err = os.Stat(tempPath)
|
||||||
|
if err == nil {
|
||||||
|
errRemove := os.Remove(tempPath)
|
||||||
|
if errRemove != nil {
|
||||||
|
return common.NewErrorf("Error removing existing temporary db file: %v", errRemove)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Create the temporary file
|
||||||
|
tempFile, err := os.Create(tempPath)
|
||||||
|
if err != nil {
|
||||||
|
return common.NewErrorf("Error creating temporary db file: %v", err)
|
||||||
|
}
|
||||||
|
defer tempFile.Close()
|
||||||
|
|
||||||
|
// Remove temp file before returning
|
||||||
|
defer os.Remove(tempPath)
|
||||||
|
|
||||||
|
// Close old DB
|
||||||
|
old_db, _ := db.DB()
|
||||||
|
old_db.Close()
|
||||||
|
|
||||||
|
// Save uploaded file to temporary file
|
||||||
|
_, err = io.Copy(tempFile, file)
|
||||||
|
if err != nil {
|
||||||
|
return common.NewErrorf("Error saving db: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if we can init db or not
|
||||||
|
newDb, err := gorm.Open(sqlite.Open(tempPath), &gorm.Config{})
|
||||||
|
if err != nil {
|
||||||
|
return common.NewErrorf("Error checking db: %v", err)
|
||||||
|
}
|
||||||
|
newDb_db, _ := newDb.DB()
|
||||||
|
newDb_db.Close()
|
||||||
|
|
||||||
|
// Backup the current database for fallback
|
||||||
|
fallbackPath := fmt.Sprintf("%s.backup", config.GetDBPath())
|
||||||
|
// Remove the existing fallback file (if any)
|
||||||
|
_, err = os.Stat(fallbackPath)
|
||||||
|
if err == nil {
|
||||||
|
errRemove := os.Remove(fallbackPath)
|
||||||
|
if errRemove != nil {
|
||||||
|
return common.NewErrorf("Error removing existing fallback db file: %v", errRemove)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Move the current database to the fallback location
|
||||||
|
err = os.Rename(config.GetDBPath(), fallbackPath)
|
||||||
|
if err != nil {
|
||||||
|
return common.NewErrorf("Error backing up temporary db file: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove the temporary file before returning
|
||||||
|
defer os.Remove(fallbackPath)
|
||||||
|
|
||||||
|
// Move temp to DB path
|
||||||
|
err = os.Rename(tempPath, config.GetDBPath())
|
||||||
|
if err != nil {
|
||||||
|
errRename := os.Rename(fallbackPath, config.GetDBPath())
|
||||||
|
if errRename != nil {
|
||||||
|
return common.NewErrorf("Error moving db file and restoring fallback: %v", errRename)
|
||||||
|
}
|
||||||
|
return common.NewErrorf("Error moving db file: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Migrate DB
|
||||||
|
migration.MigrateDb()
|
||||||
|
err = InitDB(config.GetDBPath())
|
||||||
|
if err != nil {
|
||||||
|
errRename := os.Rename(fallbackPath, config.GetDBPath())
|
||||||
|
if errRename != nil {
|
||||||
|
return common.NewErrorf("Error migrating db and restoring fallback: %v", errRename)
|
||||||
|
}
|
||||||
|
return common.NewErrorf("Error migrating db: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Restart app
|
||||||
|
err = SendSighup()
|
||||||
|
if err != nil {
|
||||||
|
return common.NewErrorf("Error restarting app: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsSQLiteDB(file io.Reader) (bool, error) {
|
||||||
|
signature := []byte("SQLite format 3\x00")
|
||||||
|
buf := make([]byte, len(signature))
|
||||||
|
_, err := file.Read(buf)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
return bytes.Equal(buf, signature), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func SendSighup() error {
|
||||||
|
// Get the current process
|
||||||
|
process, err := os.FindProcess(os.Getpid())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send SIGHUP to the current process
|
||||||
|
go func() {
|
||||||
|
time.Sleep(3 * time.Second)
|
||||||
|
err := process.Signal(syscall.SIGHUP)
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("send signal SIGHUP failed:", err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package database
|
package database
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"s-ui/config"
|
"s-ui/config"
|
||||||
@@ -29,7 +30,7 @@ func initUser() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func InitDB(dbPath string) error {
|
func OpenDB(dbPath string) error {
|
||||||
dir := path.Dir(dbPath)
|
dir := path.Dir(dbPath)
|
||||||
err := os.MkdirAll(dir, 01740)
|
err := os.MkdirAll(dir, 01740)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -48,13 +49,37 @@ func InitDB(dbPath string) error {
|
|||||||
Logger: gormLogger,
|
Logger: gormLogger,
|
||||||
}
|
}
|
||||||
db, err = gorm.Open(sqlite.Open(dbPath), c)
|
db, err = gorm.Open(sqlite.Open(dbPath), c)
|
||||||
|
|
||||||
|
if config.IsDebug() {
|
||||||
|
db = db.Debug()
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func InitDB(dbPath string) error {
|
||||||
|
err := OpenDB(dbPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Default Outbounds
|
||||||
|
if !db.Migrator().HasTable(&model.Outbound{}) {
|
||||||
|
db.Migrator().CreateTable(&model.Outbound{})
|
||||||
|
defaultOutbound := []model.Outbound{
|
||||||
|
{Type: "direct", Tag: "direct", Options: json.RawMessage(`{}`)},
|
||||||
|
{Type: "dns", Tag: "dns-out", Options: json.RawMessage(`{}`)},
|
||||||
|
}
|
||||||
|
db.Create(&defaultOutbound)
|
||||||
|
}
|
||||||
|
|
||||||
err = db.AutoMigrate(
|
err = db.AutoMigrate(
|
||||||
&model.Setting{},
|
&model.Setting{},
|
||||||
|
&model.Tls{},
|
||||||
|
&model.Inbound{},
|
||||||
|
&model.Outbound{},
|
||||||
|
&model.Endpoint{},
|
||||||
&model.User{},
|
&model.User{},
|
||||||
|
&model.Tokens{},
|
||||||
&model.Stats{},
|
&model.Stats{},
|
||||||
&model.Client{},
|
&model.Client{},
|
||||||
&model.Changes{},
|
&model.Changes{},
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Endpoint struct {
|
||||||
|
Id uint `json:"id" form:"id" gorm:"primaryKey;autoIncrement"`
|
||||||
|
Type string `json:"type" form:"type"`
|
||||||
|
Tag string `json:"tag" form:"tag" gorm:"unique"`
|
||||||
|
Options json.RawMessage `json:"-" form:"-"`
|
||||||
|
Ext json.RawMessage `json:"ext" form:"ext"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *Endpoint) UnmarshalJSON(data []byte) error {
|
||||||
|
var err error
|
||||||
|
var raw map[string]interface{}
|
||||||
|
if err = json.Unmarshal(data, &raw); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract fixed fields and store the rest in Options
|
||||||
|
if val, exists := raw["id"].(float64); exists {
|
||||||
|
o.Id = uint(val)
|
||||||
|
}
|
||||||
|
delete(raw, "id")
|
||||||
|
o.Type, _ = raw["type"].(string)
|
||||||
|
delete(raw, "type")
|
||||||
|
o.Tag = raw["tag"].(string)
|
||||||
|
delete(raw, "tag")
|
||||||
|
o.Ext, _ = json.MarshalIndent(raw["ext"], "", " ")
|
||||||
|
delete(raw, "ext")
|
||||||
|
|
||||||
|
// Remaining fields
|
||||||
|
o.Options, err = json.MarshalIndent(raw, "", " ")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarshalJSON customizes marshalling
|
||||||
|
func (o Endpoint) MarshalJSON() ([]byte, error) {
|
||||||
|
// Combine fixed fields and dynamic fields into one map
|
||||||
|
combined := make(map[string]interface{})
|
||||||
|
switch o.Type {
|
||||||
|
case "warp":
|
||||||
|
combined["type"] = "wireguard"
|
||||||
|
default:
|
||||||
|
combined["type"] = o.Type
|
||||||
|
}
|
||||||
|
combined["tag"] = o.Tag
|
||||||
|
|
||||||
|
if o.Options != nil {
|
||||||
|
var restFields map[string]json.RawMessage
|
||||||
|
if err := json.Unmarshal(o.Options, &restFields); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for k, v := range restFields {
|
||||||
|
combined[k] = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return json.Marshal(combined)
|
||||||
|
}
|
||||||
@@ -0,0 +1,103 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Inbound struct {
|
||||||
|
Id uint `json:"id" form:"id" gorm:"primaryKey;autoIncrement"`
|
||||||
|
Type string `json:"type" form:"type"`
|
||||||
|
Tag string `json:"tag" form:"tag" gorm:"unique"`
|
||||||
|
|
||||||
|
// Foreign key to tls table
|
||||||
|
TlsId uint `json:"tls_id" form:"tls_id"`
|
||||||
|
Tls *Tls `json:"tls" form:"tls" gorm:"foreignKey:TlsId;references:Id"`
|
||||||
|
|
||||||
|
Addrs json.RawMessage `json:"addrs" form:"addrs"`
|
||||||
|
OutJson json.RawMessage `json:"out_json" form:"out_json"`
|
||||||
|
Options json.RawMessage `json:"-" form:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *Inbound) UnmarshalJSON(data []byte) error {
|
||||||
|
var err error
|
||||||
|
var raw map[string]interface{}
|
||||||
|
if err = json.Unmarshal(data, &raw); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract fixed fields and store the rest in Options
|
||||||
|
if val, exists := raw["id"].(float64); exists {
|
||||||
|
i.Id = uint(val)
|
||||||
|
}
|
||||||
|
delete(raw, "id")
|
||||||
|
i.Type, _ = raw["type"].(string)
|
||||||
|
delete(raw, "type")
|
||||||
|
i.Tag, _ = raw["tag"].(string)
|
||||||
|
delete(raw, "tag")
|
||||||
|
|
||||||
|
// TlsId
|
||||||
|
if val, exists := raw["tls_id"].(float64); exists {
|
||||||
|
i.TlsId = uint(val)
|
||||||
|
}
|
||||||
|
delete(raw, "tls_id")
|
||||||
|
delete(raw, "tls")
|
||||||
|
delete(raw, "users")
|
||||||
|
|
||||||
|
// Addrs
|
||||||
|
i.Addrs, _ = json.MarshalIndent(raw["addrs"], "", " ")
|
||||||
|
delete(raw, "addrs")
|
||||||
|
|
||||||
|
// OutJson
|
||||||
|
i.OutJson, _ = json.MarshalIndent(raw["out_json"], "", " ")
|
||||||
|
delete(raw, "out_json")
|
||||||
|
|
||||||
|
// Remaining fields
|
||||||
|
i.Options, err = json.MarshalIndent(raw, "", " ")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarshalJSON customizes marshalling
|
||||||
|
func (i Inbound) MarshalJSON() ([]byte, error) {
|
||||||
|
// Combine fixed fields and dynamic fields into one map
|
||||||
|
combined := make(map[string]interface{})
|
||||||
|
combined["type"] = i.Type
|
||||||
|
combined["tag"] = i.Tag
|
||||||
|
if i.Tls != nil {
|
||||||
|
combined["tls"] = i.Tls.Server
|
||||||
|
}
|
||||||
|
|
||||||
|
if i.Options != nil {
|
||||||
|
var restFields map[string]json.RawMessage
|
||||||
|
if err := json.Unmarshal(i.Options, &restFields); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for k, v := range restFields {
|
||||||
|
combined[k] = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return json.Marshal(combined)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i Inbound) MarshalFull() (*map[string]interface{}, error) {
|
||||||
|
combined := make(map[string]interface{})
|
||||||
|
combined["id"] = i.Id
|
||||||
|
combined["type"] = i.Type
|
||||||
|
combined["tag"] = i.Tag
|
||||||
|
combined["tls_id"] = i.TlsId
|
||||||
|
combined["addrs"] = i.Addrs
|
||||||
|
combined["out_json"] = i.OutJson
|
||||||
|
|
||||||
|
if i.Options != nil {
|
||||||
|
var restFields map[string]interface{}
|
||||||
|
if err := json.Unmarshal(i.Options, &restFields); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for k, v := range restFields {
|
||||||
|
combined[k] = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return &combined, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
import "encoding/json"
|
||||||
|
|
||||||
|
type Setting struct {
|
||||||
|
Id uint `json:"id" form:"id" gorm:"primaryKey;autoIncrement"`
|
||||||
|
Key string `json:"key" form:"key"`
|
||||||
|
Value string `json:"value" form:"value"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Tls struct {
|
||||||
|
Id uint `json:"id" form:"id" gorm:"primaryKey;autoIncrement"`
|
||||||
|
Name string `json:"name" form:"name"`
|
||||||
|
Server json.RawMessage `json:"server" form:"server"`
|
||||||
|
Client json.RawMessage `json:"client" form:"client"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type User struct {
|
||||||
|
Id uint `json:"id" form:"id" gorm:"primaryKey;autoIncrement"`
|
||||||
|
Username string `json:"username" form:"username"`
|
||||||
|
Password string `json:"password" form:"password"`
|
||||||
|
LastLogins string `json:"lastLogin"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Client struct {
|
||||||
|
Id uint `json:"id" form:"id" gorm:"primaryKey;autoIncrement"`
|
||||||
|
Enable bool `json:"enable" form:"enable"`
|
||||||
|
Name string `json:"name" form:"name"`
|
||||||
|
Config json.RawMessage `json:"config,omitempty" form:"config"`
|
||||||
|
Inbounds json.RawMessage `json:"inbounds" form:"inbounds"`
|
||||||
|
Links json.RawMessage `json:"links,omitempty" form:"links"`
|
||||||
|
Volume int64 `json:"volume" form:"volume"`
|
||||||
|
Expiry int64 `json:"expiry" form:"expiry"`
|
||||||
|
Down int64 `json:"down" form:"down"`
|
||||||
|
Up int64 `json:"up" form:"up"`
|
||||||
|
Desc string `json:"desc" form:"desc"`
|
||||||
|
Group string `json:"group" form:"group"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Stats struct {
|
||||||
|
Id uint64 `json:"id" gorm:"primaryKey;autoIncrement"`
|
||||||
|
DateTime int64 `json:"dateTime"`
|
||||||
|
Resource string `json:"resource"`
|
||||||
|
Tag string `json:"tag"`
|
||||||
|
Direction bool `json:"direction"`
|
||||||
|
Traffic int64 `json:"traffic"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Changes struct {
|
||||||
|
Id uint64 `json:"id" gorm:"primaryKey;autoIncrement"`
|
||||||
|
DateTime int64 `json:"dateTime"`
|
||||||
|
Actor string `json:"actor"`
|
||||||
|
Key string `json:"key"`
|
||||||
|
Action string `json:"action"`
|
||||||
|
Obj json.RawMessage `json:"obj"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Tokens struct {
|
||||||
|
Id uint `json:"id" form:"id" gorm:"primaryKey;autoIncrement"`
|
||||||
|
Desc string `json:"desc" form:"desc"`
|
||||||
|
Token string `json:"token" form:"token"`
|
||||||
|
Expiry int64 `json:"expiry" form:"expiry"`
|
||||||
|
UserId uint `json:"userId" form:"userId"`
|
||||||
|
User *User `json:"user" gorm:"foreignKey:UserId;references:Id"`
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
import "encoding/json"
|
||||||
|
|
||||||
|
type Outbound struct {
|
||||||
|
Id uint `json:"id" form:"id" gorm:"primaryKey;autoIncrement"`
|
||||||
|
Type string `json:"type" form:"type"`
|
||||||
|
Tag string `json:"tag" form:"tag" gorm:"unique"`
|
||||||
|
Options json.RawMessage `json:"-" form:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *Outbound) UnmarshalJSON(data []byte) error {
|
||||||
|
var err error
|
||||||
|
var raw map[string]interface{}
|
||||||
|
if err = json.Unmarshal(data, &raw); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract fixed fields and store the rest in Options
|
||||||
|
if val, exists := raw["id"].(float64); exists {
|
||||||
|
o.Id = uint(val)
|
||||||
|
}
|
||||||
|
delete(raw, "id")
|
||||||
|
o.Type, _ = raw["type"].(string)
|
||||||
|
delete(raw, "type")
|
||||||
|
o.Tag = raw["tag"].(string)
|
||||||
|
delete(raw, "tag")
|
||||||
|
|
||||||
|
// Remaining fields
|
||||||
|
o.Options, err = json.MarshalIndent(raw, "", " ")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarshalJSON customizes marshalling
|
||||||
|
func (o Outbound) MarshalJSON() ([]byte, error) {
|
||||||
|
// Combine fixed fields and dynamic fields into one map
|
||||||
|
combined := make(map[string]interface{})
|
||||||
|
combined["type"] = o.Type
|
||||||
|
combined["tag"] = o.Tag
|
||||||
|
|
||||||
|
if o.Options != nil {
|
||||||
|
var restFields map[string]json.RawMessage
|
||||||
|
if err := json.Unmarshal(o.Options, &restFields); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for k, v := range restFields {
|
||||||
|
combined[k] = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return json.Marshal(combined)
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
---
|
||||||
|
services:
|
||||||
|
s-ui:
|
||||||
|
image: alireza7/s-ui
|
||||||
|
container_name: s-ui
|
||||||
|
hostname: "s-ui"
|
||||||
|
volumes:
|
||||||
|
- "./db:/app/db"
|
||||||
|
- "./cert:/app/cert"
|
||||||
|
tty: true
|
||||||
|
restart: unless-stopped
|
||||||
|
ports:
|
||||||
|
- "2095:2095"
|
||||||
|
- "2096:2096"
|
||||||
|
networks:
|
||||||
|
- s-ui
|
||||||
|
entrypoint: "./entrypoint.sh"
|
||||||
|
|
||||||
|
networks:
|
||||||
|
s-ui:
|
||||||
|
driver: bridge
|
||||||
|
|
||||||
Executable
+4
@@ -0,0 +1,4 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
./sui migrate
|
||||||
|
./sui
|
||||||
Submodule
+1
Submodule frontend added at 0d3496cfd4
@@ -1,4 +0,0 @@
|
|||||||
> 1%
|
|
||||||
last 2 versions
|
|
||||||
not dead
|
|
||||||
not ie 11
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
[*.{js,jsx,ts,tsx,vue}]
|
|
||||||
indent_style = space
|
|
||||||
indent_size = 2
|
|
||||||
trim_trailing_whitespace = true
|
|
||||||
insert_final_newline = true
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
root: true,
|
|
||||||
env: {
|
|
||||||
node: true,
|
|
||||||
},
|
|
||||||
extends: [
|
|
||||||
'plugin:vue/vue3-essential',
|
|
||||||
'eslint:recommended',
|
|
||||||
'@vue/eslint-config-typescript',
|
|
||||||
],
|
|
||||||
rules: {
|
|
||||||
'vue/multi-word-component-names': 'off',
|
|
||||||
},
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
.DS_Store
|
|
||||||
node_modules
|
|
||||||
/dist
|
|
||||||
/bin
|
|
||||||
|
|
||||||
# local env files
|
|
||||||
.env.local
|
|
||||||
.env.*.local
|
|
||||||
|
|
||||||
# Log files
|
|
||||||
npm-debug.log*
|
|
||||||
yarn-debug.log*
|
|
||||||
yarn-error.log*
|
|
||||||
pnpm-debug.log*
|
|
||||||
|
|
||||||
# Editor directories and files
|
|
||||||
.idea
|
|
||||||
.vscode
|
|
||||||
*.suo
|
|
||||||
*.ntvs*
|
|
||||||
*.njsproj
|
|
||||||
*.sln
|
|
||||||
*.sw?
|
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
# base
|
|
||||||
|
|
||||||
## Project setup
|
|
||||||
|
|
||||||
```
|
|
||||||
# yarn
|
|
||||||
yarn
|
|
||||||
|
|
||||||
# npm
|
|
||||||
npm install
|
|
||||||
|
|
||||||
# pnpm
|
|
||||||
pnpm install
|
|
||||||
|
|
||||||
# bun
|
|
||||||
bun install
|
|
||||||
```
|
|
||||||
|
|
||||||
### Compiles and hot-reloads for development
|
|
||||||
|
|
||||||
```
|
|
||||||
# yarn
|
|
||||||
yarn dev
|
|
||||||
|
|
||||||
# npm
|
|
||||||
npm run dev
|
|
||||||
|
|
||||||
# pnpm
|
|
||||||
pnpm dev
|
|
||||||
|
|
||||||
# bun
|
|
||||||
pnpm run dev
|
|
||||||
```
|
|
||||||
|
|
||||||
### Compiles and minifies for production
|
|
||||||
|
|
||||||
```
|
|
||||||
# yarn
|
|
||||||
yarn build
|
|
||||||
|
|
||||||
# npm
|
|
||||||
npm run build
|
|
||||||
|
|
||||||
# pnpm
|
|
||||||
pnpm build
|
|
||||||
|
|
||||||
# bun
|
|
||||||
pnpm run build
|
|
||||||
```
|
|
||||||
|
|
||||||
### Lints and fixes files
|
|
||||||
|
|
||||||
```
|
|
||||||
# yarn
|
|
||||||
yarn lint
|
|
||||||
|
|
||||||
# npm
|
|
||||||
npm run lint
|
|
||||||
|
|
||||||
# pnpm
|
|
||||||
pnpm lint
|
|
||||||
|
|
||||||
# bun
|
|
||||||
pnpm run lint
|
|
||||||
```
|
|
||||||
|
|
||||||
### Customize configuration
|
|
||||||
|
|
||||||
See [Configuration Reference](https://vitejs.dev/config/).
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8" />
|
|
||||||
<link rel="icon" href="assets/favicon.ico" />
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
||||||
<script>
|
|
||||||
window.BASE_URL = "{{ .BASE_URL }}"
|
|
||||||
|
|
||||||
// Dev Mode
|
|
||||||
if (window.BASE_URL.charAt(0) === '{') window.BASE_URL = "/app/"
|
|
||||||
</script>
|
|
||||||
<title>S-UI</title>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div id="app"></div>
|
|
||||||
<script type="module" src="/src/main.ts"></script>
|
|
||||||
</body>
|
|
||||||
|
|
||||||
</html>
|
|
||||||
Generated
-4964
File diff suppressed because it is too large
Load Diff
@@ -1,42 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "frontend",
|
|
||||||
"version": "0.0.0",
|
|
||||||
"private": true,
|
|
||||||
"scripts": {
|
|
||||||
"dev": "vite",
|
|
||||||
"build": "vue-tsc --noEmit && vite build",
|
|
||||||
"preview": "vite preview",
|
|
||||||
"lint": "eslint . --fix --ignore-path .gitignore"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"@mdi/font": "7.0.96",
|
|
||||||
"axios": "^1.6.5",
|
|
||||||
"chart.js": "^4.4.1",
|
|
||||||
"clipboard": "^2.0.11",
|
|
||||||
"core-js": "^3.29.0",
|
|
||||||
"pinia": "^2.1.7",
|
|
||||||
"qrcode.vue": "^3.4.1",
|
|
||||||
"roboto-fontface": "*",
|
|
||||||
"vue": "^3.2.0",
|
|
||||||
"vue-chartjs": "^5.3.0",
|
|
||||||
"vue-i18n": "^9.8.0",
|
|
||||||
"vue-router": "^4.0.0",
|
|
||||||
"vue3-persian-datetime-picker": "^1.2.2",
|
|
||||||
"vuetify": "^3.0.0"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"@babel/types": "^7.21.4",
|
|
||||||
"@types/node": "^18.15.0",
|
|
||||||
"@vitejs/plugin-vue": "^4.0.0",
|
|
||||||
"@vue/eslint-config-typescript": "^11.0.0",
|
|
||||||
"eslint": "^8.22.0",
|
|
||||||
"eslint-plugin-vue": "^9.3.0",
|
|
||||||
"material-design-icons-iconfont": "^6.7.0",
|
|
||||||
"sass": "^1.60.0",
|
|
||||||
"typescript": "^5.0.0",
|
|
||||||
"unplugin-fonts": "^1.0.3",
|
|
||||||
"vite": "^4.2.0",
|
|
||||||
"vite-plugin-vuetify": "^1.0.0",
|
|
||||||
"vue-tsc": "^1.2.0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.5 KiB |
@@ -1,34 +0,0 @@
|
|||||||
<template>
|
|
||||||
<v-overlay
|
|
||||||
:model-value="loading"
|
|
||||||
persistent
|
|
||||||
content-class="text-center"
|
|
||||||
class="align-center justify-center"
|
|
||||||
>
|
|
||||||
<v-progress-circular
|
|
||||||
indeterminate
|
|
||||||
size="64"
|
|
||||||
></v-progress-circular>
|
|
||||||
<br />
|
|
||||||
{{ $t('loading') }}
|
|
||||||
</v-overlay>
|
|
||||||
<Message />
|
|
||||||
<router-view />
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script lang="ts" setup>
|
|
||||||
import Message from '@/components/message.vue'
|
|
||||||
import { inject, ref, Ref } from 'vue'
|
|
||||||
|
|
||||||
const loading:Ref = inject('loading')?? ref(false)
|
|
||||||
|
|
||||||
// Change page title
|
|
||||||
document.title = "S-UI " + document.location.hostname
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style>
|
|
||||||
.v-overlay .v-list-item,
|
|
||||||
.v-field__input {
|
|
||||||
direction: ltr;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 763 B |
@@ -1,24 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<svg viewBox="1.019 0.0225 45.9789 46.9775" width="45.9789" height="46.9775" xmlns="http://www.w3.org/2000/svg">
|
|
||||||
<g featurekey="symbolFeature-0" transform="matrix(0.4545450210571289, 0, 0, 0.4545450210571289, 0.7917079329490662, 1.7009549140930176)" fill="#737373">
|
|
||||||
<g xmlns="http://www.w3.org/2000/svg">
|
|
||||||
<g>
|
|
||||||
<path d="M50,99.658L0.5,70.699V29.301L50,0.341l49.5,28.959v41.398L50,99.658z M2.5,69.553L50,97.342l47.5-27.789V30.448L50,2.659 L2.5,30.448V69.553z"/>
|
|
||||||
</g>
|
|
||||||
<g>
|
|
||||||
<polygon points="51,98.376 49,98.376 49,58.822 0.995,30.738 2.005,29.011 50,57.091 97.995,29.011 99.005,30.738 51,58.822 "/>
|
|
||||||
</g>
|
|
||||||
<g>
|
|
||||||
<polyline points="28.494,14.082 76.994,42.457 71.506,45.667 23.006,17.292 "/>
|
|
||||||
<polygon points="71.507,46.246 71.254,46.098 22.754,17.724 23.259,16.861 71.507,45.087 76.003,42.457 28.241,14.514 28.746,13.65 77.983,42.457 "/>
|
|
||||||
</g>
|
|
||||||
<g>
|
|
||||||
<polyline points="71.506,45.667 71.506,57.982 71.51,57.982 76.993,54.775 76.993,42.457 "/>
|
|
||||||
<polyline points="71.006,45.667 72.006,45.667 72.006,57.113 76.493,54.487 76.493,42.457 77.493,42.457 77.493,55.062 71.646,58.482 71,58.85 "/>
|
|
||||||
</g>
|
|
||||||
</g>
|
|
||||||
</g>
|
|
||||||
<g featurekey="nameFeature-0" transform="matrix(1.6160469055175781, 0, 0, 1.6160469055175781, 3.2854819297790527, -21.369783401489258)" fill="#a6a6a6">
|
|
||||||
<path d="M10.904 40.4028 c-5.316 0 -9.2256 -3.048 -9.2256 -6.6192 c0 -1.8592 1.2372 -2.8152 2.5116 -2.8152 c1.0924 0 2.2288 0.7184 2.2288 2.1488 c0 1.4428 -1.4112 1.9972 -1.4112 2.9972 c0 1.782 2.974 3.0552 5.338 3.0552 c3.244 0 6.382 -1.5736 6.382 -5.102 c0 -6.2716 -14.403 -3.6536 -14.403 -13.229 c0 -5.0924 4.3436 -7.6012 9.9036 -7.6012 c4.7364 0 8.9656 2.6496 8.9656 6.1048 c0 1.946 -1.2372 2.9308 -2.4828 2.9308 c-1.1216 0 -2.258 -0.7476 -2.258 -2.178 c0 -1.5584 1.382 -1.8812 1.382 -2.8812 c0 -1.6952 -2.974 -2.7436 -5.3092 -2.7436 c-3.04 0 -5.9296 1.1848 -5.9296 4.6496 c0 5.866 15.193 3.7708 15.193 13.345 c0 4.0208 -3.8304 7.938 -10.886 7.938 z"/>
|
|
||||||
</g>
|
|
||||||
</svg>
|
|
||||||
|
Before Width: | Height: | Size: 2.0 KiB |
@@ -1,132 +0,0 @@
|
|||||||
<template>
|
|
||||||
<v-text-field
|
|
||||||
id="expiry"
|
|
||||||
:label="$t('date.expiry')"
|
|
||||||
v-model="dateFormatted"
|
|
||||||
prepend-inner-icon="mdi-calendar"
|
|
||||||
readonly
|
|
||||||
hide-details
|
|
||||||
></v-text-field>
|
|
||||||
<DatePicker
|
|
||||||
v-model="Input"
|
|
||||||
@input="Input=$event"
|
|
||||||
:locale="$i18n.locale"
|
|
||||||
element="expiry"
|
|
||||||
compact-time
|
|
||||||
type="datetime">
|
|
||||||
<template v-slot:next-month>
|
|
||||||
<v-icon icon="mdi-chevron-right" />
|
|
||||||
</template>
|
|
||||||
<template v-slot:prev-month>
|
|
||||||
<v-icon icon="mdi-chevron-left" />
|
|
||||||
</template>
|
|
||||||
<template #submit-btn="{ submit, canSubmit }">
|
|
||||||
<v-btn
|
|
||||||
:disabled="!canSubmit"
|
|
||||||
@click="submit"
|
|
||||||
>{{ $t('submit') }}</v-btn>
|
|
||||||
</template>
|
|
||||||
<template #cancel-btn="{ vm }">
|
|
||||||
<v-btn
|
|
||||||
@click="reset(vm)"
|
|
||||||
>{{ $t('reset') }}</v-btn>
|
|
||||||
</template>
|
|
||||||
<template #now-btn="{ goToday }">
|
|
||||||
<v-btn
|
|
||||||
@click="goToday"
|
|
||||||
>{{ $t('now') }}</v-btn>
|
|
||||||
</template>
|
|
||||||
</DatePicker>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script lang="ts">
|
|
||||||
import DatePicker from 'vue3-persian-datetime-picker'
|
|
||||||
import { i18n } from '@/locales'
|
|
||||||
|
|
||||||
export default {
|
|
||||||
props: ['expiry'],
|
|
||||||
emits: ['submit'],
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
menu: false,
|
|
||||||
input: new Date(),
|
|
||||||
}
|
|
||||||
},
|
|
||||||
components: { DatePicker },
|
|
||||||
computed: {
|
|
||||||
dateFormatted() {
|
|
||||||
if (this.expDate == 0) return i18n.global.t('unlimited')
|
|
||||||
const date = new Date(this.expDate*1000)
|
|
||||||
return date.toLocaleString(i18n.global.locale.value)
|
|
||||||
},
|
|
||||||
expDate() {
|
|
||||||
return parseInt(this.expiry?? 0)
|
|
||||||
},
|
|
||||||
Input: {
|
|
||||||
get() { return this.expDate == 0 ? new Date() : new Date(this.expDate*1000) },
|
|
||||||
set(v:string) {
|
|
||||||
this.input = new Date(v)
|
|
||||||
this.submit()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
updateInput(v:Date) {
|
|
||||||
this.input = v
|
|
||||||
},
|
|
||||||
setNow() {
|
|
||||||
this.input = new Date()
|
|
||||||
},
|
|
||||||
submit() {
|
|
||||||
this.$emit('submit',Math.floor(this.input.getTime()/1000))
|
|
||||||
},
|
|
||||||
reset(vm:any) {
|
|
||||||
this.$emit('submit',0)
|
|
||||||
this.input = new Date()
|
|
||||||
vm.visible = false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
watch: {
|
|
||||||
menu(v) {
|
|
||||||
if (v) {
|
|
||||||
this.input = this.expiry == 0 ? new Date() : new Date(this.expDate*1000)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style>
|
|
||||||
.vpd-addon-list,
|
|
||||||
.vpd-addon-list-item {
|
|
||||||
background-color: rgb(var(--v-theme-background));
|
|
||||||
border-color: rgb(var(--v-theme-background));
|
|
||||||
}
|
|
||||||
.vpd-content {
|
|
||||||
background-color: rgb(var(--v-theme-background));
|
|
||||||
}
|
|
||||||
.vpd-addon-list-item.vpd-selected,
|
|
||||||
.vpd-addon-list-item:hover {
|
|
||||||
background-color: rgb(var(--v-theme-primary));
|
|
||||||
}
|
|
||||||
.vpd-close-addon {
|
|
||||||
color: rgb(var(--v-theme-on-surface));
|
|
||||||
background-color: transparent;
|
|
||||||
}
|
|
||||||
.vpd-controls {
|
|
||||||
overflow-x: hidden;
|
|
||||||
}
|
|
||||||
.vpd-month-label {
|
|
||||||
width: auto;
|
|
||||||
}
|
|
||||||
.vpd-actions button:hover {
|
|
||||||
background-color: transparent;
|
|
||||||
}
|
|
||||||
.vpd-wrapper[data-type=datetime].vpd-compact-time .vpd-time {
|
|
||||||
border-top: 0;
|
|
||||||
}
|
|
||||||
.vpd-time .vpd-time-h .vpd-counter-item,
|
|
||||||
.vpd-time .vpd-time-m .vpd-counter-item {
|
|
||||||
vertical-align: top;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
@@ -1,216 +0,0 @@
|
|||||||
<template>
|
|
||||||
<v-card subtitle="Dial" style="background-color: inherit;">
|
|
||||||
<v-row>
|
|
||||||
<v-col cols="12" sm="6" md="4" v-if="optionDetour">
|
|
||||||
<v-text-field
|
|
||||||
label="Forward to Outbound tag"
|
|
||||||
hide-details
|
|
||||||
v-model="dial.detour"></v-text-field>
|
|
||||||
</v-col>
|
|
||||||
<v-col cols="12" sm="6" md="4" v-if="optionBind">
|
|
||||||
<v-text-field
|
|
||||||
label="Bind to Network Interface"
|
|
||||||
hide-details
|
|
||||||
v-model="dial.bind_interface"></v-text-field>
|
|
||||||
</v-col>
|
|
||||||
</v-row>
|
|
||||||
<v-row>
|
|
||||||
<v-col cols="12" sm="6" md="4" v-if="optionIPV4">
|
|
||||||
<v-text-field
|
|
||||||
label="Bind to IPv4"
|
|
||||||
hide-details
|
|
||||||
v-model="dial.inet4_bind_address"></v-text-field>
|
|
||||||
</v-col>
|
|
||||||
<v-col cols="12" sm="6" md="4" v-if="optionIPV6">
|
|
||||||
<v-text-field
|
|
||||||
label="Bind to IPv6"
|
|
||||||
hide-details
|
|
||||||
v-model="dial.inet6_bind_address"></v-text-field>
|
|
||||||
</v-col>
|
|
||||||
</v-row>
|
|
||||||
<v-row>
|
|
||||||
<v-col cols="12" sm="6" md="4" v-if="optionRM">
|
|
||||||
<v-text-field
|
|
||||||
label="Linux Routing Mark"
|
|
||||||
hide-details
|
|
||||||
type="number"
|
|
||||||
min="0"
|
|
||||||
v-model.number="routingMark"></v-text-field>
|
|
||||||
</v-col>
|
|
||||||
<v-col cols="12" sm="6" md="4" v-if="optionRA">
|
|
||||||
<v-switch v-model="dial.reuse_addr" color="primary" label="Reuse listener address" hide-details></v-switch>
|
|
||||||
</v-col>
|
|
||||||
</v-row>
|
|
||||||
<v-row v-if="optionTCP">
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<v-switch v-model="dial.tcp_fast_open" color="primary" label="TCP Fast Open" hide-details></v-switch>
|
|
||||||
</v-col>
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<v-switch v-model="dial.tcp_multi_path" color="primary" label="TCP Multi Path" hide-details></v-switch>
|
|
||||||
</v-col>
|
|
||||||
</v-row>
|
|
||||||
<v-row>
|
|
||||||
<v-col cols="12" sm="6" md="4" v-if="optionUDP">
|
|
||||||
<v-switch v-model="dial.udp_fragment" color="primary" label="UDP Fragment" hide-details></v-switch>
|
|
||||||
</v-col>
|
|
||||||
<v-col cols="12" sm="6" md="4" v-if="optionCT">
|
|
||||||
<v-text-field
|
|
||||||
label="Connection Timeout"
|
|
||||||
hide-details
|
|
||||||
type="number"
|
|
||||||
min="1"
|
|
||||||
suffix="s"
|
|
||||||
v-model.number="connectTimeout"></v-text-field>
|
|
||||||
</v-col>
|
|
||||||
</v-row>
|
|
||||||
<v-row v-if="optionDS">
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<v-select
|
|
||||||
hide-details
|
|
||||||
clearable
|
|
||||||
@click:clear="delete dial.domain_strategy"
|
|
||||||
width="100"
|
|
||||||
label="Domain to IP Strategy"
|
|
||||||
:items="['prefer_ipv4','prefer_ipv6','ipv4_only','ipv6_only']"
|
|
||||||
v-model="dial.domain_strategy">
|
|
||||||
</v-select>
|
|
||||||
</v-col>
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<v-text-field
|
|
||||||
label="Fallback Timeout"
|
|
||||||
hide-details
|
|
||||||
type="number"
|
|
||||||
min="50"
|
|
||||||
step="50"
|
|
||||||
suffix="ms"
|
|
||||||
v-model.number="fallbackDelay"></v-text-field>
|
|
||||||
</v-col>
|
|
||||||
</v-row>
|
|
||||||
<v-card-actions class="pt-0">
|
|
||||||
<v-spacer></v-spacer>
|
|
||||||
<v-menu v-model="menu" :close-on-content-click="false" location="start">
|
|
||||||
<template v-slot:activator="{ props }">
|
|
||||||
<v-btn v-bind="props" hide-details>Dial Options</v-btn>
|
|
||||||
</template>
|
|
||||||
<v-card>
|
|
||||||
<v-list>
|
|
||||||
<v-list-item>
|
|
||||||
<v-switch v-model="optionDetour" color="primary" label="Detour" hide-details></v-switch>
|
|
||||||
</v-list-item>
|
|
||||||
<v-list-item>
|
|
||||||
<v-switch v-model="optionBind" color="primary" label="Bind Interface" hide-details></v-switch>
|
|
||||||
</v-list-item>
|
|
||||||
<v-list-item>
|
|
||||||
<v-switch v-model="optionIPV4" color="primary" label="Bind to IPv4" hide-details></v-switch>
|
|
||||||
</v-list-item>
|
|
||||||
<v-list-item>
|
|
||||||
<v-switch v-model="optionIPV6" color="primary" label="Bind to IPv6" hide-details></v-switch>
|
|
||||||
</v-list-item>
|
|
||||||
<v-list-item>
|
|
||||||
<v-switch v-model="optionRM" color="primary" label="Routing Mark" hide-details></v-switch>
|
|
||||||
</v-list-item>
|
|
||||||
<v-list-item>
|
|
||||||
<v-switch v-model="optionRA" color="primary" label="Reuse Address" hide-details></v-switch>
|
|
||||||
</v-list-item>
|
|
||||||
<v-list-item>
|
|
||||||
<v-switch v-model="optionTCP" color="primary" label="TCP Options" hide-details></v-switch>
|
|
||||||
</v-list-item>
|
|
||||||
<v-list-item>
|
|
||||||
<v-switch v-model="optionUDP" color="primary" label="UDP Options" hide-details></v-switch>
|
|
||||||
</v-list-item>
|
|
||||||
<v-list-item>
|
|
||||||
<v-switch v-model="optionCT" color="primary" label="Connection Timeout" hide-details></v-switch>
|
|
||||||
</v-list-item>
|
|
||||||
<v-list-item>
|
|
||||||
<v-switch v-model="optionDS" color="primary" label="Domain Strategy" hide-details></v-switch>
|
|
||||||
</v-list-item>
|
|
||||||
</v-list>
|
|
||||||
</v-card>
|
|
||||||
</v-menu>
|
|
||||||
</v-card-actions>
|
|
||||||
</v-card>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script lang="ts">
|
|
||||||
export default {
|
|
||||||
props: ['dial'],
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
menu: false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
fallbackDelay: {
|
|
||||||
get() { return this.$props.dial.fallback_delay ? parseInt(this.$props.dial.fallback_delay.replace('ms','')) : 300 },
|
|
||||||
set(newValue:number) { this.$props.dial.fallback_delay = newValue > 0 ? newValue + 'ms' : '300ms' }
|
|
||||||
},
|
|
||||||
connectTimeout: {
|
|
||||||
get() { return this.$props.dial.connect_timeout ? parseInt(this.$props.dial.connect_timeout.replace('s','')) : 5 },
|
|
||||||
set(newValue:number) { this.$props.dial.connect_timeout = newValue > 0 ? newValue + 's' : '5s' }
|
|
||||||
},
|
|
||||||
routingMark: {
|
|
||||||
get() { return this.$props.dial.routing_mark?? 0 },
|
|
||||||
set(newValue:number) { this.$props.dial.routing_mark = newValue > 0 ? newValue : 0 }
|
|
||||||
},
|
|
||||||
optionDetour: {
|
|
||||||
get(): boolean { return this.$props.dial.detour != undefined },
|
|
||||||
set(v:boolean) { v ? this.$props.dial.detour = '' : delete this.$props.dial.detour }
|
|
||||||
},
|
|
||||||
optionBind: {
|
|
||||||
get(): boolean { return this.$props.dial.bind_interface != undefined },
|
|
||||||
set(v:boolean) { v ? this.$props.dial.bind_interface = '' : delete this.$props.dial.bind_interface }
|
|
||||||
},
|
|
||||||
optionIPV4: {
|
|
||||||
get(): boolean { return this.$props.dial.inet4_bind_address != undefined },
|
|
||||||
set(v:boolean) { v ? this.$props.dial.inet4_bind_address = '' : delete this.$props.dial.inet4_bind_address }
|
|
||||||
},
|
|
||||||
optionIPV6: {
|
|
||||||
get(): boolean { return this.$props.dial.inet6_bind_address != undefined },
|
|
||||||
set(v:boolean) { v ? this.$props.dial.inet6_bind_address = '' : delete this.$props.dial.inet6_bind_address }
|
|
||||||
},
|
|
||||||
optionRM: {
|
|
||||||
get(): boolean { return this.$props.dial.routing_mark != undefined },
|
|
||||||
set(v:boolean) { v ? this.$props.dial.routing_mark = 0 : delete this.$props.dial.routing_mark }
|
|
||||||
},
|
|
||||||
optionRA: {
|
|
||||||
get(): boolean { return this.$props.dial.reuse_addr != undefined },
|
|
||||||
set(v:boolean) { v ? this.$props.dial.reuse_addr = true : delete this.$props.dial.reuse_addr }
|
|
||||||
},
|
|
||||||
optionTCP: {
|
|
||||||
get(): boolean {
|
|
||||||
return this.$props.dial.tcp_fast_open != undefined &&
|
|
||||||
this.$props.dial.tcp_multi_path != undefined
|
|
||||||
},
|
|
||||||
set(v:boolean) {
|
|
||||||
if (v) {
|
|
||||||
this.$props.dial.tcp_fast_open = false
|
|
||||||
this.$props.dial.tcp_multi_path = false
|
|
||||||
} else {
|
|
||||||
delete this.$props.dial.tcp_fast_open
|
|
||||||
delete this.$props.dial.tcp_multi_path
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
optionUDP: {
|
|
||||||
get(): boolean { return this.$props.dial.udp_fragment != undefined },
|
|
||||||
set(v:boolean) { v ? this.$props.dial.udp_fragment = true : delete this.$props.dial.udp_fragment }
|
|
||||||
},
|
|
||||||
optionCT: {
|
|
||||||
get(): boolean { return this.$props.dial.connect_timeout != undefined },
|
|
||||||
set(v:boolean) { v ? this.$props.dial.connect_timeout = '5s' : delete this.$props.dial.connect_timeout }
|
|
||||||
},
|
|
||||||
optionDS: {
|
|
||||||
get(): boolean { return this.$props.dial.domain_strategy != undefined },
|
|
||||||
set(v:boolean) {
|
|
||||||
if (v) {
|
|
||||||
this.$props.dial.domain_strategy = 'prefer_ipv4'
|
|
||||||
this.$props.dial.fallback_delay = '300ms'
|
|
||||||
} else {
|
|
||||||
delete this.$props.dial.domain_strategy
|
|
||||||
delete this.$props.dial.fallback_delay
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
@@ -1,75 +0,0 @@
|
|||||||
<template>
|
|
||||||
<v-card :subtitle="$t('in.multiplex')">
|
|
||||||
<v-row>
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<v-switch color="primary" label="Enable Multiplex" v-model="muxEnable" hide-details></v-switch>
|
|
||||||
</v-col>
|
|
||||||
<v-col cols="12" sm="6" md="4" v-if="mux.enabled">
|
|
||||||
<v-switch color="primary" label="Reject Non-Padded" v-model="mux.padding" hide-details></v-switch>
|
|
||||||
</v-col>
|
|
||||||
<v-col cols="12" sm="6" md="4" v-if="mux.enabled">
|
|
||||||
<v-switch color="primary" label="Enable Brutal" v-model="burtalEnable" hide-details></v-switch>
|
|
||||||
</v-col>
|
|
||||||
</v-row>
|
|
||||||
<v-row v-if="mux.brutal?.enabled">
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<v-text-field
|
|
||||||
label="Uplink Bandwidth"
|
|
||||||
hide-details
|
|
||||||
type="number"
|
|
||||||
suffix="Mbps"
|
|
||||||
v-model.number="up_mbps">
|
|
||||||
</v-text-field>
|
|
||||||
</v-col>
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<v-text-field
|
|
||||||
label="Downlink Bandwidth"
|
|
||||||
hide-details
|
|
||||||
type="number"
|
|
||||||
suffix="Mbps"
|
|
||||||
min="0"
|
|
||||||
v-model.number="down_mbps">
|
|
||||||
</v-text-field>
|
|
||||||
</v-col>
|
|
||||||
</v-row>
|
|
||||||
</v-card>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script lang="ts">
|
|
||||||
import { iMultiplex } from '@/types/inMultiplex'
|
|
||||||
export default {
|
|
||||||
props: ['inbound'],
|
|
||||||
data() {
|
|
||||||
return {}
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
mux(): iMultiplex {
|
|
||||||
return <iMultiplex> this.$props.inbound.multiplex
|
|
||||||
},
|
|
||||||
muxEnable: {
|
|
||||||
get(): boolean { return this.$props.inbound.multiplex ? this.mux.enabled : false },
|
|
||||||
set(newValue:boolean) { this.$props.inbound.multiplex = newValue ? { enabled: newValue } : {} }
|
|
||||||
},
|
|
||||||
burtalEnable: {
|
|
||||||
get(): boolean { return this.mux.brutal ? this.mux.brutal.enabled : false },
|
|
||||||
set(newValue:boolean) { this.mux.brutal = { enabled: newValue, up_mbps: 100, down_mbps: 100 } }
|
|
||||||
},
|
|
||||||
down_mbps: {
|
|
||||||
get() { return this.mux.brutal && this.mux.brutal.down_mbps ? this.mux.brutal.down_mbps : 0 },
|
|
||||||
set(newValue:any) {
|
|
||||||
if (this.mux.brutal){
|
|
||||||
this.mux.brutal.down_mbps = newValue.length != 0 ? newValue : 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
up_mbps: {
|
|
||||||
get() { return this.mux.brutal && this.mux.brutal.up_mbps ? this.mux.brutal.up_mbps : 0 },
|
|
||||||
set(newValue:any) {
|
|
||||||
if (this.mux.brutal){
|
|
||||||
this.mux.brutal.up_mbps = newValue.length != 0 ? newValue : 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
@@ -1,214 +0,0 @@
|
|||||||
<template>
|
|
||||||
<v-card :subtitle="$t('in.tls')">
|
|
||||||
<v-row v-if="tlsOptional">
|
|
||||||
<v-col cols="auto">
|
|
||||||
<v-switch color="primary" :label="$t('tls.enable')" v-model="tlsEnable" hide-details></v-switch>
|
|
||||||
</v-col>
|
|
||||||
</v-row>
|
|
||||||
<template v-if="tls.enabled">
|
|
||||||
<v-row>
|
|
||||||
<v-col cols="auto">
|
|
||||||
<v-btn-toggle v-model="usePath"
|
|
||||||
class="rounded-xl"
|
|
||||||
density="compact"
|
|
||||||
variant="outlined"
|
|
||||||
shaped
|
|
||||||
mandatory>
|
|
||||||
<v-btn
|
|
||||||
@click="tls.key=undefined; tls.certificate=undefined"
|
|
||||||
>{{ $t('tls.usePath') }}</v-btn>
|
|
||||||
<v-btn
|
|
||||||
@click="tls.key_path=undefined; tls.certificate_path=undefined"
|
|
||||||
>{{ $t('tls.useText') }}</v-btn>
|
|
||||||
</v-btn-toggle>
|
|
||||||
</v-col>
|
|
||||||
</v-row>
|
|
||||||
<v-row v-if="usePath == 0">
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<v-text-field
|
|
||||||
:label="$t('tls.certPath')"
|
|
||||||
hide-details
|
|
||||||
v-model="tls.certificate_path">
|
|
||||||
</v-text-field>
|
|
||||||
</v-col>
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<v-text-field
|
|
||||||
:label="$t('tls.keyPath')"
|
|
||||||
hide-details
|
|
||||||
v-model="tls.key_path">
|
|
||||||
</v-text-field>
|
|
||||||
</v-col>
|
|
||||||
</v-row>
|
|
||||||
<v-row v-else>
|
|
||||||
<v-col cols="12" sm="6">
|
|
||||||
<v-textarea
|
|
||||||
:label="$t('tls.cert')"
|
|
||||||
hide-details
|
|
||||||
v-model="certText">
|
|
||||||
</v-textarea>
|
|
||||||
</v-col>
|
|
||||||
<v-col cols="12" sm="6">
|
|
||||||
<v-textarea
|
|
||||||
:label="$t('tls.key')"
|
|
||||||
hide-details
|
|
||||||
v-model="keyText">
|
|
||||||
</v-textarea>
|
|
||||||
</v-col>
|
|
||||||
</v-row>
|
|
||||||
<v-row>
|
|
||||||
<v-col cols="12" sm="6" md="4" v-if="tls.server_name != undefined">
|
|
||||||
<v-text-field
|
|
||||||
label="SNI"
|
|
||||||
hide-details
|
|
||||||
v-model="tls.server_name">
|
|
||||||
</v-text-field>
|
|
||||||
</v-col>
|
|
||||||
<v-col cols="12" sm="6" md="4" v-if="tls.alpn">
|
|
||||||
<v-select
|
|
||||||
hide-details
|
|
||||||
label="ALPN"
|
|
||||||
multiple
|
|
||||||
:items="alpn"
|
|
||||||
v-model="tls.alpn">
|
|
||||||
</v-select>
|
|
||||||
</v-col>
|
|
||||||
</v-row>
|
|
||||||
<v-row>
|
|
||||||
<v-col cols="12" sm="6" md="4" v-if="tls.min_version">
|
|
||||||
<v-select
|
|
||||||
hide-details
|
|
||||||
label="Minimum Version"
|
|
||||||
:items="tlsVersions"
|
|
||||||
v-model="tls.min_version">
|
|
||||||
</v-select>
|
|
||||||
</v-col>
|
|
||||||
<v-col cols="12" sm="6" md="4" v-if="tls.max_version">
|
|
||||||
<v-select
|
|
||||||
hide-details
|
|
||||||
label="Maximum Version"
|
|
||||||
:items="tlsVersions"
|
|
||||||
v-model="tls.max_version">
|
|
||||||
</v-select>
|
|
||||||
</v-col>
|
|
||||||
</v-row>
|
|
||||||
<v-row>
|
|
||||||
<v-col cols="12" md="8" v-if="tls.cipher_suites != undefined">
|
|
||||||
<v-select
|
|
||||||
hide-details
|
|
||||||
label="Cipher Suites"
|
|
||||||
multiple
|
|
||||||
:items="cipher_suites"
|
|
||||||
v-model="tls.cipher_suites">
|
|
||||||
</v-select>
|
|
||||||
</v-col>
|
|
||||||
</v-row>
|
|
||||||
</template>
|
|
||||||
<v-card-actions>
|
|
||||||
<v-spacer></v-spacer>
|
|
||||||
<v-menu v-model="menu" :close-on-content-click="false" location="start" v-if="tls.enabled">
|
|
||||||
<template v-slot:activator="{ props }">
|
|
||||||
<v-btn v-bind="props" hide-details>TLS Options</v-btn>
|
|
||||||
</template>
|
|
||||||
<v-card>
|
|
||||||
<v-list>
|
|
||||||
<v-list-item>
|
|
||||||
<v-switch v-model="optionSNI" color="primary" label="SNI" hide-details></v-switch>
|
|
||||||
</v-list-item>
|
|
||||||
<v-list-item>
|
|
||||||
<v-switch v-model="optionALPN" color="primary" label="ALPN" hide-details></v-switch>
|
|
||||||
</v-list-item>
|
|
||||||
<v-list-item>
|
|
||||||
<v-switch v-model="optionMinV" color="primary" label="Min Version" hide-details></v-switch>
|
|
||||||
</v-list-item>
|
|
||||||
<v-list-item>
|
|
||||||
<v-switch v-model="optionMaxV" color="primary" label="Max Version" hide-details></v-switch>
|
|
||||||
</v-list-item>
|
|
||||||
<v-list-item>
|
|
||||||
<v-switch v-model="optionCS" color="primary" label="Cipher Suites" hide-details></v-switch>
|
|
||||||
</v-list-item>
|
|
||||||
</v-list>
|
|
||||||
</v-card>
|
|
||||||
</v-menu>
|
|
||||||
</v-card-actions>
|
|
||||||
</v-card>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script lang="ts">
|
|
||||||
import { iTls, defaultInTls } from '@/types/inTls'
|
|
||||||
export default {
|
|
||||||
props: ['inbound'],
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
menu: false,
|
|
||||||
usePath: 0,
|
|
||||||
defaults: defaultInTls,
|
|
||||||
alpn: [
|
|
||||||
{ title: "H3", value: 'h3' },
|
|
||||||
{ title: "H2", value: 'h2' },
|
|
||||||
{ title: "Http/1.1", value: 'http/1.1' },
|
|
||||||
],
|
|
||||||
tlsVersions: [ '1.0', '1.1', '1.2', '1.3' ],
|
|
||||||
cipher_suites: [
|
|
||||||
{ title: "Automatic", value: "" },
|
|
||||||
{ title: "RSA-AES128-CBC-SHA", value: "TLS_RSA_WITH_AES_128_CBC_SHA" },
|
|
||||||
{ title: "RSA-AES256-CBC-SHA", value: "TLS_RSA_WITH_AES_256_CBC_SHA" },
|
|
||||||
{ title: "RSA-AES128-GCM-SHA256", value: "TLS_RSA_WITH_AES_128_GCM_SHA256" },
|
|
||||||
{ title: "RSA-AES256-GCM-SHA384", value: "TLS_RSA_WITH_AES_256_GCM_SHA384" },
|
|
||||||
{ title: "AES128-GCM-SHA256", value: "TLS_AES_128_GCM_SHA256" },
|
|
||||||
{ title: "AES256-GCM-SHA384", value: "TLS_AES_256_GCM_SHA384" },
|
|
||||||
{ title: "CHACHA20-POLY1305-SHA256", value: "TLS_CHACHA20_POLY1305_SHA256" },
|
|
||||||
{ title: "ECDHE-ECDSA-AES128-CBC-SHA", value: "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA" },
|
|
||||||
{ title: "ECDHE-ECDSA-AES256-CBC-SHA", value: "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA" },
|
|
||||||
{ title: "ECDHE-RSA-AES128-CBC-SHA", value: "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA" },
|
|
||||||
{ title: "ECDHE-RSA-AES256-CBC-SHA", value: "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA" },
|
|
||||||
{ title: "ECDHE-ECDSA-AES128-GCM-SHA256", value: "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256" },
|
|
||||||
{ title: "ECDHE-ECDSA-AES256-GCM-SHA384", value: "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384" },
|
|
||||||
{ title: "ECDHE-RSA-AES128-GCM-SHA256", value: "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256" },
|
|
||||||
{ title: "ECDHE-RSA-AES256-GCM-SHA384", value: "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384" },
|
|
||||||
{ title: "ECDHE-ECDSA-CHACHA20-POLY1305-SHA256", value: "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256" },
|
|
||||||
{ title: "ECDHE-RSA-CHACHA20-POLY1305-SHA256", value: "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256" }
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
tls(): iTls {
|
|
||||||
return <iTls> this.$props.inbound.tls
|
|
||||||
},
|
|
||||||
tlsEnable: {
|
|
||||||
get() { return Object.hasOwn(this.$props.inbound.tls, 'enabled') ? this.tls.enabled : false },
|
|
||||||
set(newValue: boolean) { this.$props.inbound.tls = newValue ? { enabled: true } : {} }
|
|
||||||
},
|
|
||||||
tlsOptional(): boolean {
|
|
||||||
return !['hysteria','hysteria2','tuic','naive'].includes(this.$props.inbound.type)
|
|
||||||
},
|
|
||||||
certText: {
|
|
||||||
get(): string { return this.tls.certificate ? this.tls.certificate.join('\n') : '' },
|
|
||||||
set(newValue:string) { this.tls.certificate = newValue.split('\n') }
|
|
||||||
},
|
|
||||||
keyText: {
|
|
||||||
get(): string { return this.tls.key ? this.tls.key.join('\n') : '' },
|
|
||||||
set(newValue:string) { this.tls.key = newValue.split('\n') }
|
|
||||||
},
|
|
||||||
optionSNI: {
|
|
||||||
get(): boolean { return this.tls.server_name != undefined },
|
|
||||||
set(v:boolean) { this.$props.inbound.tls.server_name = v ? '' : undefined }
|
|
||||||
},
|
|
||||||
optionALPN: {
|
|
||||||
get(): boolean { return this.tls.alpn != undefined },
|
|
||||||
set(v:boolean) { this.$props.inbound.tls.alpn = v ? defaultInTls.alpn : undefined }
|
|
||||||
},
|
|
||||||
optionMinV: {
|
|
||||||
get(): boolean { return this.tls.min_version != undefined },
|
|
||||||
set(v:boolean) { this.$props.inbound.tls.min_version = v ? defaultInTls.min_version : undefined }
|
|
||||||
},
|
|
||||||
optionMaxV: {
|
|
||||||
get(): boolean { return this.tls.max_version != undefined },
|
|
||||||
set(v:boolean) { this.$props.inbound.tls.max_version = v ? defaultInTls.max_version : undefined }
|
|
||||||
},
|
|
||||||
optionCS: {
|
|
||||||
get(): boolean { return this.tls.cipher_suites != undefined },
|
|
||||||
set(v:boolean) { this.$props.inbound.tls.cipher_suites = v ? defaultInTls.cipher_suites : undefined }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
@@ -1,154 +0,0 @@
|
|||||||
<template>
|
|
||||||
<v-card subtitle="Listen">
|
|
||||||
<v-row>
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<v-text-field
|
|
||||||
:label="$t('in.addr')"
|
|
||||||
hide-details
|
|
||||||
required
|
|
||||||
v-model="inbound.listen">
|
|
||||||
</v-text-field>
|
|
||||||
</v-col>
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<v-text-field
|
|
||||||
:label="$t('in.port')"
|
|
||||||
hide-details
|
|
||||||
type="number"
|
|
||||||
required
|
|
||||||
v-model.number="inbound.listen_port"></v-text-field>
|
|
||||||
</v-col>
|
|
||||||
</v-row>
|
|
||||||
<v-row>
|
|
||||||
<v-col cols="12" sm="6" md="4" v-if="optionDetour">
|
|
||||||
<v-text-field
|
|
||||||
label="Forward to Inbound tag"
|
|
||||||
hide-details
|
|
||||||
v-model="inbound.detour"></v-text-field>
|
|
||||||
</v-col>
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<v-switch v-model="inbound.sniff" color="primary" :label="$t('in.sniffing')" hide-details></v-switch>
|
|
||||||
</v-col>
|
|
||||||
</v-row>
|
|
||||||
<v-row v-if="inbound.sniff">
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<v-switch v-model="inbound.sniff_override_destination" color="primary" label="Override Sniffed Domain" hide-details></v-switch>
|
|
||||||
</v-col>
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<v-text-field
|
|
||||||
label="Sniffing Timeout"
|
|
||||||
hide-details
|
|
||||||
type="number"
|
|
||||||
min="50"
|
|
||||||
step="50"
|
|
||||||
suffix="ms"
|
|
||||||
v-model.number="sniffTimeout"></v-text-field>
|
|
||||||
</v-col>
|
|
||||||
</v-row>
|
|
||||||
<v-row v-if="optionTCP">
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<v-switch v-model="inbound.tcp_fast_open" color="primary" label="TCP Fast Open" hide-details></v-switch>
|
|
||||||
</v-col>
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<v-switch v-model="inbound.tcp_multi_path" color="primary" label="TCP Multi Path" hide-details></v-switch>
|
|
||||||
</v-col>
|
|
||||||
</v-row>
|
|
||||||
<v-row v-if="optionUDP">
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<v-switch v-model="inbound.udp_fragment" color="primary" label="UDP Fragment" hide-details></v-switch>
|
|
||||||
</v-col>
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<v-text-field
|
|
||||||
label="UDP NAT expiration"
|
|
||||||
hide-details
|
|
||||||
type="number"
|
|
||||||
min="1"
|
|
||||||
suffix="Min"
|
|
||||||
v-model.number="udpTimeout"></v-text-field>
|
|
||||||
</v-col>
|
|
||||||
</v-row>
|
|
||||||
<v-row v-if="optionDS">
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<v-select
|
|
||||||
hide-details
|
|
||||||
width="100"
|
|
||||||
label="Domain to IP Strategy"
|
|
||||||
:items="['prefer_ipv4','prefer_ipv6','ipv4_only','ipv6_only']"
|
|
||||||
v-model="inbound.domain_strategy">
|
|
||||||
</v-select>
|
|
||||||
</v-col>
|
|
||||||
</v-row>
|
|
||||||
<v-card-actions class="pt-0">
|
|
||||||
<v-spacer></v-spacer>
|
|
||||||
<v-menu v-model="menu" :close-on-content-click="false" location="start">
|
|
||||||
<template v-slot:activator="{ props }">
|
|
||||||
<v-btn v-bind="props" hide-details>Listen Options</v-btn>
|
|
||||||
</template>
|
|
||||||
<v-card>
|
|
||||||
<v-list>
|
|
||||||
<v-list-item>
|
|
||||||
<v-switch v-model="optionTCP" color="primary" label="TCP Options" hide-details></v-switch>
|
|
||||||
</v-list-item>
|
|
||||||
<v-list-item>
|
|
||||||
<v-switch v-model="optionUDP" color="primary" label="UDP Options" hide-details></v-switch>
|
|
||||||
</v-list-item>
|
|
||||||
<v-list-item>
|
|
||||||
<v-switch v-model="optionDetour" color="primary" label="Detour" hide-details></v-switch>
|
|
||||||
</v-list-item>
|
|
||||||
<v-list-item>
|
|
||||||
<v-switch v-model="optionDS" color="primary" label="Domain Strategy" hide-details></v-switch>
|
|
||||||
</v-list-item>
|
|
||||||
</v-list>
|
|
||||||
</v-card>
|
|
||||||
</v-menu>
|
|
||||||
</v-card-actions>
|
|
||||||
</v-card>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script lang="ts">
|
|
||||||
export default {
|
|
||||||
props: ['inbound'],
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
menu: false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
udpTimeout: {
|
|
||||||
get() { return this.$props.inbound.udp_timeout ? parseInt(this.$props.inbound.udp_timeout.replace('m','')) : 5 },
|
|
||||||
set(newValue:number) { this.$props.inbound.udp_timeout = newValue > 0 ? newValue + 'm' : '5m' }
|
|
||||||
},
|
|
||||||
sniffTimeout: {
|
|
||||||
get() { return this.$props.inbound.sniff_timeout ? parseInt(this.$props.inbound.sniff_timeout.replace('ms','')) : 300 },
|
|
||||||
set(newValue:number) { this.$props.inbound.sniff_timeout = newValue > 0 ? newValue + 'ms' : '300ms' }
|
|
||||||
},
|
|
||||||
optionTCP: {
|
|
||||||
get(): boolean {
|
|
||||||
return this.$props.inbound.tcp_fast_open != undefined &&
|
|
||||||
this.$props.inbound.tcp_multi_path != undefined
|
|
||||||
},
|
|
||||||
set(v:boolean) {
|
|
||||||
this.$props.inbound.tcp_fast_open = v ? false : undefined
|
|
||||||
this.$props.inbound.tcp_multi_path = v ? false : undefined
|
|
||||||
}
|
|
||||||
},
|
|
||||||
optionUDP: {
|
|
||||||
get(): boolean {
|
|
||||||
return this.$props.inbound.udp_fragment != undefined &&
|
|
||||||
this.$props.inbound.udp_timeout != undefined
|
|
||||||
},
|
|
||||||
set(v:boolean) {
|
|
||||||
this.$props.inbound.udp_fragment = v ? false : undefined
|
|
||||||
this.$props.inbound.udp_timeout = v ? false : undefined
|
|
||||||
}
|
|
||||||
},
|
|
||||||
optionDetour: {
|
|
||||||
get(): boolean { return this.$props.inbound.detour != undefined },
|
|
||||||
set(v:boolean) { this.$props.inbound.detour = v ? '' : undefined }
|
|
||||||
},
|
|
||||||
optionDS: {
|
|
||||||
get(): boolean { return this.$props.inbound.domain_strategy != undefined },
|
|
||||||
set(v:boolean) { this.$props.inbound.domain_strategy = v ? 'prefer_ipv4' : undefined }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
@@ -1,218 +0,0 @@
|
|||||||
<template>
|
|
||||||
<v-container class="fill-height">
|
|
||||||
<v-responsive :class="reloadItems.length>0 ? 'fill-height text-center' : 'align-center'" >
|
|
||||||
<v-row class="d-flex align-center justify-center">
|
|
||||||
<v-col cols="auto">
|
|
||||||
<v-img src="@/assets/logo.svg" :width="reloadItems.length>0 ? 100 : 200"></v-img>
|
|
||||||
</v-col>
|
|
||||||
</v-row>
|
|
||||||
<v-row class="d-flex align-center justify-center">
|
|
||||||
<v-col cols="auto">
|
|
||||||
<v-dialog v-model="menu" :close-on-content-click="false" transition="scale-transition" max-width="800">
|
|
||||||
<template v-slot:activator="{ props }">
|
|
||||||
<v-btn v-bind="props" variant="tonal">{{ $t('main.tiles') }} <v-icon icon="mdi-star-plus" /></v-btn>
|
|
||||||
</template>
|
|
||||||
<v-card rounded="xl">
|
|
||||||
<v-card-title>
|
|
||||||
<v-row>
|
|
||||||
<v-col>
|
|
||||||
{{ $t('main.tiles') }}
|
|
||||||
</v-col>
|
|
||||||
<v-spacer></v-spacer>
|
|
||||||
<v-col cols="auto"><v-icon icon="mdi-close" @click="menu = false"></v-icon></v-col>
|
|
||||||
</v-row>
|
|
||||||
</v-card-title>
|
|
||||||
<v-divider></v-divider>
|
|
||||||
<v-row>
|
|
||||||
<v-col cols="12" sm="6" md="4" v-for="items in menuItems">
|
|
||||||
<v-card variant="flat" :title="items.title">
|
|
||||||
<v-list v-for="item in items.value">
|
|
||||||
<v-list-item>
|
|
||||||
<v-switch
|
|
||||||
v-model="reloadItems"
|
|
||||||
:value="item.value"
|
|
||||||
color="primary"
|
|
||||||
:label="item.title"
|
|
||||||
hide-details></v-switch>
|
|
||||||
</v-list-item>
|
|
||||||
</v-list>
|
|
||||||
</v-card>
|
|
||||||
</v-col>
|
|
||||||
</v-row>
|
|
||||||
</v-card>
|
|
||||||
</v-dialog>
|
|
||||||
</v-col>
|
|
||||||
</v-row>
|
|
||||||
<v-row>
|
|
||||||
<v-col cols="12" sm="6" md="3" v-for="i in reloadItems" :key="i">
|
|
||||||
<v-card class="rounded-lg" variant="outlined" height="200px"
|
|
||||||
:title="menuItems.flatMap(cat => cat.value).find(m => m.value == i)?.title">
|
|
||||||
<v-card-text style="padding: 0 16px;" align="center" justify="center">
|
|
||||||
<Gauge :tilesData="tilesData" :type="i" v-if="i.charAt(0) == 'g'" />
|
|
||||||
<History :tilesData="tilesData" :type="i" v-if="i.charAt(0) == 'h'" />
|
|
||||||
<template v-if="i == 'i-sys'">
|
|
||||||
<v-row>
|
|
||||||
<v-col cols="3">{{ $t('main.info.host') }}</v-col>
|
|
||||||
<v-col cols="9" style="text-wrap: nowrap; overflow: hidden">{{ tilesData.sys?.hostName }}</v-col>
|
|
||||||
<v-col cols="3">{{ $t('main.info.cpu') }}</v-col>
|
|
||||||
<v-col cols="9">
|
|
||||||
<v-chip density="compact" variant="flat">
|
|
||||||
<v-tooltip activator="parent" location="top" style="direction: ltr;">
|
|
||||||
{{ tilesData.sys?.cpuType }}
|
|
||||||
</v-tooltip>
|
|
||||||
{{ tilesData.sys?.cpuCount }} {{ $t('main.info.core') }}
|
|
||||||
</v-chip>
|
|
||||||
</v-col>
|
|
||||||
<v-col cols="3">IP</v-col>
|
|
||||||
<v-col cols="9">
|
|
||||||
<v-chip density="compact" color="primary" variant="flat" v-if="tilesData.sys?.ipv4?.length>0">
|
|
||||||
<v-tooltip activator="parent" location="top" style="direction: ltr;">
|
|
||||||
<span v-html="tilesData.sys?.ipv4?.join('<br />')"></span>
|
|
||||||
</v-tooltip>
|
|
||||||
IPv4
|
|
||||||
</v-chip>
|
|
||||||
<v-chip density="compact" color="primary" variant="flat" v-if="tilesData.sys?.ipv6?.length>0">
|
|
||||||
<v-tooltip activator="parent" location="top" style="direction: ltr;">
|
|
||||||
<span v-html="tilesData.sys?.ipv6?.join('<br />')"></span>
|
|
||||||
</v-tooltip>
|
|
||||||
IPv6
|
|
||||||
</v-chip>
|
|
||||||
</v-col>
|
|
||||||
<v-col cols="3">S-UI</v-col>
|
|
||||||
<v-col cols="9">
|
|
||||||
<v-chip density="compact" color="primary" variant="flat">
|
|
||||||
<v-tooltip activator="parent" location="top">
|
|
||||||
{{ $t('main.info.threads') }}: {{ tilesData.sys?.appThreads }}<br />
|
|
||||||
{{ $t('main.info.memory') }}: {{ HumanReadable.sizeFormat(tilesData.sys?.appMem) }}
|
|
||||||
</v-tooltip>
|
|
||||||
v{{ tilesData.sys?.appVersion }}
|
|
||||||
</v-chip>
|
|
||||||
</v-col>
|
|
||||||
<v-col cols="3">{{ $t('main.info.uptime') }}</v-col>
|
|
||||||
<v-col cols="9">{{ HumanReadable.formatSecond(tilesData.uptime) }}</v-col>
|
|
||||||
</v-row>
|
|
||||||
</template>
|
|
||||||
<template v-if="i == 'i-sbd'">
|
|
||||||
<v-row>
|
|
||||||
<v-col cols="4">{{ $t('main.info.running') }}</v-col>
|
|
||||||
<v-col cols="8">
|
|
||||||
<v-chip density="compact" color="success" variant="flat" v-if="tilesData.sbd?.running">{{ $t('yes') }}</v-chip>
|
|
||||||
<v-chip density="compact" color="error" variant="flat" v-else>{{ $t('no') }}</v-chip>
|
|
||||||
</v-col>
|
|
||||||
<v-col cols="4">{{ $t('main.info.memory') }}</v-col>
|
|
||||||
<v-col cols="8">
|
|
||||||
<v-chip density="compact" color="primary" variant="flat" v-if="tilesData.sbd?.stats?.Alloc">
|
|
||||||
{{ HumanReadable.sizeFormat(tilesData.sbd?.stats?.Alloc) }}
|
|
||||||
</v-chip>
|
|
||||||
</v-col>
|
|
||||||
<v-col cols="4">{{ $t('main.info.threads') }}</v-col>
|
|
||||||
<v-col cols="8">
|
|
||||||
<v-chip density="compact" color="primary" variant="flat" v-if="tilesData.sbd?.stats?.NumGoroutine">
|
|
||||||
{{ tilesData.sbd?.stats?.NumGoroutine }}
|
|
||||||
</v-chip>
|
|
||||||
</v-col>
|
|
||||||
<v-col cols="4">{{ $t('main.info.uptime') }}</v-col>
|
|
||||||
<v-col cols="8">{{ HumanReadable.formatSecond(tilesData.sbd?.stats?.Uptime) }}</v-col>
|
|
||||||
<v-col cols="4">{{ $t('online') }}</v-col>
|
|
||||||
<v-col cols="8">
|
|
||||||
<template v-if="tilesData.sbd?.running">
|
|
||||||
<v-chip density="compact" color="primary" variant="flat" v-if="Data().onlines.user">
|
|
||||||
<v-tooltip activator="parent" location="top" :text="$t('pages.clients')" />
|
|
||||||
{{ Data().onlines.user?.length }}
|
|
||||||
</v-chip>
|
|
||||||
<v-chip density="compact" color="success" variant="flat" v-if="Data().onlines.inbound">
|
|
||||||
<v-tooltip activator="parent" location="top" :text="$t('pages.inbounds')" />
|
|
||||||
{{ Data().onlines.inbound?.length }}
|
|
||||||
</v-chip>
|
|
||||||
<v-chip density="compact" color="info" variant="flat" v-if="Data().onlines.outbound">
|
|
||||||
<v-tooltip activator="parent" location="top" :text="$t('pages.outbounds')" />
|
|
||||||
{{ Data().onlines.outbound?.length }}
|
|
||||||
</v-chip>
|
|
||||||
</template>
|
|
||||||
</v-col>
|
|
||||||
</v-row>
|
|
||||||
</template>
|
|
||||||
</v-card-text>
|
|
||||||
</v-card>
|
|
||||||
</v-col>
|
|
||||||
</v-row>
|
|
||||||
</v-responsive>
|
|
||||||
</v-container>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script lang="ts" setup>
|
|
||||||
import HttpUtils from '@/plugins/httputil'
|
|
||||||
import { HumanReadable } from '@/plugins/utils'
|
|
||||||
import Data from '@/store/modules/data'
|
|
||||||
import Gauge from '@/components/tiles/Gauge.vue'
|
|
||||||
import History from '@/components/tiles/History.vue'
|
|
||||||
import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
|
|
||||||
import { i18n } from '@/locales'
|
|
||||||
|
|
||||||
const menu = ref(false)
|
|
||||||
const menuItems = [
|
|
||||||
{ title: i18n.global.t('main.gauges'), value: [
|
|
||||||
{ title: i18n.global.t('main.gauge.cpu'), value: "g-cpu" },
|
|
||||||
{ title: i18n.global.t('main.gauge.mem'), value: "g-mem" },
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{ title: i18n.global.t('main.charts'), value: [
|
|
||||||
{ title: i18n.global.t('main.chart.cpu'), value: "h-cpu" },
|
|
||||||
{ title: i18n.global.t('main.chart.mem'), value: "h-mem" },
|
|
||||||
{ title: i18n.global.t('main.chart.net'), value: "h-net" },
|
|
||||||
{ title: i18n.global.t('main.chart.pnet'), value: "hp-net" },
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{ title: i18n.global.t('main.infos'), value: [
|
|
||||||
{ title: i18n.global.t('main.info.sys'), value: "i-sys" },
|
|
||||||
{ title: i18n.global.t('main.info.sbd'), value: "i-sbd" },
|
|
||||||
]
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
const tilesData = ref(<any>{})
|
|
||||||
|
|
||||||
const reloadItems = computed({
|
|
||||||
get() { return Data().reloadItems },
|
|
||||||
set(v:string[]) {
|
|
||||||
if (Data().reloadItems.length == 0 && v.length>0) startTimer()
|
|
||||||
if (Data().reloadItems.length > 0 && v.length == 0) stopTimer()
|
|
||||||
Data().reloadItems = v
|
|
||||||
v.length>0 ? localStorage.setItem("reloadItems",v.join(',')) : localStorage.removeItem("reloadItems")
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
const reloadData = async () => {
|
|
||||||
const request = [...new Set(reloadItems.value.map(r => r.split('-')[1]))]
|
|
||||||
const data = await HttpUtils.get('api/status',{ r: request.join(',')})
|
|
||||||
if (data.success) {
|
|
||||||
tilesData.value = data.obj
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let intervalId: NodeJS.Timeout | null = null
|
|
||||||
|
|
||||||
const startTimer = () => {
|
|
||||||
intervalId = setInterval(() => {
|
|
||||||
reloadData()
|
|
||||||
}, 2000)
|
|
||||||
}
|
|
||||||
|
|
||||||
const stopTimer = () => {
|
|
||||||
if (intervalId) {
|
|
||||||
clearInterval(intervalId);
|
|
||||||
intervalId = null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onMounted(() => {
|
|
||||||
if (Data().reloadItems.length != 0) {
|
|
||||||
reloadData()
|
|
||||||
startTimer()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
onBeforeUnmount(() => {
|
|
||||||
stopTimer()
|
|
||||||
})
|
|
||||||
</script>
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
<template>
|
|
||||||
<v-select
|
|
||||||
hide-details
|
|
||||||
:label="$t('network')"
|
|
||||||
:items="networks"
|
|
||||||
v-model="Network">
|
|
||||||
</v-select>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script lang="ts">
|
|
||||||
export default {
|
|
||||||
props: ['inbound'],
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
networks: [
|
|
||||||
{ title: "TCP/UDP", value: '' },
|
|
||||||
{ title: "TCP", value: 'tcp' },
|
|
||||||
{ title: "UDP", value: 'udp' },
|
|
||||||
],
|
|
||||||
}
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
Network: {
|
|
||||||
get():string { return this.$props.inbound.network?? '' },
|
|
||||||
set(v:string) { this.$props.inbound.network = v != '' ? v : undefined }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
<template>
|
|
||||||
<v-card :subtitle="$t('in.transport')">
|
|
||||||
<v-row>
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<v-switch color="primary" :label="$t('transport.enable')" v-model="tpEnable" hide-details></v-switch>
|
|
||||||
</v-col>
|
|
||||||
<v-col cols="12" sm="6" md="4" v-if="tpEnable">
|
|
||||||
<v-select
|
|
||||||
hide-details
|
|
||||||
width="100"
|
|
||||||
:label="$t('type')"
|
|
||||||
:items="Object.keys(trspTypes).map((key,index) => ({title: key, value: Object.values(trspTypes)[index]}))"
|
|
||||||
v-model="transportType">
|
|
||||||
</v-select>
|
|
||||||
</v-col>
|
|
||||||
</v-row>
|
|
||||||
<Http v-if="Transport.type == trspTypes.HTTP" :transport="Transport" />
|
|
||||||
<WebSocket v-if="Transport.type == trspTypes.WebSocket" :transport="Transport" />
|
|
||||||
<GRPC v-if="Transport.type == trspTypes.gRPC" :transport="Transport" />
|
|
||||||
<HttpUpgrade v-if="Transport.type == trspTypes.HTTPUpgrade" :transport="Transport" />
|
|
||||||
</v-card>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script lang="ts">
|
|
||||||
import { TrspTypes, Transport } from '@/types/transport'
|
|
||||||
import Http from './transports/Http.vue'
|
|
||||||
import WebSocket from './transports/WebSocket.vue'
|
|
||||||
import GRPC from './transports/gRPC.vue'
|
|
||||||
import HttpUpgrade from './transports/HttpUpgrade.vue'
|
|
||||||
export default {
|
|
||||||
props: ['inbound'],
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
trspTypes: TrspTypes
|
|
||||||
}
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
Transport() {
|
|
||||||
return <Transport>this.$props.inbound.transport
|
|
||||||
},
|
|
||||||
tpEnable: {
|
|
||||||
get() { return Object.hasOwn(this.$props.inbound.transport, 'type') },
|
|
||||||
set(newValue: boolean) { this.$props.inbound.transport = newValue ? { type: 'http' } : {} }
|
|
||||||
},
|
|
||||||
transportType: {
|
|
||||||
get() { return this.Transport.type },
|
|
||||||
set(newValue: string) { this.$props.inbound.transport = { type: newValue } }
|
|
||||||
}
|
|
||||||
},
|
|
||||||
components: { Http, WebSocket, GRPC, HttpUpgrade }
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
<template>
|
|
||||||
<v-card subtitle="Clients">
|
|
||||||
<v-row>
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<v-switch
|
|
||||||
v-model="hasUser"
|
|
||||||
@change="() => {inbound.users = hasUser? [] : undefined}"
|
|
||||||
color="primary"
|
|
||||||
:label="$t('in.clients')"
|
|
||||||
hide-details></v-switch>
|
|
||||||
</v-col>
|
|
||||||
</v-row>
|
|
||||||
</v-card>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script lang="ts">
|
|
||||||
|
|
||||||
export default {
|
|
||||||
props: ['inbound', 'id'],
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
hasUser: false,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
cardTitle() {
|
|
||||||
this.hasUser = Object.hasOwn(this.$props.inbound,'users')
|
|
||||||
return this.$props.inbound?.type.toUpperCase()
|
|
||||||
},
|
|
||||||
},
|
|
||||||
mounted() {
|
|
||||||
this.hasUser = Object.hasOwn(this.$props.inbound,'users')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
<template>
|
|
||||||
<v-snackbar
|
|
||||||
v-model="sb.showMsg"
|
|
||||||
location="top"
|
|
||||||
:color="snackbar.color"
|
|
||||||
:timeout="snackbar.timeout">
|
|
||||||
{{ snackbar.message }}
|
|
||||||
</v-snackbar>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script lang="ts" setup>
|
|
||||||
import { ref } from 'vue'
|
|
||||||
import Message from '@/store/modules/message'
|
|
||||||
|
|
||||||
const sb = Message()
|
|
||||||
|
|
||||||
const snackbar = ref(sb.snackbar)
|
|
||||||
</script>
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
<template>
|
|
||||||
<v-card subtitle="Direct">
|
|
||||||
<v-row>
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<Network :inbound="inbound" />
|
|
||||||
</v-col>
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<v-text-field
|
|
||||||
label="Override Address"
|
|
||||||
hide-details
|
|
||||||
v-model="inbound.override_address">
|
|
||||||
</v-text-field>
|
|
||||||
</v-col>
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<v-text-field
|
|
||||||
label="Override Port"
|
|
||||||
type="number"
|
|
||||||
min="0"
|
|
||||||
hide-details
|
|
||||||
v-model="override_port">
|
|
||||||
</v-text-field>
|
|
||||||
</v-col>
|
|
||||||
</v-row>
|
|
||||||
</v-card>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script lang="ts">
|
|
||||||
import Network from '@/components/Network.vue'
|
|
||||||
|
|
||||||
export default {
|
|
||||||
props: ['inbound'],
|
|
||||||
data() {
|
|
||||||
return {}
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
override_port: {
|
|
||||||
get() { return this.$props.inbound.override_port ? this.$props.inbound.override_port : ''; },
|
|
||||||
set(newValue: any) { this.$props.inbound.override_port = newValue.length == 0 || newValue == 0 ? undefined : parseInt(newValue); }
|
|
||||||
},
|
|
||||||
},
|
|
||||||
components: { Network }
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
<template>
|
|
||||||
<v-card subtitle="Hysteria">
|
|
||||||
<v-row>
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<v-text-field
|
|
||||||
label="Uplink Limit"
|
|
||||||
hide-details
|
|
||||||
type="number"
|
|
||||||
suffix="Mbps"
|
|
||||||
v-model.number="up_mbps">
|
|
||||||
</v-text-field>
|
|
||||||
</v-col>
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<v-text-field
|
|
||||||
label="Downlink Limit"
|
|
||||||
hide-details
|
|
||||||
type="number"
|
|
||||||
suffix="Mbps"
|
|
||||||
min="0"
|
|
||||||
v-model.number="down_mbps">
|
|
||||||
</v-text-field>
|
|
||||||
</v-col>
|
|
||||||
</v-row>
|
|
||||||
<v-row>
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<v-text-field
|
|
||||||
label="obfs Password"
|
|
||||||
hide-details
|
|
||||||
v-model="inbound.obfs">
|
|
||||||
</v-text-field>
|
|
||||||
</v-col>
|
|
||||||
</v-row>
|
|
||||||
</v-card>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script lang="ts">
|
|
||||||
|
|
||||||
export default {
|
|
||||||
props: ['inbound'],
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
}
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
down_mbps: {
|
|
||||||
get() { return this.$props.inbound.down_mbps ? this.$props.inbound.down_mbps : 0 },
|
|
||||||
set(newValue:any) {
|
|
||||||
if (newValue.length != 0 ){
|
|
||||||
this.$props.inbound.down_mbps = newValue
|
|
||||||
this.$props.inbound.down = "" + newValue + " Mbps"
|
|
||||||
} else {
|
|
||||||
this.$props.inbound.down_mbps = 0
|
|
||||||
this.$props.inbound.down = "0 Mbps"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
up_mbps: {
|
|
||||||
get() { return this.$props.inbound.up_mbps ? this.$props.inbound.up_mbps : 0 },
|
|
||||||
set(newValue:number) { this.$props.inbound.up_mbps = newValue > 0 ? newValue : 0 }
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
@@ -1,91 +0,0 @@
|
|||||||
<template>
|
|
||||||
<v-card subtitle="Hysteria2">
|
|
||||||
<v-row>
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<v-text-field
|
|
||||||
label="Masquerade"
|
|
||||||
hide-details
|
|
||||||
v-model="hysteria2.masquerade"></v-text-field>
|
|
||||||
</v-col>
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<v-switch v-model="hysteria2.ignore_client_bandwidth" color="primary" label="Ignore Client Bandwidth" hide-details></v-switch>
|
|
||||||
</v-col>
|
|
||||||
</v-row>
|
|
||||||
<v-row v-if="!hysteria2.ignore_client_bandwidth">
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<v-text-field
|
|
||||||
label="Uplink Limit"
|
|
||||||
hide-details
|
|
||||||
type="number"
|
|
||||||
suffix="Mbps"
|
|
||||||
v-model.number="up_mbps">
|
|
||||||
</v-text-field>
|
|
||||||
</v-col>
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<v-text-field
|
|
||||||
label="Downlink Limit"
|
|
||||||
hide-details
|
|
||||||
type="number"
|
|
||||||
suffix="Mbps"
|
|
||||||
min="0"
|
|
||||||
v-model.number="down_mbps">
|
|
||||||
</v-text-field>
|
|
||||||
</v-col>
|
|
||||||
</v-row>
|
|
||||||
<v-row v-if="hysteria2.obfs">
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<v-text-field
|
|
||||||
label="obfs Password"
|
|
||||||
hide-details
|
|
||||||
v-model="hysteria2.obfs.password">
|
|
||||||
</v-text-field>
|
|
||||||
</v-col>
|
|
||||||
</v-row>
|
|
||||||
<v-card-actions>
|
|
||||||
<v-spacer></v-spacer>
|
|
||||||
<v-menu v-model="menu" :close-on-content-click="false" location="start">
|
|
||||||
<template v-slot:activator="{ props }">
|
|
||||||
<v-btn v-bind="props" hide-details>Options</v-btn>
|
|
||||||
</template>
|
|
||||||
<v-card>
|
|
||||||
<v-list>
|
|
||||||
<v-list-item>
|
|
||||||
<v-switch v-model="optionObfs" color="primary" label="Obfs" hide-details></v-switch>
|
|
||||||
</v-list-item>
|
|
||||||
</v-list>
|
|
||||||
</v-card>
|
|
||||||
</v-menu>
|
|
||||||
</v-card-actions>
|
|
||||||
</v-card>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script lang="ts">
|
|
||||||
import { Hysteria2, createInbound } from '@/types/inbounds'
|
|
||||||
|
|
||||||
export default {
|
|
||||||
props: ['inbound'],
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
menu: false,
|
|
||||||
hysteria2: <Hysteria2> createInbound("hysteria2",{ "tag": "" }),
|
|
||||||
}
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
down_mbps: {
|
|
||||||
get() { return this.hysteria2.down_mbps ? this.hysteria2.down_mbps : 0 },
|
|
||||||
set(newValue:any) { this.hysteria2.down_mbps = newValue.length == 0 ? undefined : this.hysteria2.down_mbps }
|
|
||||||
},
|
|
||||||
up_mbps: {
|
|
||||||
get() { return this.hysteria2.up_mbps ? this.hysteria2.up_mbps : 0 },
|
|
||||||
set(newValue:any) { this.hysteria2.up_mbps = newValue.length == 0 ? undefined : this.hysteria2.up_mbps }
|
|
||||||
},
|
|
||||||
optionObfs: {
|
|
||||||
get(): boolean { return this.hysteria2.obfs != undefined },
|
|
||||||
set(v:boolean) { this.$props.inbound.obfs = v ? { type: "salamander", password: ""} : undefined }
|
|
||||||
}
|
|
||||||
},
|
|
||||||
mounted() {
|
|
||||||
this.hysteria2 = <Hysteria2> this.$props.inbound
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
<template>
|
|
||||||
<v-card subtitle="Naive">
|
|
||||||
<v-row>
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<Network :inbound="inbound" />
|
|
||||||
</v-col>
|
|
||||||
</v-row>
|
|
||||||
</v-card>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script lang="ts">
|
|
||||||
import Network from '@/components/Network.vue'
|
|
||||||
|
|
||||||
export default {
|
|
||||||
props: ['inbound'],
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
}
|
|
||||||
},
|
|
||||||
components: { Network }
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
@@ -1,153 +0,0 @@
|
|||||||
<template>
|
|
||||||
<v-card subtitle="ShadowTls">
|
|
||||||
<v-row>
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<v-select
|
|
||||||
hide-details
|
|
||||||
:items="[1,2,3]"
|
|
||||||
label="Version"
|
|
||||||
v-model="version">
|
|
||||||
</v-select>
|
|
||||||
</v-col>
|
|
||||||
<v-col cols="12" sm="6" md="4" v-if="inbound.password != undefined">
|
|
||||||
<v-text-field
|
|
||||||
label="Password"
|
|
||||||
hide-details
|
|
||||||
v-model="inbound.password">
|
|
||||||
</v-text-field>
|
|
||||||
</v-col>
|
|
||||||
</v-row>
|
|
||||||
<v-row>
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<v-text-field
|
|
||||||
label="Handshake Server"
|
|
||||||
hide-details
|
|
||||||
v-model="Inbound.handshake.server">
|
|
||||||
</v-text-field>
|
|
||||||
</v-col>
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<v-text-field
|
|
||||||
label="Server Port"
|
|
||||||
type="number"
|
|
||||||
min="0"
|
|
||||||
hide-details
|
|
||||||
v-model="server_port">
|
|
||||||
</v-text-field>
|
|
||||||
</v-col>
|
|
||||||
</v-row>
|
|
||||||
<Dial :dial="Inbound.handshake" />
|
|
||||||
<v-row v-if="Inbound.handshake_for_server_name != undefined">
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<v-text-field
|
|
||||||
label="Add Hanshake Server"
|
|
||||||
hide-details
|
|
||||||
append-icon="mdi-plus"
|
|
||||||
@click:append="addHandshakeServer()"
|
|
||||||
v-model="handshake_server">
|
|
||||||
</v-text-field>
|
|
||||||
</v-col>
|
|
||||||
</v-row>
|
|
||||||
<v-card
|
|
||||||
v-for="(value, key) in Inbound.handshake_for_server_name"
|
|
||||||
border
|
|
||||||
density="compact"
|
|
||||||
style="margin: 5px;"
|
|
||||||
color="background">
|
|
||||||
<v-card-title>
|
|
||||||
<v-row>
|
|
||||||
<v-col>{{ key }}</v-col>
|
|
||||||
<v-spacer></v-spacer>
|
|
||||||
<v-col>
|
|
||||||
<v-btn @click="Inbound.handshake_for_server_name ? delete Inbound.handshake_for_server_name[key] : null"
|
|
||||||
icon="mdi-delete"
|
|
||||||
></v-btn>
|
|
||||||
</v-col>
|
|
||||||
</v-row>
|
|
||||||
</v-card-title>
|
|
||||||
<v-row>
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<v-text-field
|
|
||||||
label="Handshake Server"
|
|
||||||
hide-details
|
|
||||||
v-model="value.server">
|
|
||||||
</v-text-field>
|
|
||||||
</v-col>
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<v-text-field
|
|
||||||
label="Server Port"
|
|
||||||
type="number"
|
|
||||||
min="0"
|
|
||||||
hide-details
|
|
||||||
v-model="value.server_port">
|
|
||||||
</v-text-field>
|
|
||||||
</v-col>
|
|
||||||
</v-row>
|
|
||||||
<Dial :dial="value" />
|
|
||||||
</v-card>
|
|
||||||
</v-card>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script lang="ts">
|
|
||||||
import { ShadowTLS } from '@/types/inbounds'
|
|
||||||
import Dial from '../Dial.vue'
|
|
||||||
|
|
||||||
export default {
|
|
||||||
props: ['inbound'],
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
handshake_server: ''
|
|
||||||
}
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
addHandshakeServer() {
|
|
||||||
this.inbound.handshake_for_server_name[this.handshake_server] = {}
|
|
||||||
// Clear the input field after adding the server
|
|
||||||
this.handshake_server = ''
|
|
||||||
}
|
|
||||||
},
|
|
||||||
mounted() {
|
|
||||||
this.version = this.Inbound.version
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
version: {
|
|
||||||
get() { this.version = this.Inbound.version; return this.Inbound.version; },
|
|
||||||
set(newValue: any) {
|
|
||||||
switch (newValue) {
|
|
||||||
case 1:
|
|
||||||
this.Inbound.password = undefined
|
|
||||||
this.Inbound.users = undefined
|
|
||||||
this.Inbound.handshake_for_server_name = undefined
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
if (!this.Inbound.password) {
|
|
||||||
this.Inbound.password = ""
|
|
||||||
}
|
|
||||||
this.Inbound.users = undefined
|
|
||||||
if (!this.Inbound.handshake_for_server_name) {
|
|
||||||
this.Inbound.handshake_for_server_name = {}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
this.Inbound.password = undefined
|
|
||||||
if (Object.hasOwn(this.Inbound, 'users')) {
|
|
||||||
this.Inbound.users = []
|
|
||||||
}
|
|
||||||
if (!this.Inbound.handshake_for_server_name) {
|
|
||||||
this.Inbound.handshake_for_server_name = {}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
this.Inbound.version = newValue;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Inbound(): ShadowTLS {
|
|
||||||
return <ShadowTLS>this.$props.inbound;
|
|
||||||
},
|
|
||||||
server_port: {
|
|
||||||
get() { return this.Inbound.handshake.server_port ? this.Inbound.handshake.server_port : 443; },
|
|
||||||
set(newValue: any) { this.Inbound.handshake.server_port = newValue.length == 0 || newValue == 0 ? 443 : parseInt(newValue); }
|
|
||||||
},
|
|
||||||
},
|
|
||||||
components: { Dial }
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
<template>
|
|
||||||
<v-card subtitle="Shadowsocks">
|
|
||||||
<v-row>
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<v-select
|
|
||||||
hide-details
|
|
||||||
label="Method"
|
|
||||||
:items="ssMethods"
|
|
||||||
v-model="inbound.method">
|
|
||||||
</v-select>
|
|
||||||
</v-col>
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<v-text-field v-model="inbound.password" label="Password" hide-details></v-text-field>
|
|
||||||
</v-col>
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<Network :inbound="inbound" />
|
|
||||||
</v-col>
|
|
||||||
</v-row>
|
|
||||||
</v-card>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script lang="ts">
|
|
||||||
import Network from '@/components/Network.vue'
|
|
||||||
|
|
||||||
export default {
|
|
||||||
props: ['inbound'],
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
ssMethods: [
|
|
||||||
"none",
|
|
||||||
"aes-128-gcm",
|
|
||||||
"aes-192-gcm",
|
|
||||||
"aes-256-gcm",
|
|
||||||
"chacha20-ietf-poly1305",
|
|
||||||
"xchacha20-ietf-poly1305",
|
|
||||||
"2022-blake3-aes-128-gcm",
|
|
||||||
"2022-blake3-aes-256-gcm",
|
|
||||||
"2022-blake3-chacha20-poly1305"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
components: { Network }
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
<template>
|
|
||||||
<v-card subtitle="TProxy">
|
|
||||||
<v-row>
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<Network :inbound="inbound" />
|
|
||||||
</v-col>
|
|
||||||
</v-row>
|
|
||||||
</v-card>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script lang="ts">
|
|
||||||
import Network from '@/components/Network.vue'
|
|
||||||
|
|
||||||
export default {
|
|
||||||
props: ['inbound'],
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
}
|
|
||||||
},
|
|
||||||
components: { Network }
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
<template>
|
|
||||||
<v-card subtitle="TUIC">
|
|
||||||
<v-row>
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<v-select
|
|
||||||
hide-details
|
|
||||||
label="Congestion Control"
|
|
||||||
:items="congestion_controls"
|
|
||||||
v-model="inbound.congestion_control">
|
|
||||||
</v-select>
|
|
||||||
</v-col>
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<v-switch color="primary" label="Zero-RTT Handshake" v-model="inbound.zero_rtt_handshake" hide-details></v-switch>
|
|
||||||
</v-col>
|
|
||||||
</v-row>
|
|
||||||
<v-row>
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<v-text-field
|
|
||||||
label="Authentication Timeout"
|
|
||||||
hide-details
|
|
||||||
type="number"
|
|
||||||
suffix="s"
|
|
||||||
min="1"
|
|
||||||
v-model.number="auth_timeout">
|
|
||||||
</v-text-field>
|
|
||||||
</v-col>
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<v-text-field
|
|
||||||
label="Heartbeat"
|
|
||||||
hide-details
|
|
||||||
type="number"
|
|
||||||
suffix="s"
|
|
||||||
min="1"
|
|
||||||
v-model.number="heartbeat">
|
|
||||||
</v-text-field>
|
|
||||||
</v-col>
|
|
||||||
</v-row>
|
|
||||||
</v-card>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script lang="ts">
|
|
||||||
import { TUIC } from '@/types/inbounds'
|
|
||||||
export default {
|
|
||||||
props: ['inbound'],
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
congestion_controls: [
|
|
||||||
"cubic","new_reno", "bbr"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
Inbound(): TUIC {
|
|
||||||
return <TUIC> this.$props.inbound
|
|
||||||
},
|
|
||||||
auth_timeout: {
|
|
||||||
get() { return this.Inbound.auth_timeout ? parseInt(this.Inbound.auth_timeout.replace('s','')) : '' },
|
|
||||||
set(newValue:number) { this.$props.inbound.auth_timeout = newValue ? newValue + 's' : '' }
|
|
||||||
},
|
|
||||||
heartbeat: {
|
|
||||||
get() { return this.Inbound.heartbeat ? parseInt(this.Inbound.heartbeat.replace('s','')) : '' },
|
|
||||||
set(newValue:number) { this.$props.inbound.heartbeat = newValue ? newValue + 's' : '' }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
@@ -1,111 +0,0 @@
|
|||||||
<script lang="ts" setup>
|
|
||||||
import { HumanReadable } from '@/plugins/utils';
|
|
||||||
import { computed } from 'vue';
|
|
||||||
|
|
||||||
const props = defineProps({
|
|
||||||
tilesData: <any>{},
|
|
||||||
type: String
|
|
||||||
})
|
|
||||||
|
|
||||||
const data = computed(() => {
|
|
||||||
const d = props.tilesData
|
|
||||||
if (!d.mem && !d.cpu) return { percent: 0, text: '-' }
|
|
||||||
switch (props.type) {
|
|
||||||
case 'g-cpu':
|
|
||||||
return { percent: d.cpu, text: Math.ceil(d.cpu) + "%" }
|
|
||||||
case 'g-mem':
|
|
||||||
const curr = HumanReadable.sizeFormat(d.mem.current,0).split(' ')
|
|
||||||
const total = HumanReadable.sizeFormat(d.mem.total,0).split(' ')
|
|
||||||
if (curr[1] == total[1]) curr[1] = ''
|
|
||||||
return {
|
|
||||||
percent: Math.ceil(d.mem.current*100/d.mem.total),
|
|
||||||
text: curr[0] + "<sup>" + (curr[1]?? ' ') + "</sup>/" + total[0] + "<sup>" + (total[1]?? '') + "</sup>"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return { percent: 0, text: '-'}
|
|
||||||
})
|
|
||||||
|
|
||||||
const cssTransformRotateValue = computed(() => {
|
|
||||||
const percentageAsFraction = data.value.percent / 100
|
|
||||||
const halfPercentage = percentageAsFraction / 2
|
|
||||||
|
|
||||||
return `${halfPercentage}turn`
|
|
||||||
})
|
|
||||||
|
|
||||||
const gaugeColor = computed(() => {
|
|
||||||
if (data.value.percent > 90) return 'error'
|
|
||||||
if (data.value.percent > 70) return 'warning'
|
|
||||||
return 'primary'
|
|
||||||
})
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<div class="gauge__outer">
|
|
||||||
<div class="gauge__inner">
|
|
||||||
<div
|
|
||||||
class="gauge__fill"
|
|
||||||
:style="{
|
|
||||||
transform: `rotate(${cssTransformRotateValue})`,
|
|
||||||
background: `rgb(var(--v-theme-${gaugeColor}))`
|
|
||||||
}">
|
|
||||||
</div>
|
|
||||||
<span class="gauge__cover" dir="ltr" v-html="data.text">
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<style scoped>
|
|
||||||
.gauge__outer {
|
|
||||||
width: 100%;
|
|
||||||
max-width: 250px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.gauge__inner {
|
|
||||||
width: 100%;
|
|
||||||
height: 0;
|
|
||||||
padding-bottom: 50%;
|
|
||||||
background: rgb(var(--v-theme-surface));
|
|
||||||
position: relative;
|
|
||||||
border-top-left-radius: 100% 200%;
|
|
||||||
border-top-right-radius: 100% 200%;
|
|
||||||
overflow: hidden;
|
|
||||||
}
|
|
||||||
|
|
||||||
.gauge__fill {
|
|
||||||
position: absolute;
|
|
||||||
top: 100%;
|
|
||||||
left: 0;
|
|
||||||
width: inherit;
|
|
||||||
height: 100%;
|
|
||||||
background: rgb(var(--v-theme-primary));
|
|
||||||
transform-origin: center top;
|
|
||||||
transform: rotate(0turn);
|
|
||||||
transition: transform 0.2s ease-out;
|
|
||||||
}
|
|
||||||
|
|
||||||
.gauge__cover {
|
|
||||||
width: 75%;
|
|
||||||
height: 150%;
|
|
||||||
background: rgb(var(--v-theme-background));
|
|
||||||
position: absolute;
|
|
||||||
top: 25%;
|
|
||||||
left: 50%;
|
|
||||||
transform: translateX(-50%);
|
|
||||||
border-radius: 50%;
|
|
||||||
|
|
||||||
/* Text */
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
padding-bottom: 25%;
|
|
||||||
box-sizing: border-box;
|
|
||||||
font-family: 'Lexend', sans-serif;
|
|
||||||
font-weight: bold;
|
|
||||||
font-size: 32px;
|
|
||||||
}
|
|
||||||
|
|
||||||
sup {
|
|
||||||
font-size: 16px;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
@@ -1,200 +0,0 @@
|
|||||||
<template>
|
|
||||||
<Line v-if="loaded" :data="data" :options="<any>options" />
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script lang="ts">
|
|
||||||
import { ref } from 'vue'
|
|
||||||
import { Line } from 'vue-chartjs'
|
|
||||||
import {
|
|
||||||
Chart as ChartJS,
|
|
||||||
CategoryScale,
|
|
||||||
LinearScale,
|
|
||||||
PointElement,
|
|
||||||
LineElement,
|
|
||||||
Title,
|
|
||||||
Filler,
|
|
||||||
} from 'chart.js'
|
|
||||||
import { HumanReadable } from '@/plugins/utils'
|
|
||||||
ChartJS.register(
|
|
||||||
CategoryScale,
|
|
||||||
LinearScale,
|
|
||||||
PointElement,
|
|
||||||
LineElement,
|
|
||||||
Title,
|
|
||||||
Filler
|
|
||||||
)
|
|
||||||
ChartJS.defaults.font.family = 'Vazirmatn'
|
|
||||||
export default {
|
|
||||||
components: {
|
|
||||||
Line
|
|
||||||
},
|
|
||||||
props: ['tilesData','type'],
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
loaded: false,
|
|
||||||
labels: new Array(20).fill(''),
|
|
||||||
oldValues: <any>{},
|
|
||||||
options1: {
|
|
||||||
animation: false,
|
|
||||||
responsive: true,
|
|
||||||
maintainAspectRatio: false,
|
|
||||||
interaction: {
|
|
||||||
intersect: false,
|
|
||||||
mode: 'index',
|
|
||||||
},
|
|
||||||
plugins: {
|
|
||||||
tooltip: {
|
|
||||||
enabled: false
|
|
||||||
},
|
|
||||||
legend: {
|
|
||||||
display: false,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
scales: {
|
|
||||||
y: {
|
|
||||||
min: 0,
|
|
||||||
max: 100,
|
|
||||||
grid: {
|
|
||||||
color: () => { return this.$vuetify.theme.current.colors.secondary },
|
|
||||||
},
|
|
||||||
beginAtZero: true,
|
|
||||||
ticks: {
|
|
||||||
beginAtZero: true,
|
|
||||||
steps: 10,
|
|
||||||
stepValue: 5,
|
|
||||||
max: 100
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
optionsNet: {
|
|
||||||
animation: false,
|
|
||||||
responsive: true,
|
|
||||||
maintainAspectRatio: false,
|
|
||||||
interaction: {
|
|
||||||
intersect: false,
|
|
||||||
mode: 'index',
|
|
||||||
},
|
|
||||||
plugins: {
|
|
||||||
tooltip: {
|
|
||||||
enabled: false
|
|
||||||
},
|
|
||||||
legend: {
|
|
||||||
display: false,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
scales: {
|
|
||||||
y: {
|
|
||||||
grid: {
|
|
||||||
color: () => { return this.$vuetify.theme.current.colors.secondary },
|
|
||||||
},
|
|
||||||
beginAtZero: true,
|
|
||||||
ticks: {
|
|
||||||
callback: (label:any, index: number) => { return parseInt(label).toString() },
|
|
||||||
count: 10
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
data: ref(<any>{})
|
|
||||||
}
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
options() {
|
|
||||||
switch (this.$props.type){
|
|
||||||
case "h-net":
|
|
||||||
this.optionsNet.scales.y.ticks.callback = (label:any, index: number) => {
|
|
||||||
return label == 0 ? "0" : HumanReadable.sizeFormat(label,0)
|
|
||||||
}
|
|
||||||
return this.optionsNet
|
|
||||||
case "hp-net":
|
|
||||||
this.optionsNet.scales.y.ticks.callback = (label:any, index: number) => {
|
|
||||||
return label == 0 ? "0" : HumanReadable.packetFormat(label,0)
|
|
||||||
}
|
|
||||||
return this.optionsNet
|
|
||||||
}
|
|
||||||
return this.options1
|
|
||||||
}
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
updateData1(value1: number) {
|
|
||||||
const newData = <number[]>[]
|
|
||||||
if (this.data.datasets){
|
|
||||||
newData.push(...this.data.datasets[0].data,value1)
|
|
||||||
}
|
|
||||||
if (newData.length>20) newData.shift()
|
|
||||||
this.data = {
|
|
||||||
labels: this.labels,
|
|
||||||
datasets: [
|
|
||||||
{
|
|
||||||
label: '',
|
|
||||||
backgroundColor: 'rgba(255, 165, 0, 0.2)',
|
|
||||||
borderColor: 'rgba(255, 165, 0,0.8)',
|
|
||||||
fill: true,
|
|
||||||
data: newData
|
|
||||||
}
|
|
||||||
],
|
|
||||||
}
|
|
||||||
this.loaded = true
|
|
||||||
},
|
|
||||||
updateData2(value1: number, value2:number) {
|
|
||||||
const newData1 = <number[]>[]
|
|
||||||
const newData2 = <number[]>[]
|
|
||||||
if (this.data.datasets){
|
|
||||||
newData1.push(...this.data.datasets[0].data,value1)
|
|
||||||
newData2.push(...this.data.datasets[1].data,value2)
|
|
||||||
}
|
|
||||||
if (newData1.length>20) newData1.shift()
|
|
||||||
if (newData2.length>20) newData2.shift()
|
|
||||||
this.data = {
|
|
||||||
labels: this.labels,
|
|
||||||
datasets: [
|
|
||||||
{
|
|
||||||
label: '',
|
|
||||||
backgroundColor: 'rgba(255, 165, 0, 0.2)',
|
|
||||||
borderColor: 'rgba(255, 165, 0,0.8)',
|
|
||||||
fill: true,
|
|
||||||
data: newData1
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: '',
|
|
||||||
backgroundColor: 'rgba(0, 128, 0, 0.1)',
|
|
||||||
borderColor: 'rgba(0, 128, 0,0.8)',
|
|
||||||
fill: true,
|
|
||||||
data: newData2
|
|
||||||
}
|
|
||||||
],
|
|
||||||
}
|
|
||||||
this.loaded = true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
watch: {
|
|
||||||
tilesData(v:any) {
|
|
||||||
switch (this.$props.type) {
|
|
||||||
case 'h-cpu':
|
|
||||||
this.updateData1(v.cpu)
|
|
||||||
break
|
|
||||||
case 'h-mem':
|
|
||||||
this.updateData1(v.mem.current*100/v.mem.total)
|
|
||||||
break
|
|
||||||
case 'h-net':
|
|
||||||
if (this.oldValues.sent) {
|
|
||||||
const downSpeed = (v.net.recv-this.oldValues.recv)/2 // Each 2 sec
|
|
||||||
const upSpeed = (v.net.sent-this.oldValues.sent)/2 // Each 2 sec
|
|
||||||
this.updateData2(upSpeed,downSpeed)
|
|
||||||
}
|
|
||||||
this.oldValues = v.net
|
|
||||||
break
|
|
||||||
case 'hp-net':
|
|
||||||
if (this.oldValues.psent) {
|
|
||||||
const downSpeed = (v.net.precv-this.oldValues.precv)/2 // Each 2 sec
|
|
||||||
const upSpeed = (v.net.psent-this.oldValues.psent)/2 // Each 2 sec
|
|
||||||
this.updateData2(upSpeed,downSpeed)
|
|
||||||
}
|
|
||||||
this.oldValues = v.net
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
@@ -1,75 +0,0 @@
|
|||||||
<template>
|
|
||||||
<v-row>
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<v-text-field
|
|
||||||
:label="$t('transport.hosts')"
|
|
||||||
hide-details
|
|
||||||
v-model="hosts">
|
|
||||||
</v-text-field>
|
|
||||||
</v-col>
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<v-text-field
|
|
||||||
:label="$t('transport.path')"
|
|
||||||
hide-details
|
|
||||||
v-model="transport.path">
|
|
||||||
</v-text-field>
|
|
||||||
</v-col>
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<v-text-field
|
|
||||||
label="Method"
|
|
||||||
hide-details
|
|
||||||
v-model="transport.method">
|
|
||||||
</v-text-field>
|
|
||||||
</v-col>
|
|
||||||
</v-row>
|
|
||||||
<v-row>
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<v-text-field
|
|
||||||
label="Idle Timeout"
|
|
||||||
hide-details
|
|
||||||
type="number"
|
|
||||||
suffix="s"
|
|
||||||
min="1"
|
|
||||||
v-model.number="idle_timeout">
|
|
||||||
</v-text-field>
|
|
||||||
</v-col>
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<v-text-field
|
|
||||||
label="Ping Timeout"
|
|
||||||
hide-details
|
|
||||||
type="number"
|
|
||||||
suffix="s"
|
|
||||||
min="1"
|
|
||||||
v-model.number="ping_timeout">
|
|
||||||
</v-text-field>
|
|
||||||
</v-col>
|
|
||||||
</v-row>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script lang="ts">
|
|
||||||
import { HTTP } from '../../types/transport'
|
|
||||||
export default {
|
|
||||||
props: ['transport'],
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
}
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
Http(): HTTP {
|
|
||||||
return <HTTP> this.$props.transport?? {}
|
|
||||||
},
|
|
||||||
hosts: {
|
|
||||||
get() { return this.Http.host ? this.Http.host.join(',') : '' },
|
|
||||||
set(newValue:string) { this.$props.transport.host = newValue.length>0 ? newValue.split(',') : [] }
|
|
||||||
},
|
|
||||||
idle_timeout: {
|
|
||||||
get() { return this.Http.idle_timeout ? parseInt(this.Http.idle_timeout.replace('s','')) : '' },
|
|
||||||
set(newValue:number) { this.$props.transport.idle_timeout = newValue ? newValue + 's' : '' }
|
|
||||||
},
|
|
||||||
ping_timeout: {
|
|
||||||
get() { return this.Http.ping_timeout ? parseInt(this.Http.ping_timeout.replace('s','')) : '' },
|
|
||||||
set(newValue:number) { this.$props.transport.ping_timeout = newValue ? newValue + 's' : '' }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
<template>
|
|
||||||
<v-row>
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<v-text-field
|
|
||||||
:label="$t('transport.hosts')"
|
|
||||||
hide-details
|
|
||||||
v-model="transport.host">
|
|
||||||
</v-text-field>
|
|
||||||
</v-col>
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<v-text-field
|
|
||||||
:label="$t('transport.path')"
|
|
||||||
hide-details
|
|
||||||
v-model="transport.path">
|
|
||||||
</v-text-field>
|
|
||||||
</v-col>
|
|
||||||
</v-row>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script lang="ts">
|
|
||||||
export default {
|
|
||||||
props: ['transport'],
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
<template>
|
|
||||||
<v-row>
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<v-text-field
|
|
||||||
:label="$t('transport.path')"
|
|
||||||
hide-details
|
|
||||||
v-model="transport.path">
|
|
||||||
</v-text-field>
|
|
||||||
</v-col>
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<v-text-field
|
|
||||||
:label="$t('transport.host')"
|
|
||||||
hide-details
|
|
||||||
v-model="host">
|
|
||||||
</v-text-field>
|
|
||||||
</v-col>
|
|
||||||
</v-row>
|
|
||||||
<v-row>
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<v-text-field
|
|
||||||
label="Max Early Data"
|
|
||||||
hide-details
|
|
||||||
type="number"
|
|
||||||
min="0"
|
|
||||||
v-model.number="max_early_data">
|
|
||||||
</v-text-field>
|
|
||||||
</v-col>
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<v-text-field
|
|
||||||
label="Early Data Header Name"
|
|
||||||
hide-details
|
|
||||||
v-model="transport.early_data_header_name">
|
|
||||||
</v-text-field>
|
|
||||||
</v-col>
|
|
||||||
</v-row>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script lang="ts">
|
|
||||||
import { WebSocket } from '../../types/transport'
|
|
||||||
export default {
|
|
||||||
props: ['transport'],
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
}
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
WS(): WebSocket {
|
|
||||||
return <WebSocket> this.$props.transport
|
|
||||||
},
|
|
||||||
max_early_data: {
|
|
||||||
get() { return this.WS.max_early_data ? this.WS.max_early_data : '' },
|
|
||||||
set(newValue:number) { this.$props.transport.max_early_data = newValue != 0 ? newValue : undefined }
|
|
||||||
},
|
|
||||||
host: {
|
|
||||||
get() { return this.WS.headers?.Host ? this.WS.headers.Host : '' },
|
|
||||||
set(newValue:string) {
|
|
||||||
this.$props.transport.headers = newValue != "" ? { Host: newValue } : undefined
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
mounted() {
|
|
||||||
this.WS.early_data_header_name ??= 'Sec-WebSocket-Protocol'
|
|
||||||
this.WS.path ??= '/'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
<template>
|
|
||||||
<v-row>
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<v-text-field
|
|
||||||
label="Service Name"
|
|
||||||
hide-details
|
|
||||||
v-model="transport.service_name">
|
|
||||||
</v-text-field>
|
|
||||||
</v-col>
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<v-switch
|
|
||||||
color="primary"
|
|
||||||
v-model="transport.permit_without_stream"
|
|
||||||
label="Permit Without Stream"
|
|
||||||
hide-details>
|
|
||||||
</v-switch>
|
|
||||||
</v-col>
|
|
||||||
</v-row>
|
|
||||||
<v-row>
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<v-text-field
|
|
||||||
label="Idle Timeout"
|
|
||||||
hide-details
|
|
||||||
type="number"
|
|
||||||
suffix="s"
|
|
||||||
min="1"
|
|
||||||
v-model.number="idle_timeout">
|
|
||||||
</v-text-field>
|
|
||||||
</v-col>
|
|
||||||
<v-col cols="12" sm="6" md="4">
|
|
||||||
<v-text-field
|
|
||||||
label="Ping Timeout"
|
|
||||||
hide-details
|
|
||||||
type="number"
|
|
||||||
suffix="s"
|
|
||||||
min="1"
|
|
||||||
v-model.number="ping_timeout">
|
|
||||||
</v-text-field>
|
|
||||||
</v-col>
|
|
||||||
</v-row>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script lang="ts">
|
|
||||||
import { gRPC } from '../../types/transport'
|
|
||||||
export default {
|
|
||||||
props: ['transport'],
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
}
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
GRPC(): gRPC {
|
|
||||||
return <gRPC> this.$props.transport?? {}
|
|
||||||
},
|
|
||||||
idle_timeout: {
|
|
||||||
get() { return this.GRPC.idle_timeout ? parseInt(this.GRPC.idle_timeout.replace('s','')) : '' },
|
|
||||||
set(newValue:number) { this.$props.transport.idle_timeout = newValue ? newValue + 's' : '' }
|
|
||||||
},
|
|
||||||
ping_timeout: {
|
|
||||||
get() { return this.GRPC.ping_timeout ? parseInt(this.GRPC.ping_timeout.replace('s','')) : '' },
|
|
||||||
set(newValue:number) { this.$props.transport.ping_timeout = newValue ? newValue + 's' : '' }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
<template>
|
|
||||||
<v-app-bar :elevation="5">
|
|
||||||
<v-icon v-if="isMobile" icon="mdi-menu" @click="$emit('toggleDrawer')" />
|
|
||||||
<span v-else style="width: 24px"></span>
|
|
||||||
<v-app-bar-title :text="$t(<string>$router.currentRoute.value.name)" class="align-center text-center " />
|
|
||||||
<v-btn prepend-icon="mdi-content-save" v-if="stateChange" :text="$t('actions.save')" @click="saveChanges"></v-btn>
|
|
||||||
<v-icon icon="mdi-theme-light-dark" @click="toggleTheme()" style="margin: 0 10px;"></v-icon>
|
|
||||||
</v-app-bar>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script lang="ts" setup>
|
|
||||||
import { computed, onMounted, ref,watch } from "vue"
|
|
||||||
import { useTheme } from "vuetify"
|
|
||||||
import { FindDiff } from "@/plugins/utils"
|
|
||||||
import Data from "@/store/modules/data"
|
|
||||||
|
|
||||||
defineProps(['isMobile'])
|
|
||||||
|
|
||||||
const theme = useTheme()
|
|
||||||
const darkMode = ref(localStorage.getItem('theme') == "dark")
|
|
||||||
|
|
||||||
const store = Data()
|
|
||||||
|
|
||||||
const toggleTheme = () => {
|
|
||||||
darkMode.value = !darkMode.value
|
|
||||||
theme.global.name.value = darkMode.value ? "dark" : "light"
|
|
||||||
localStorage.setItem('theme', theme.global.name.value)
|
|
||||||
}
|
|
||||||
|
|
||||||
const saveChanges = () => {
|
|
||||||
store.pushData()
|
|
||||||
}
|
|
||||||
|
|
||||||
const oldData = computed((): any => {
|
|
||||||
return {config: store.oldData.config, clients: store.oldData.clients}
|
|
||||||
})
|
|
||||||
|
|
||||||
const newData = computed((): any => {
|
|
||||||
return {config: store.config, clients: store.clients}
|
|
||||||
})
|
|
||||||
|
|
||||||
const stateChange = computed((): any => {
|
|
||||||
return !FindDiff.deepCompare(newData.value,oldData.value)
|
|
||||||
})
|
|
||||||
</script>
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
<template>
|
|
||||||
<v-app style="overflow: auto;">
|
|
||||||
<drawer :isMobile="isMobile" :displayDrawer="displayDrawer" @toggleDrawer="toggleDrawer" />
|
|
||||||
<default-bar :isMobile="isMobile" @toggleDrawer="toggleDrawer" />
|
|
||||||
<default-view />
|
|
||||||
</v-app>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script lang="ts" setup>
|
|
||||||
import { computed, ref } from 'vue'
|
|
||||||
import DefaultBar from './AppBar.vue'
|
|
||||||
import Drawer from './Drawer.vue'
|
|
||||||
import DefaultView from './View.vue'
|
|
||||||
import { useDisplay } from 'vuetify'
|
|
||||||
|
|
||||||
const { smAndDown } = useDisplay()
|
|
||||||
const displayDrawer = ref(false)
|
|
||||||
|
|
||||||
const toggleDrawer = () => {
|
|
||||||
displayDrawer.value = !displayDrawer.value
|
|
||||||
}
|
|
||||||
|
|
||||||
const isMobile = computed( ():boolean =>{
|
|
||||||
displayDrawer.value = !smAndDown.value
|
|
||||||
return smAndDown.value
|
|
||||||
})
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style>
|
|
||||||
.v-card-subtitle {
|
|
||||||
text-align: center;
|
|
||||||
border-bottom: 1px solid gray;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
<template>
|
|
||||||
<v-navigation-drawer
|
|
||||||
v-model="showDrawer"
|
|
||||||
:temporary="isMobile"
|
|
||||||
:expand-on-hover="!isMobile"
|
|
||||||
:rail="!isMobile"
|
|
||||||
:permanent="!isMobile"
|
|
||||||
@click="isMobile ? $emit('toggleDrawer') : null"
|
|
||||||
>
|
|
||||||
<v-list-item
|
|
||||||
height="63"
|
|
||||||
prepend-avatar="@/assets/logo.svg"
|
|
||||||
title="S-UI"
|
|
||||||
>
|
|
||||||
<template v-slot:append v-if="isMobile">
|
|
||||||
<v-icon icon="mdi-close" />
|
|
||||||
</template>
|
|
||||||
</v-list-item>
|
|
||||||
|
|
||||||
<v-divider></v-divider>
|
|
||||||
|
|
||||||
<v-list density="compact" nav>
|
|
||||||
<v-list-item link
|
|
||||||
v-for="item in menu"
|
|
||||||
:key="item.title"
|
|
||||||
:to="item.path"
|
|
||||||
:active="router.currentRoute.value.path == item.path">
|
|
||||||
<template v-slot:prepend>
|
|
||||||
<v-icon :icon="item.icon"></v-icon>
|
|
||||||
</template>
|
|
||||||
<v-list-item-title v-text="$t(item.title)"></v-list-item-title>
|
|
||||||
</v-list-item>
|
|
||||||
</v-list>
|
|
||||||
<template v-slot:append>
|
|
||||||
<v-list-item prepend-icon="mdi-logout" :title="$t('menu.logout')" @click="Logout"></v-list-item>
|
|
||||||
</template>
|
|
||||||
</v-navigation-drawer>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script lang="ts" setup>
|
|
||||||
import { computed } from 'vue'
|
|
||||||
import router from '@/router'
|
|
||||||
import { logout } from '@/plugins/httputil'
|
|
||||||
|
|
||||||
const props = defineProps(['isMobile','displayDrawer'])
|
|
||||||
|
|
||||||
const showDrawer = computed((): boolean => {
|
|
||||||
return props.displayDrawer
|
|
||||||
})
|
|
||||||
|
|
||||||
const menu = [
|
|
||||||
{ title: 'pages.home', icon: 'mdi-home', path: '/' },
|
|
||||||
{ title: 'pages.inbounds', icon: 'mdi-cloud-download', path: '/inbounds' },
|
|
||||||
{ title: 'pages.clients', icon: 'mdi-account-multiple', path: '/clients' },
|
|
||||||
{ title: 'pages.outbounds', icon: 'mdi-cloud-upload', path: '/outbounds' },
|
|
||||||
{ title: 'pages.rules', icon: 'mdi-routes', path: '/rules' },
|
|
||||||
{ title: 'pages.basics', icon: 'mdi-application-cog', path: '/basics' },
|
|
||||||
{ title: 'pages.admins', icon: 'mdi-account-tie', path: '/admins' },
|
|
||||||
{ title: 'pages.settings', icon: 'mdi-cog', path: '/settings' },
|
|
||||||
]
|
|
||||||
|
|
||||||
const Logout = async () => {
|
|
||||||
logout()
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user