Compare commits
41 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8901581d0c | ||
|
|
c6bab83e24 | ||
|
|
9cd74b43d0 | ||
|
|
2d8cc8ebe5 | ||
| 58bb324d82 | |||
| bed78a36d0 | |||
| e4999abf47 | |||
| 937536e422 | |||
| 838bde28f0 | |||
| 743b91f3bf | |||
| 5a03d9e1f1 | |||
| dcfd2f4466 | |||
| f13dc2451c | |||
| 1c71a7633b | |||
| b7a1a249a4 | |||
| 5cee8daabc | |||
|
|
a9ca714b24 | ||
|
|
d6627a292d | ||
| e0d88e9ad7 | |||
|
|
ba9edd3c02 | ||
|
|
e40d079f7a | ||
|
|
8ce5b149f7 | ||
|
|
0a41e10793 | ||
|
|
3386b0fcb6 | ||
|
|
98a5525e6d | ||
|
|
5c8020d5fb | ||
|
|
a2773aa1a7 | ||
|
|
9cc2fa8076 | ||
|
|
1890cad8d9 | ||
|
|
11572f132c | ||
|
|
9f13b0d4e9 | ||
|
|
7cddb7b3e7 | ||
|
|
d1058f9e89 | ||
|
|
06dfcfaff3 | ||
|
|
67c41cde5c | ||
|
|
4500f48d4c | ||
|
|
381c6911af | ||
|
|
42445d18eb | ||
|
|
d3969079a5 | ||
|
|
6496d56e0e | ||
|
|
23fa089608 |
@@ -163,13 +163,21 @@ jobs:
|
|||||||
id: release_notes
|
id: release_notes
|
||||||
run: |
|
run: |
|
||||||
if [ -n "${{ inputs.release_notes }}" ]; then
|
if [ -n "${{ inputs.release_notes }}" ]; then
|
||||||
|
# 使用用户输入的 release notes
|
||||||
echo "${{ inputs.release_notes }}" > release_notes.md
|
echo "${{ inputs.release_notes }}" > release_notes.md
|
||||||
else
|
else
|
||||||
echo "Release ${{ inputs.version }}" > release_notes.md
|
# 使用最近一次 commit message 作为 release notes
|
||||||
|
echo "## Release ${{ inputs.version }}" > release_notes.md
|
||||||
echo "" >> release_notes.md
|
echo "" >> release_notes.md
|
||||||
echo "## Assets" >> release_notes.md
|
echo "### Changes" >> release_notes.md
|
||||||
echo "" >> release_notes.md
|
echo "" >> release_notes.md
|
||||||
echo "Download the appropriate binary for your platform:" >> release_notes.md
|
# 获取最近一次 commit 的完整 message
|
||||||
|
git log -1 --pretty=format:"%B" >> release_notes.md
|
||||||
|
echo "" >> release_notes.md
|
||||||
|
echo "" >> release_notes.md
|
||||||
|
echo "---" >> release_notes.md
|
||||||
|
echo "" >> release_notes.md
|
||||||
|
echo "### Assets" >> release_notes.md
|
||||||
echo "" >> release_notes.md
|
echo "" >> release_notes.md
|
||||||
echo "- **Linux (amd64/arm64)**: \`.tar.gz\` files" >> release_notes.md
|
echo "- **Linux (amd64/arm64)**: \`.tar.gz\` files" >> release_notes.md
|
||||||
echo "- **macOS (amd64/arm64)**: \`.tar.gz\` files" >> release_notes.md
|
echo "- **macOS (amd64/arm64)**: \`.tar.gz\` files" >> release_notes.md
|
||||||
@@ -177,22 +185,22 @@ jobs:
|
|||||||
echo "" >> release_notes.md
|
echo "" >> release_notes.md
|
||||||
echo "Verify downloads with \`SHA256SUMS\`" >> release_notes.md
|
echo "Verify downloads with \`SHA256SUMS\`" >> release_notes.md
|
||||||
fi
|
fi
|
||||||
|
echo "=== Release Notes ==="
|
||||||
cat release_notes.md
|
cat release_notes.md
|
||||||
|
|
||||||
- name: Create Release
|
- name: Create Release
|
||||||
uses: softprops/action-gh-release@v1
|
uses: akkuman/gitea-release-action@v1
|
||||||
with:
|
with:
|
||||||
tag_name: ${{ inputs.version }}
|
tag_name: ${{ inputs.version }}
|
||||||
name: Release ${{ inputs.version }}
|
name: Release ${{ inputs.version }}
|
||||||
body_path: release_notes.md
|
body_path: release_notes.md
|
||||||
files: |
|
files: |-
|
||||||
dist/*.tar.gz
|
dist/*.tar.gz
|
||||||
dist/*.zip
|
dist/*.zip
|
||||||
dist/SHA256SUMS
|
dist/SHA256SUMS
|
||||||
draft: ${{ inputs.draft }}
|
draft: ${{ inputs.draft }}
|
||||||
prerelease: ${{ inputs.prerelease }}
|
prerelease: ${{ inputs.prerelease }}
|
||||||
env:
|
token: ${{ secrets.ACCOUNT_TOKEN }}
|
||||||
GITHUB_TOKEN: ${{ secrets.ACCOUNT_TOKEN }}
|
|
||||||
|
|
||||||
- name: Release created successfully
|
- name: Release created successfully
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
117
.github/workflows/build.yml
vendored
Normal file
117
.github/workflows/build.yml
vendored
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
name: CI Build
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
pull_request:
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: ci-${{ github.workflow }}-${{ github.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
frontend:
|
||||||
|
name: Build frontend
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup Node.js
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: '20'
|
||||||
|
cache: npm
|
||||||
|
cache-dependency-path: web/package-lock.json
|
||||||
|
|
||||||
|
- name: Install frontend dependencies
|
||||||
|
working-directory: web
|
||||||
|
run: npm ci
|
||||||
|
|
||||||
|
- name: Build frontend
|
||||||
|
working-directory: web
|
||||||
|
run: npm run build
|
||||||
|
|
||||||
|
- name: Upload frontend artifact
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: frontend-dist
|
||||||
|
path: web/dist
|
||||||
|
retention-days: 1
|
||||||
|
|
||||||
|
build:
|
||||||
|
name: Build ${{ matrix.goos }}/${{ matrix.goarch }}
|
||||||
|
needs: frontend
|
||||||
|
runs-on: ${{ matrix.runner }}
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
include:
|
||||||
|
- runner: ubuntu-latest
|
||||||
|
goos: linux
|
||||||
|
goarch: amd64
|
||||||
|
- runner: ubuntu-latest
|
||||||
|
goos: linux
|
||||||
|
goarch: arm64
|
||||||
|
- runner: windows-latest
|
||||||
|
goos: windows
|
||||||
|
goarch: amd64
|
||||||
|
- runner: macos-latest
|
||||||
|
goos: darwin
|
||||||
|
goarch: amd64
|
||||||
|
- runner: macos-latest
|
||||||
|
goos: darwin
|
||||||
|
goarch: arm64
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup Go
|
||||||
|
uses: actions/setup-go@v5
|
||||||
|
with:
|
||||||
|
go-version-file: go.mod
|
||||||
|
cache: true
|
||||||
|
|
||||||
|
- name: Download frontend artifact
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
name: frontend-dist
|
||||||
|
path: internal/server/app/dist
|
||||||
|
|
||||||
|
- name: Download Go modules
|
||||||
|
run: go mod download
|
||||||
|
|
||||||
|
- name: Build server and client
|
||||||
|
shell: bash
|
||||||
|
env:
|
||||||
|
GOOS: ${{ matrix.goos }}
|
||||||
|
GOARCH: ${{ matrix.goarch }}
|
||||||
|
CGO_ENABLED: 0
|
||||||
|
run: |
|
||||||
|
mkdir -p build/${GOOS}_${GOARCH}
|
||||||
|
EXT=""
|
||||||
|
if [ "$GOOS" = "windows" ]; then
|
||||||
|
EXT=".exe"
|
||||||
|
fi
|
||||||
|
|
||||||
|
BUILD_TIME="$(date -u '+%Y-%m-%dT%H:%M:%SZ')"
|
||||||
|
GIT_COMMIT="${GITHUB_SHA::7}"
|
||||||
|
VERSION="${GITHUB_REF_NAME}"
|
||||||
|
if [ "${GITHUB_REF_TYPE}" != "tag" ]; then
|
||||||
|
VERSION="${GITHUB_SHA::7}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
LDFLAGS="-s -w -X 'main.Version=${VERSION}' -X 'main.BuildTime=${BUILD_TIME}' -X 'main.GitCommit=${GIT_COMMIT}'"
|
||||||
|
|
||||||
|
go build -trimpath -ldflags "$LDFLAGS" -o "build/${GOOS}_${GOARCH}/server${EXT}" ./cmd/server
|
||||||
|
go build -trimpath -ldflags "$LDFLAGS" -o "build/${GOOS}_${GOARCH}/client${EXT}" ./cmd/client
|
||||||
|
|
||||||
|
- name: Upload binaries artifact
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: gotunnel-${{ matrix.goos }}-${{ matrix.goarch }}
|
||||||
|
path: build/${{ matrix.goos }}_${{ matrix.goarch }}/
|
||||||
|
retention-days: 7
|
||||||
214
.github/workflows/release.yml
vendored
Normal file
214
.github/workflows/release.yml
vendored
Normal file
@@ -0,0 +1,214 @@
|
|||||||
|
name: Release
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- 'v*'
|
||||||
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
tag:
|
||||||
|
description: 'Release tag to publish, e.g. v1.2.3'
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: release-${{ github.event.inputs.tag || github.ref }}
|
||||||
|
cancel-in-progress: false
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
frontend:
|
||||||
|
name: Build frontend
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Setup Node.js
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: '20'
|
||||||
|
cache: npm
|
||||||
|
cache-dependency-path: web/package-lock.json
|
||||||
|
|
||||||
|
- name: Install frontend dependencies
|
||||||
|
working-directory: web
|
||||||
|
run: npm ci
|
||||||
|
|
||||||
|
- name: Build frontend
|
||||||
|
working-directory: web
|
||||||
|
run: npm run build
|
||||||
|
|
||||||
|
- name: Upload frontend artifact
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: frontend-dist
|
||||||
|
path: web/dist
|
||||||
|
retention-days: 1
|
||||||
|
|
||||||
|
build-assets:
|
||||||
|
name: Package ${{ matrix.component }} ${{ matrix.goos }}/${{ matrix.goarch }}
|
||||||
|
needs: frontend
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
include:
|
||||||
|
- component: server
|
||||||
|
goos: linux
|
||||||
|
goarch: amd64
|
||||||
|
archive_ext: tar.gz
|
||||||
|
- component: client
|
||||||
|
goos: linux
|
||||||
|
goarch: amd64
|
||||||
|
archive_ext: tar.gz
|
||||||
|
- component: server
|
||||||
|
goos: linux
|
||||||
|
goarch: arm64
|
||||||
|
archive_ext: tar.gz
|
||||||
|
- component: client
|
||||||
|
goos: linux
|
||||||
|
goarch: arm64
|
||||||
|
archive_ext: tar.gz
|
||||||
|
- component: server
|
||||||
|
goos: darwin
|
||||||
|
goarch: amd64
|
||||||
|
archive_ext: tar.gz
|
||||||
|
- component: client
|
||||||
|
goos: darwin
|
||||||
|
goarch: amd64
|
||||||
|
archive_ext: tar.gz
|
||||||
|
- component: server
|
||||||
|
goos: darwin
|
||||||
|
goarch: arm64
|
||||||
|
archive_ext: tar.gz
|
||||||
|
- component: client
|
||||||
|
goos: darwin
|
||||||
|
goarch: arm64
|
||||||
|
archive_ext: tar.gz
|
||||||
|
- component: server
|
||||||
|
goos: windows
|
||||||
|
goarch: amd64
|
||||||
|
archive_ext: zip
|
||||||
|
- component: client
|
||||||
|
goos: windows
|
||||||
|
goarch: amd64
|
||||||
|
archive_ext: zip
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Setup Go
|
||||||
|
uses: actions/setup-go@v5
|
||||||
|
with:
|
||||||
|
go-version-file: go.mod
|
||||||
|
cache: true
|
||||||
|
|
||||||
|
- name: Download frontend artifact
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
name: frontend-dist
|
||||||
|
path: internal/server/app/dist
|
||||||
|
|
||||||
|
- name: Download Go modules
|
||||||
|
run: go mod download
|
||||||
|
|
||||||
|
- name: Resolve release metadata
|
||||||
|
id: meta
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
if [ "${GITHUB_EVENT_NAME}" = "workflow_dispatch" ]; then
|
||||||
|
TAG="${{ github.event.inputs.tag }}"
|
||||||
|
else
|
||||||
|
TAG="${GITHUB_REF_NAME}"
|
||||||
|
fi
|
||||||
|
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "commit=${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "build_time=$(date -u '+%Y-%m-%dT%H:%M:%SZ')" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
|
- name: Build binary
|
||||||
|
shell: bash
|
||||||
|
env:
|
||||||
|
GOOS: ${{ matrix.goos }}
|
||||||
|
GOARCH: ${{ matrix.goarch }}
|
||||||
|
CGO_ENABLED: 0
|
||||||
|
VERSION: ${{ steps.meta.outputs.tag }}
|
||||||
|
GIT_COMMIT: ${{ steps.meta.outputs.commit }}
|
||||||
|
BUILD_TIME: ${{ steps.meta.outputs.build_time }}
|
||||||
|
run: |
|
||||||
|
mkdir -p dist/package
|
||||||
|
EXT=""
|
||||||
|
if [ "$GOOS" = "windows" ]; then
|
||||||
|
EXT=".exe"
|
||||||
|
fi
|
||||||
|
|
||||||
|
OUTPUT_NAME="${{ matrix.component }}${EXT}"
|
||||||
|
LDFLAGS="-s -w -X 'main.Version=${VERSION}' -X 'main.BuildTime=${BUILD_TIME}' -X 'main.GitCommit=${GIT_COMMIT}'"
|
||||||
|
go build -trimpath -ldflags "$LDFLAGS" -o "dist/package/${OUTPUT_NAME}" ./cmd/${{ matrix.component }}
|
||||||
|
|
||||||
|
- name: Create release archive
|
||||||
|
id: package
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
TAG="${{ steps.meta.outputs.tag }}"
|
||||||
|
ARCHIVE="gotunnel-${{ matrix.component }}-${TAG}-${{ matrix.goos }}-${{ matrix.goarch }}.${{ matrix.archive_ext }}"
|
||||||
|
mkdir -p dist/out
|
||||||
|
if [ "${{ matrix.archive_ext }}" = "zip" ]; then
|
||||||
|
(cd dist/package && zip -r "../out/${ARCHIVE}" .)
|
||||||
|
else
|
||||||
|
tar -C dist/package -czf "dist/out/${ARCHIVE}" .
|
||||||
|
fi
|
||||||
|
echo "archive=dist/out/${ARCHIVE}" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
|
- name: Upload release asset artifact
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: release-${{ matrix.component }}-${{ matrix.goos }}-${{ matrix.goarch }}
|
||||||
|
path: ${{ steps.package.outputs.archive }}
|
||||||
|
retention-days: 1
|
||||||
|
|
||||||
|
publish:
|
||||||
|
name: Publish release
|
||||||
|
needs: build-assets
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Download packaged assets
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
path: release-artifacts
|
||||||
|
pattern: release-*
|
||||||
|
merge-multiple: true
|
||||||
|
|
||||||
|
- name: Resolve release metadata
|
||||||
|
id: meta
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
if [ "${GITHUB_EVENT_NAME}" = "workflow_dispatch" ]; then
|
||||||
|
TAG="${{ github.event.inputs.tag }}"
|
||||||
|
else
|
||||||
|
TAG="${GITHUB_REF_NAME}"
|
||||||
|
fi
|
||||||
|
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
|
- name: Generate checksums
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
cd release-artifacts
|
||||||
|
sha256sum * > SHA256SUMS.txt
|
||||||
|
|
||||||
|
- name: Create or update GitHub release
|
||||||
|
uses: softprops/action-gh-release@v2
|
||||||
|
with:
|
||||||
|
tag_name: ${{ steps.meta.outputs.tag }}
|
||||||
|
target_commitish: ${{ github.sha }}
|
||||||
|
generate_release_notes: true
|
||||||
|
fail_on_unmatched_files: true
|
||||||
|
files: |
|
||||||
|
release-artifacts/*
|
||||||
113
AGENTS.md
Normal file
113
AGENTS.md
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
# AGENTS.md
|
||||||
|
|
||||||
|
This file provides guidance to Codex (Codex.ai/code) when working with code in this repository.
|
||||||
|
|
||||||
|
## Build Commands
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Build server and client binaries
|
||||||
|
go build -o server ./cmd/server
|
||||||
|
go build -o client ./cmd/client
|
||||||
|
|
||||||
|
# Run server (zero-config, auto-generates token and TLS cert)
|
||||||
|
./server
|
||||||
|
./server -c server.yaml # with config file
|
||||||
|
|
||||||
|
# Run client
|
||||||
|
./client -s <server>:7000 -t <token>
|
||||||
|
|
||||||
|
# Web UI development (in web/ directory)
|
||||||
|
cd web && npm install && npm run dev # development server
|
||||||
|
cd web && npm run build # production build (outputs to web/dist/)
|
||||||
|
|
||||||
|
# Cross-platform build (Windows PowerShell)
|
||||||
|
.\scripts\build.ps1
|
||||||
|
|
||||||
|
# Cross-platform build (Linux/Mac)
|
||||||
|
./scripts/build.sh all
|
||||||
|
```
|
||||||
|
|
||||||
|
## Architecture Overview
|
||||||
|
|
||||||
|
GoTunnel is an intranet penetration tool (similar to frp) with **server-centric configuration** - clients require zero configuration and receive mapping rules from the server after authentication.
|
||||||
|
|
||||||
|
### Core Design
|
||||||
|
|
||||||
|
- **Yamux Multiplexing**: Single TCP connection carries both control (auth, config, heartbeat) and data channels
|
||||||
|
- **Binary Protocol**: `[Type(1 byte)][Length(4 bytes)][Payload(JSON)]` - see `pkg/protocol/message.go`
|
||||||
|
- **TLS by Default**: Auto-generated self-signed ECDSA P-256 certificates, no manual setup required
|
||||||
|
- **Embedded Web UI**: Vue.js SPA embedded in server binary via `//go:embed`
|
||||||
|
- **JS Plugin System**: Extensible plugin system using goja JavaScript runtime
|
||||||
|
|
||||||
|
### Package Structure
|
||||||
|
|
||||||
|
```
|
||||||
|
cmd/server/ # Server entry point
|
||||||
|
cmd/client/ # Client entry point
|
||||||
|
internal/server/
|
||||||
|
├── tunnel/ # Core tunnel server, client session management
|
||||||
|
├── config/ # YAML configuration loading
|
||||||
|
├── db/ # SQLite storage (ClientStore, JSPluginStore interfaces)
|
||||||
|
├── app/ # Web server, SPA handler
|
||||||
|
├── router/ # REST API endpoints (Swagger documented)
|
||||||
|
└── plugin/ # Server-side JS plugin manager
|
||||||
|
internal/client/
|
||||||
|
└── tunnel/ # Client tunnel logic, auto-reconnect, plugin execution
|
||||||
|
pkg/
|
||||||
|
├── protocol/ # Message types and serialization
|
||||||
|
├── crypto/ # TLS certificate generation
|
||||||
|
├── relay/ # Bidirectional data relay (32KB buffers)
|
||||||
|
├── auth/ # JWT authentication
|
||||||
|
├── utils/ # Port availability checking
|
||||||
|
├── version/ # Version info and update checking (Gitea API)
|
||||||
|
└── update/ # Shared update logic (download, extract tar.gz/zip)
|
||||||
|
web/ # Vue 3 + TypeScript frontend (Vite + naive-ui)
|
||||||
|
scripts/ # Build scripts (build.sh, build.ps1)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Key Interfaces
|
||||||
|
|
||||||
|
- `ClientStore` (internal/server/db/): Database abstraction for client rules storage
|
||||||
|
- `ServerInterface` (internal/server/router/handler/): API handler interface
|
||||||
|
|
||||||
|
### Proxy Types
|
||||||
|
|
||||||
|
1. **TCP** (default): Direct port forwarding (remote_port → local_ip:local_port)
|
||||||
|
2. **UDP**: UDP port forwarding
|
||||||
|
3. **HTTP**: HTTP proxy through client network
|
||||||
|
4. **HTTPS**: HTTPS proxy through client network
|
||||||
|
5. **SOCKS5**: SOCKS5 proxy through client network
|
||||||
|
|
||||||
|
### Data Flow
|
||||||
|
|
||||||
|
External User → Server Port → Yamux Stream → Client → Local Service
|
||||||
|
|
||||||
|
### Configuration
|
||||||
|
|
||||||
|
- Server: YAML config + SQLite database for client rules and JS plugins
|
||||||
|
- Client: Command-line flags only (server address, token)
|
||||||
|
- Default ports: 7000 (tunnel), 7500 (web console)
|
||||||
|
|
||||||
|
## API Documentation
|
||||||
|
|
||||||
|
The server provides Swagger-documented REST APIs at `/api/`.
|
||||||
|
|
||||||
|
### Key Endpoints
|
||||||
|
|
||||||
|
- `POST /api/auth/login` - JWT authentication
|
||||||
|
- `GET /api/clients` - List all clients
|
||||||
|
- `GET /api/client/{id}` - Get client details
|
||||||
|
- `PUT /api/client/{id}` - Update client config
|
||||||
|
- `POST /api/client/{id}/push` - Push config to online client
|
||||||
|
- `POST /api/client/{id}/plugin/{name}/{action}` - Plugin actions (start/stop/restart/delete)
|
||||||
|
- `GET /api/plugins` - List registered plugins
|
||||||
|
- `GET /api/update/check/server` - Check server updates
|
||||||
|
- `POST /api/update/apply/server` - Apply server update
|
||||||
|
|
||||||
|
## Update System
|
||||||
|
|
||||||
|
Both server and client support self-update from Gitea releases.
|
||||||
|
|
||||||
|
- Release assets are compressed archives (`.tar.gz` for Linux/Mac, `.zip` for Windows)
|
||||||
|
- The `pkg/update/` package handles download, extraction, and binary replacement
|
||||||
|
- Updates can be triggered from the Web UI at `/update` page
|
||||||
58
CLAUDE.md
58
CLAUDE.md
@@ -14,8 +14,7 @@ go build -o client ./cmd/client
|
|||||||
./server -c server.yaml # with config file
|
./server -c server.yaml # with config file
|
||||||
|
|
||||||
# Run client
|
# Run client
|
||||||
./client -s <server>:7000 -t <token> -id <client-id>
|
./client -s <server>:7000 -t <token>
|
||||||
./client -s <server>:7000 -t <token> -id <client-id> -no-tls # disable TLS
|
|
||||||
|
|
||||||
# Web UI development (in web/ directory)
|
# Web UI development (in web/ directory)
|
||||||
cd web && npm install && npm run dev # development server
|
cd web && npm install && npm run dev # development server
|
||||||
@@ -61,13 +60,7 @@ pkg/
|
|||||||
├── auth/ # JWT authentication
|
├── auth/ # JWT authentication
|
||||||
├── utils/ # Port availability checking
|
├── utils/ # Port availability checking
|
||||||
├── version/ # Version info and update checking (Gitea API)
|
├── version/ # Version info and update checking (Gitea API)
|
||||||
├── update/ # Shared update logic (download, extract tar.gz/zip)
|
└── update/ # Shared update logic (download, extract tar.gz/zip)
|
||||||
└── plugin/ # Plugin system core
|
|
||||||
├── types.go # Plugin interfaces
|
|
||||||
├── registry.go # Plugin registry
|
|
||||||
├── script/ # JS plugin runtime (goja)
|
|
||||||
├── sign/ # Plugin signature verification
|
|
||||||
└── store/ # Plugin persistence (SQLite)
|
|
||||||
web/ # Vue 3 + TypeScript frontend (Vite + naive-ui)
|
web/ # Vue 3 + TypeScript frontend (Vite + naive-ui)
|
||||||
scripts/ # Build scripts (build.sh, build.ps1)
|
scripts/ # Build scripts (build.sh, build.ps1)
|
||||||
```
|
```
|
||||||
@@ -75,23 +68,16 @@ scripts/ # Build scripts (build.sh, build.ps1)
|
|||||||
### Key Interfaces
|
### Key Interfaces
|
||||||
|
|
||||||
- `ClientStore` (internal/server/db/): Database abstraction for client rules storage
|
- `ClientStore` (internal/server/db/): Database abstraction for client rules storage
|
||||||
- `JSPluginStore` (internal/server/db/): JS plugin persistence
|
|
||||||
- `ServerInterface` (internal/server/router/handler/): API handler interface
|
- `ServerInterface` (internal/server/router/handler/): API handler interface
|
||||||
- `ClientPlugin` (pkg/plugin/): Plugin interface for client-side plugins
|
|
||||||
|
|
||||||
### Proxy Types
|
### Proxy Types
|
||||||
|
|
||||||
**内置类型** (直接在 tunnel 中处理):
|
|
||||||
1. **TCP** (default): Direct port forwarding (remote_port → local_ip:local_port)
|
1. **TCP** (default): Direct port forwarding (remote_port → local_ip:local_port)
|
||||||
2. **UDP**: UDP port forwarding
|
2. **UDP**: UDP port forwarding
|
||||||
3. **HTTP**: HTTP proxy through client network
|
3. **HTTP**: HTTP proxy through client network
|
||||||
4. **HTTPS**: HTTPS proxy through client network
|
4. **HTTPS**: HTTPS proxy through client network
|
||||||
5. **SOCKS5**: SOCKS5 proxy through client network
|
5. **SOCKS5**: SOCKS5 proxy through client network
|
||||||
|
|
||||||
**JS 插件类型** (通过 goja 运行时):
|
|
||||||
- Custom application plugins (file-server, api-server, etc.)
|
|
||||||
- Runs on client side with sandbox restrictions
|
|
||||||
|
|
||||||
### Data Flow
|
### Data Flow
|
||||||
|
|
||||||
External User → Server Port → Yamux Stream → Client → Local Service
|
External User → Server Port → Yamux Stream → Client → Local Service
|
||||||
@@ -99,47 +85,9 @@ External User → Server Port → Yamux Stream → Client → Local Service
|
|||||||
### Configuration
|
### Configuration
|
||||||
|
|
||||||
- Server: YAML config + SQLite database for client rules and JS plugins
|
- Server: YAML config + SQLite database for client rules and JS plugins
|
||||||
- Client: Command-line flags only (server address, token, client ID)
|
- Client: Command-line flags only (server address, token)
|
||||||
- Default ports: 7000 (tunnel), 7500 (web console)
|
- Default ports: 7000 (tunnel), 7500 (web console)
|
||||||
|
|
||||||
## Plugin System
|
|
||||||
|
|
||||||
GoTunnel supports a JavaScript-based plugin system using the goja runtime.
|
|
||||||
|
|
||||||
### Plugin Architecture
|
|
||||||
|
|
||||||
- **内置协议**: tcp, udp, http, https, socks5 直接在 tunnel 代码中处理
|
|
||||||
- **JS Plugins**: 自定义应用插件通过 goja 运行时在客户端执行
|
|
||||||
- **Plugin Store**: 从官方商店浏览和安装插件
|
|
||||||
- **Signature Verification**: 插件需要签名验证才能运行
|
|
||||||
|
|
||||||
### JS Plugin Lifecycle
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
function metadata() {
|
|
||||||
return {
|
|
||||||
name: "plugin-name",
|
|
||||||
version: "1.0.0",
|
|
||||||
type: "app",
|
|
||||||
description: "Plugin description",
|
|
||||||
author: "Author"
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function start() { /* called on plugin start */ }
|
|
||||||
function handleConn(conn) { /* handle each connection */ }
|
|
||||||
function stop() { /* called on plugin stop */ }
|
|
||||||
```
|
|
||||||
|
|
||||||
### Plugin APIs
|
|
||||||
|
|
||||||
- **Basic**: `log()`, `config()`
|
|
||||||
- **Connection**: `conn.Read()`, `conn.Write()`, `conn.Close()`
|
|
||||||
- **File System**: `fs.readFile()`, `fs.writeFile()`, `fs.readDir()`, `fs.stat()`, etc.
|
|
||||||
- **HTTP**: `http.serve()`, `http.json()`, `http.sendFile()`
|
|
||||||
|
|
||||||
See `PLUGINS.md` for detailed plugin development documentation.
|
|
||||||
|
|
||||||
## API Documentation
|
## API Documentation
|
||||||
|
|
||||||
The server provides Swagger-documented REST APIs at `/api/`.
|
The server provides Swagger-documented REST APIs at `/api/`.
|
||||||
|
|||||||
645
PLUGINS.md
645
PLUGINS.md
@@ -1,645 +0,0 @@
|
|||||||
# GoTunnel 插件开发指南
|
|
||||||
|
|
||||||
本文档介绍如何为 GoTunnel 开发 JS 插件。JS 插件基于 [goja](https://github.com/dop251/goja) 运行时,运行在客户端上。
|
|
||||||
|
|
||||||
## 目录
|
|
||||||
|
|
||||||
- [快速开始](#快速开始)
|
|
||||||
- [插件结构](#插件结构)
|
|
||||||
- [API 参考](#api-参考)
|
|
||||||
- [示例插件](#示例插件)
|
|
||||||
- [插件签名](#插件签名)
|
|
||||||
- [发布到商店](#发布到商店)
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 快速开始
|
|
||||||
|
|
||||||
### 最小插件示例
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
// 必须:定义插件元数据
|
|
||||||
function metadata() {
|
|
||||||
return {
|
|
||||||
name: "my-plugin",
|
|
||||||
version: "1.0.0",
|
|
||||||
type: "app",
|
|
||||||
description: "My first plugin",
|
|
||||||
author: "Your Name"
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// 可选:插件启动时调用
|
|
||||||
function start() {
|
|
||||||
log("Plugin started");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 必须:处理连接
|
|
||||||
function handleConn(conn) {
|
|
||||||
// 处理连接逻辑
|
|
||||||
conn.Close();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 可选:插件停止时调用
|
|
||||||
function stop() {
|
|
||||||
log("Plugin stopped");
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 插件结构
|
|
||||||
|
|
||||||
### 生命周期函数
|
|
||||||
|
|
||||||
| 函数 | 必须 | 说明 |
|
|
||||||
|------|------|------|
|
|
||||||
| `metadata()` | 否 | 返回插件元数据,不定义则使用默认值 |
|
|
||||||
| `start()` | 否 | 插件启动时调用 |
|
|
||||||
| `handleConn(conn)` | 是 | 处理每个连接 |
|
|
||||||
| `stop()` | 否 | 插件停止时调用 |
|
|
||||||
|
|
||||||
### 元数据字段
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
function metadata() {
|
|
||||||
return {
|
|
||||||
name: "plugin-name", // 插件名称
|
|
||||||
version: "1.0.0", // 版本号
|
|
||||||
type: "app", // 类型: "app" (应用插件)
|
|
||||||
description: "描述", // 插件描述
|
|
||||||
author: "作者" // 作者名称
|
|
||||||
};
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## API 参考
|
|
||||||
|
|
||||||
### 基础 API
|
|
||||||
|
|
||||||
#### `log(message)`
|
|
||||||
|
|
||||||
输出日志信息。
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
log("Hello, World!");
|
|
||||||
// 输出: [JS:plugin-name] Hello, World!
|
|
||||||
```
|
|
||||||
|
|
||||||
#### `config(key)`
|
|
||||||
|
|
||||||
获取插件配置值。
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
var port = config("port");
|
|
||||||
var host = config("host") || "127.0.0.1";
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### 连接 API (conn)
|
|
||||||
|
|
||||||
`handleConn` 函数接收的 `conn` 对象提供以下方法:
|
|
||||||
|
|
||||||
#### `conn.Read(size)`
|
|
||||||
|
|
||||||
读取数据,返回字节数组,失败返回 `null`。
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
var data = conn.Read(1024);
|
|
||||||
if (data) {
|
|
||||||
log("Received " + data.length + " bytes");
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
#### `conn.Write(data)`
|
|
||||||
|
|
||||||
写入数据,返回写入的字节数。
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
var written = conn.Write(data);
|
|
||||||
log("Wrote " + written + " bytes");
|
|
||||||
```
|
|
||||||
|
|
||||||
#### `conn.Close()`
|
|
||||||
|
|
||||||
关闭连接。
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
conn.Close();
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### 文件系统 API (fs)
|
|
||||||
|
|
||||||
所有文件操作都在沙箱中执行,有路径和大小限制。
|
|
||||||
|
|
||||||
#### `fs.readFile(path)`
|
|
||||||
|
|
||||||
读取文件内容。
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
var result = fs.readFile("/path/to/file.txt");
|
|
||||||
if (result.error) {
|
|
||||||
log("Error: " + result.error);
|
|
||||||
} else {
|
|
||||||
log("Content: " + result.data);
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
#### `fs.writeFile(path, content)`
|
|
||||||
|
|
||||||
写入文件内容。
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
var result = fs.writeFile("/path/to/file.txt", "Hello");
|
|
||||||
if (result.ok) {
|
|
||||||
log("File written");
|
|
||||||
} else {
|
|
||||||
log("Error: " + result.error);
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
#### `fs.readDir(path)`
|
|
||||||
|
|
||||||
读取目录内容。
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
var result = fs.readDir("/path/to/dir");
|
|
||||||
if (!result.error) {
|
|
||||||
for (var i = 0; i < result.entries.length; i++) {
|
|
||||||
var entry = result.entries[i];
|
|
||||||
log(entry.name + " - " + (entry.isDir ? "DIR" : entry.size + " bytes"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
#### `fs.stat(path)`
|
|
||||||
|
|
||||||
获取文件信息。
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
var result = fs.stat("/path/to/file");
|
|
||||||
if (!result.error) {
|
|
||||||
log("Name: " + result.name);
|
|
||||||
log("Size: " + result.size);
|
|
||||||
log("IsDir: " + result.isDir);
|
|
||||||
log("ModTime: " + result.modTime);
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
#### `fs.exists(path)`
|
|
||||||
|
|
||||||
检查文件是否存在。
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
var result = fs.exists("/path/to/file");
|
|
||||||
if (result.exists) {
|
|
||||||
log("File exists");
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
#### `fs.mkdir(path)`
|
|
||||||
|
|
||||||
创建目录。
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
var result = fs.mkdir("/path/to/new/dir");
|
|
||||||
if (result.ok) {
|
|
||||||
log("Directory created");
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
#### `fs.remove(path)`
|
|
||||||
|
|
||||||
删除文件或目录。
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
var result = fs.remove("/path/to/file");
|
|
||||||
if (result.ok) {
|
|
||||||
log("Removed");
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### HTTP API (http)
|
|
||||||
|
|
||||||
用于构建简单的 HTTP 服务。
|
|
||||||
|
|
||||||
#### `http.serve(conn, handler)`
|
|
||||||
|
|
||||||
处理 HTTP 请求。
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
function handleConn(conn) {
|
|
||||||
http.serve(conn, function(req) {
|
|
||||||
return {
|
|
||||||
status: 200,
|
|
||||||
contentType: "application/json",
|
|
||||||
body: http.json({ message: "Hello", path: req.path })
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
**请求对象 (req):**
|
|
||||||
|
|
||||||
| 字段 | 类型 | 说明 |
|
|
||||||
|------|------|------|
|
|
||||||
| `method` | string | HTTP 方法 (GET, POST, etc.) |
|
|
||||||
| `path` | string | 请求路径 |
|
|
||||||
| `body` | string | 请求体 |
|
|
||||||
|
|
||||||
**响应对象:**
|
|
||||||
|
|
||||||
| 字段 | 类型 | 说明 |
|
|
||||||
|------|------|------|
|
|
||||||
| `status` | number | HTTP 状态码 (默认 200) |
|
|
||||||
| `contentType` | string | Content-Type (默认 application/json) |
|
|
||||||
| `body` | string | 响应体 |
|
|
||||||
|
|
||||||
#### `http.json(data)`
|
|
||||||
|
|
||||||
将对象序列化为 JSON 字符串。
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
var jsonStr = http.json({ name: "test", value: 123 });
|
|
||||||
// 返回: '{"name":"test","value":123}'
|
|
||||||
```
|
|
||||||
|
|
||||||
#### `http.sendFile(conn, filePath)`
|
|
||||||
|
|
||||||
发送文件作为 HTTP 响应。
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
function handleConn(conn) {
|
|
||||||
http.sendFile(conn, "/path/to/index.html");
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### 增强 API (Enhanced APIs)
|
|
||||||
|
|
||||||
GoTunnel v2.0+ 提供了更多强大的 API 能力。
|
|
||||||
|
|
||||||
#### `logger` (日志)
|
|
||||||
|
|
||||||
推荐使用结构化日志替代简单的 `log()`。
|
|
||||||
|
|
||||||
- `logger.info(msg)`
|
|
||||||
- `logger.warn(msg)`
|
|
||||||
- `logger.error(msg)`
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
logger.info("Server started");
|
|
||||||
logger.error("Connection failed");
|
|
||||||
```
|
|
||||||
|
|
||||||
#### `config` (配置)
|
|
||||||
|
|
||||||
增强的配置获取方式。
|
|
||||||
|
|
||||||
- `config.get(key)`: 获取配置值
|
|
||||||
- `config.getAll()`: 获取所有配置
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
var all = config.getAll();
|
|
||||||
var port = config.get("port");
|
|
||||||
```
|
|
||||||
|
|
||||||
#### `storage` (持久化存储)
|
|
||||||
|
|
||||||
简单的 Key-Value 存储,数据保存在客户端本地。
|
|
||||||
|
|
||||||
- `storage.get(key, default)`
|
|
||||||
- `storage.set(key, value)`
|
|
||||||
- `storage.delete(key)`
|
|
||||||
- `storage.keys()`
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
storage.set("last_run", Date.now());
|
|
||||||
var last = storage.get("last_run", 0);
|
|
||||||
```
|
|
||||||
|
|
||||||
#### `event` (事件总线)
|
|
||||||
|
|
||||||
插件内部或插件间的事件通信。
|
|
||||||
|
|
||||||
- `event.on(name, callback)`
|
|
||||||
- `event.emit(name, data)`
|
|
||||||
- `event.off(name)`
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
event.on("user_login", function(user) {
|
|
||||||
logger.info("User logged in: " + user);
|
|
||||||
});
|
|
||||||
event.emit("user_login", "admin");
|
|
||||||
```
|
|
||||||
|
|
||||||
#### `request` (HTTP 请求)
|
|
||||||
|
|
||||||
发起外部 HTTP 请求。
|
|
||||||
|
|
||||||
- `request.get(url)`
|
|
||||||
- `request.post(url, contentType, body)`
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
var res = request.get("https://api.ipify.org");
|
|
||||||
logger.info("My IP: " + res.body);
|
|
||||||
```
|
|
||||||
|
|
||||||
#### `notify` (通知)
|
|
||||||
|
|
||||||
发送系统通知。
|
|
||||||
|
|
||||||
- `notify.send(title, message)`
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
notify.send("Download Complete", "File saved to disk");
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 示例插件
|
|
||||||
|
|
||||||
### Echo 服务
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
function metadata() {
|
|
||||||
return {
|
|
||||||
name: "echo",
|
|
||||||
version: "1.0.0",
|
|
||||||
type: "app",
|
|
||||||
description: "Echo back received data"
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleConn(conn) {
|
|
||||||
while (true) {
|
|
||||||
var data = conn.Read(4096);
|
|
||||||
if (!data || data.length === 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
conn.Write(data);
|
|
||||||
}
|
|
||||||
conn.Close();
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### HTTP 文件服务器
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
function metadata() {
|
|
||||||
return {
|
|
||||||
name: "file-server",
|
|
||||||
version: "1.0.0",
|
|
||||||
type: "app",
|
|
||||||
description: "Simple HTTP file server"
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
var rootDir = "";
|
|
||||||
|
|
||||||
function start() {
|
|
||||||
rootDir = config("root") || "/tmp";
|
|
||||||
log("Serving files from: " + rootDir);
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleConn(conn) {
|
|
||||||
http.serve(conn, function(req) {
|
|
||||||
if (req.method === "GET") {
|
|
||||||
var filePath = rootDir + req.path;
|
|
||||||
if (req.path === "/") {
|
|
||||||
filePath = rootDir + "/index.html";
|
|
||||||
}
|
|
||||||
|
|
||||||
var stat = fs.stat(filePath);
|
|
||||||
if (stat.error) {
|
|
||||||
return { status: 404, body: "Not Found" };
|
|
||||||
}
|
|
||||||
|
|
||||||
if (stat.isDir) {
|
|
||||||
return listDirectory(filePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
var file = fs.readFile(filePath);
|
|
||||||
if (file.error) {
|
|
||||||
return { status: 500, body: file.error };
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
status: 200,
|
|
||||||
contentType: "text/html",
|
|
||||||
body: file.data
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return { status: 405, body: "Method Not Allowed" };
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function listDirectory(path) {
|
|
||||||
var result = fs.readDir(path);
|
|
||||||
if (result.error) {
|
|
||||||
return { status: 500, body: result.error };
|
|
||||||
}
|
|
||||||
|
|
||||||
var html = "<html><body><h1>Directory Listing</h1><ul>";
|
|
||||||
for (var i = 0; i < result.entries.length; i++) {
|
|
||||||
var e = result.entries[i];
|
|
||||||
html += "<li><a href='" + e.name + "'>" + e.name + "</a></li>";
|
|
||||||
}
|
|
||||||
html += "</ul></body></html>";
|
|
||||||
|
|
||||||
return { status: 200, contentType: "text/html", body: html };
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### JSON API 服务
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
function metadata() {
|
|
||||||
return {
|
|
||||||
name: "api-server",
|
|
||||||
version: "1.0.0",
|
|
||||||
type: "app",
|
|
||||||
description: "JSON API server"
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
var counter = 0;
|
|
||||||
|
|
||||||
function handleConn(conn) {
|
|
||||||
http.serve(conn, function(req) {
|
|
||||||
if (req.path === "/api/status") {
|
|
||||||
return {
|
|
||||||
status: 200,
|
|
||||||
body: http.json({
|
|
||||||
status: "ok",
|
|
||||||
counter: counter++,
|
|
||||||
timestamp: Date.now()
|
|
||||||
})
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (req.path === "/api/echo" && req.method === "POST") {
|
|
||||||
return {
|
|
||||||
status: 200,
|
|
||||||
body: http.json({
|
|
||||||
received: req.body
|
|
||||||
})
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
status: 404,
|
|
||||||
body: http.json({ error: "Not Found" })
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 插件签名
|
|
||||||
|
|
||||||
为了安全,JS 插件需要官方签名才能运行。
|
|
||||||
|
|
||||||
### 签名格式
|
|
||||||
|
|
||||||
签名文件 (`.sig`) 包含 Base64 编码的签名数据:
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"payload": {
|
|
||||||
"name": "plugin-name",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"checksum": "sha256-hash",
|
|
||||||
"key_id": "official-v1"
|
|
||||||
},
|
|
||||||
"signature": "base64-signature"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 获取签名
|
|
||||||
|
|
||||||
1. 提交插件到官方仓库
|
|
||||||
2. 通过审核后获得签名
|
|
||||||
3. 将 `.js` 和 `.sig` 文件一起分发
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 发布到商店
|
|
||||||
|
|
||||||
### 商店 JSON 格式
|
|
||||||
|
|
||||||
插件商店使用 `store.json` 文件索引所有插件:
|
|
||||||
|
|
||||||
```json
|
|
||||||
[
|
|
||||||
{
|
|
||||||
"name": "echo",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"type": "app",
|
|
||||||
"description": "Echo service plugin",
|
|
||||||
"author": "GoTunnel",
|
|
||||||
"icon": "https://example.com/icon.png",
|
|
||||||
"download_url": "https://example.com/plugins/echo.js"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
```
|
|
||||||
|
|
||||||
### 提交流程
|
|
||||||
|
|
||||||
1. Fork 官方插件仓库
|
|
||||||
2. 添加插件文件到 `plugins/` 目录
|
|
||||||
3. 更新 `store.json`
|
|
||||||
4. 提交 Pull Request
|
|
||||||
5. 等待审核和签名
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 沙箱限制
|
|
||||||
|
|
||||||
为了安全,JS 插件运行在沙箱环境中:
|
|
||||||
|
|
||||||
| 限制项 | 默认值 |
|
|
||||||
|--------|--------|
|
|
||||||
| 最大读取文件大小 | 10 MB |
|
|
||||||
| 最大写入文件大小 | 10 MB |
|
|
||||||
| 允许读取路径 | 插件数据目录 |
|
|
||||||
| 允许写入路径 | 插件数据目录 |
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 调试技巧
|
|
||||||
|
|
||||||
### 日志输出
|
|
||||||
|
|
||||||
使用 `log()` 函数输出调试信息:
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
log("Debug: variable = " + JSON.stringify(variable));
|
|
||||||
```
|
|
||||||
|
|
||||||
### 错误处理
|
|
||||||
|
|
||||||
始终检查 API 返回的错误:
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
var result = fs.readFile(path);
|
|
||||||
if (result.error) {
|
|
||||||
log("Error reading file: " + result.error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 配置测试
|
|
||||||
|
|
||||||
在 Web 控制台的插件管理页面安装并配置插件,或通过 API 安装:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# 安装 JS 插件到客户端
|
|
||||||
POST /api/client/{id}/plugin/js/install
|
|
||||||
Content-Type: application/json
|
|
||||||
{
|
|
||||||
"plugin_name": "my-plugin",
|
|
||||||
"source": "function metadata() {...}",
|
|
||||||
"rule_name": "my-rule",
|
|
||||||
"remote_port": 8080,
|
|
||||||
"config": {"debug": "true"},
|
|
||||||
"auto_start": true
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 常见问题
|
|
||||||
|
|
||||||
**Q: 插件无法加载?**
|
|
||||||
|
|
||||||
A: 检查签名文件是否存在且有效。
|
|
||||||
|
|
||||||
**Q: 文件操作失败?**
|
|
||||||
|
|
||||||
A: 确认路径在沙箱允许范围内。
|
|
||||||
|
|
||||||
**Q: 如何获取客户端 IP?**
|
|
||||||
|
|
||||||
A: 目前 API 不支持,计划在后续版本添加。
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 更新日志
|
|
||||||
|
|
||||||
### v1.0.0
|
|
||||||
|
|
||||||
- 初始版本
|
|
||||||
- 支持基础 API: log, config
|
|
||||||
- 支持连接 API: Read, Write, Close
|
|
||||||
- 支持文件系统 API: fs.*
|
|
||||||
- 支持 HTTP API: http.*
|
|
||||||
18
README.md
18
README.md
@@ -17,7 +17,7 @@ GoTunnel 是一个类似 frp 的内网穿透解决方案,核心特点是**服
|
|||||||
| TLS 证书 | 自动生成,零配置 | 需手动配置 |
|
| TLS 证书 | 自动生成,零配置 | 需手动配置 |
|
||||||
| 管理界面 | 内置 Web 控制台 (naive-ui) | 需额外部署 Dashboard |
|
| 管理界面 | 内置 Web 控制台 (naive-ui) | 需额外部署 Dashboard |
|
||||||
| 客户端部署 | 仅需 2 个参数 | 需配置文件 |
|
| 客户端部署 | 仅需 2 个参数 | 需配置文件 |
|
||||||
| 客户端 ID | 可选,服务端自动分配 | 需手动配置 |
|
| 客户端 ID | 自动根据设备标识计算 | 需手动配置 |
|
||||||
|
|
||||||
### 架构设计
|
### 架构设计
|
||||||
|
|
||||||
@@ -111,14 +111,9 @@ go build -o client ./cmd/client
|
|||||||
### 客户端启动
|
### 客户端启动
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# 最简启动(ID 由服务端自动分配)
|
# 最简启动(ID 由客户端根据设备标识自动计算)
|
||||||
./client -s <服务器IP>:7000 -t <Token>
|
./client -s <服务器IP>:7000 -t <Token>
|
||||||
|
|
||||||
# 指定客户端 ID
|
|
||||||
./client -s <服务器IP>:7000 -t <Token> -id <客户端ID>
|
|
||||||
|
|
||||||
# 禁用 TLS(需服务端也禁用)
|
|
||||||
./client -s <服务器IP>:7000 -t <Token> -no-tls
|
|
||||||
```
|
```
|
||||||
|
|
||||||
**参数说明:**
|
**参数说明:**
|
||||||
@@ -127,9 +122,6 @@ go build -o client ./cmd/client
|
|||||||
|------|------|------|
|
|------|------|------|
|
||||||
| `-s` | 服务器地址 (ip:port) | 是 |
|
| `-s` | 服务器地址 (ip:port) | 是 |
|
||||||
| `-t` | 认证 Token | 是 |
|
| `-t` | 认证 Token | 是 |
|
||||||
| `-id` | 客户端 ID | 否(服务端自动分配) |
|
|
||||||
| `-no-tls` | 禁用 TLS 加密 | 否 |
|
|
||||||
| `-skip-verify` | 跳过证书验证(不安全,仅测试用) | 否 |
|
|
||||||
|
|
||||||
## 配置系统
|
## 配置系统
|
||||||
|
|
||||||
@@ -388,7 +380,7 @@ curl -X POST http://server:7500/api/clients \
|
|||||||
-d '{"id":"home","rules":[{"name":"web","type":"tcp","local_ip":"127.0.0.1","local_port":80,"remote_port":8080}]}'
|
-d '{"id":"home","rules":[{"name":"web","type":"tcp","local_ip":"127.0.0.1","local_port":80,"remote_port":8080}]}'
|
||||||
|
|
||||||
# 客户端连接
|
# 客户端连接
|
||||||
./client -s server:7000 -t <token> -id home
|
./client -s server:7000 -t <token>
|
||||||
|
|
||||||
# 访问:http://server:8080 -> 内网 127.0.0.1:80
|
# 访问:http://server:8080 -> 内网 127.0.0.1:80
|
||||||
```
|
```
|
||||||
@@ -411,7 +403,7 @@ A: 在 Web 控制台点击客户端详情,进入编辑模式即可设置昵称
|
|||||||
|
|
||||||
**Q: 如何禁用 TLS?**
|
**Q: 如何禁用 TLS?**
|
||||||
|
|
||||||
A: 服务端配置 `tls_disabled: true`,客户端使用 `-no-tls` 参数。
|
A: 客户端命令行默认使用 TLS;如需兼容旧的非 TLS 部署,请改用客户端配置文件中的 `no_tls: true`。
|
||||||
|
|
||||||
**Q: 端口被占用怎么办?**
|
**Q: 端口被占用怎么办?**
|
||||||
|
|
||||||
@@ -419,7 +411,7 @@ A: 服务端会自动检测端口冲突,请检查日志并更换端口。
|
|||||||
|
|
||||||
**Q: 客户端 ID 是如何分配的?**
|
**Q: 客户端 ID 是如何分配的?**
|
||||||
|
|
||||||
A: 如果客户端未指定 `-id` 参数,服务端会自动生成 16 位随机 ID。
|
A: 客户端会把系统机器 ID、全部可用 MAC、主机名和网卡名等稳定标识组合后再进行哈希,得到固定客户端 ID;服务端不再为客户端分配或修正 ID。
|
||||||
|
|
||||||
**Q: 如何更新服务端/客户端?**
|
**Q: 如何更新服务端/客户端?**
|
||||||
|
|
||||||
|
|||||||
@@ -7,14 +7,22 @@ import (
|
|||||||
"github.com/gotunnel/internal/client/config"
|
"github.com/gotunnel/internal/client/config"
|
||||||
"github.com/gotunnel/internal/client/tunnel"
|
"github.com/gotunnel/internal/client/tunnel"
|
||||||
"github.com/gotunnel/pkg/crypto"
|
"github.com/gotunnel/pkg/crypto"
|
||||||
"github.com/gotunnel/pkg/plugin"
|
"github.com/gotunnel/pkg/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// 版本信息(通过 ldflags 注入)
|
||||||
|
var Version string
|
||||||
|
var BuildTime string
|
||||||
|
var GitCommit string
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
version.SetVersion(Version)
|
||||||
|
version.SetBuildInfo(GitCommit, BuildTime)
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
server := flag.String("s", "", "server address (ip:port)")
|
server := flag.String("s", "", "server address (ip:port)")
|
||||||
token := flag.String("t", "", "auth token")
|
token := flag.String("t", "", "auth token")
|
||||||
id := flag.String("id", "", "client id (optional, auto-assigned if empty)")
|
|
||||||
noTLS := flag.Bool("no-tls", false, "disable TLS")
|
|
||||||
configPath := flag.String("c", "", "config file path")
|
configPath := flag.String("c", "", "config file path")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
@@ -37,18 +45,12 @@ func main() {
|
|||||||
if *token != "" {
|
if *token != "" {
|
||||||
cfg.Token = *token
|
cfg.Token = *token
|
||||||
}
|
}
|
||||||
if *id != "" {
|
|
||||||
cfg.ID = *id
|
|
||||||
}
|
|
||||||
if *noTLS {
|
|
||||||
cfg.NoTLS = *noTLS
|
|
||||||
}
|
|
||||||
|
|
||||||
if cfg.Server == "" || cfg.Token == "" {
|
if cfg.Server == "" || cfg.Token == "" {
|
||||||
log.Fatal("Usage: client [-c config.yaml] | [-s <server:port> -t <token> [-id <client_id>] [-no-tls]]")
|
log.Fatal("Usage: client [-c config.yaml] | [-s <server:port> -t <token>]")
|
||||||
}
|
}
|
||||||
|
|
||||||
client := tunnel.NewClient(cfg.Server, cfg.Token, cfg.ID)
|
client := tunnel.NewClient(cfg.Server, cfg.Token)
|
||||||
|
|
||||||
// TLS 默认启用,默认跳过证书验证(类似 frp)
|
// TLS 默认启用,默认跳过证书验证(类似 frp)
|
||||||
if !cfg.NoTLS {
|
if !cfg.NoTLS {
|
||||||
@@ -57,14 +59,5 @@ func main() {
|
|||||||
log.Printf("[Client] TLS enabled")
|
log.Printf("[Client] TLS enabled")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 初始化插件注册表(用于 JS 插件)
|
|
||||||
registry := plugin.NewRegistry()
|
|
||||||
client.SetPluginRegistry(registry)
|
|
||||||
|
|
||||||
// 初始化版本存储
|
|
||||||
if err := client.InitVersionStore(); err != nil {
|
|
||||||
log.Printf("[Client] Warning: failed to init version store: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
client.Run()
|
client.Run()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,10 +26,19 @@ import (
|
|||||||
"github.com/gotunnel/internal/server/db"
|
"github.com/gotunnel/internal/server/db"
|
||||||
"github.com/gotunnel/internal/server/tunnel"
|
"github.com/gotunnel/internal/server/tunnel"
|
||||||
"github.com/gotunnel/pkg/crypto"
|
"github.com/gotunnel/pkg/crypto"
|
||||||
"github.com/gotunnel/pkg/plugin"
|
"github.com/gotunnel/pkg/version"
|
||||||
"github.com/gotunnel/pkg/plugin/sign"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// 版本信息(通过 ldflags 注入)
|
||||||
|
var Version string
|
||||||
|
var BuildTime string
|
||||||
|
var GitCommit string
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
version.SetVersion(Version)
|
||||||
|
version.SetBuildInfo(GitCommit, BuildTime)
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
configPath := flag.String("c", "server.yaml", "config file path")
|
configPath := flag.String("c", "server.yaml", "config file path")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
@@ -70,23 +79,15 @@ func main() {
|
|||||||
log.Printf("[Server] TLS enabled")
|
log.Printf("[Server] TLS enabled")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 初始化插件系统(用于客户端 JS 插件管理)
|
// 设置流量存储,用于记录流量统计
|
||||||
registry := plugin.NewRegistry()
|
server.SetTrafficStore(clientStore)
|
||||||
server.SetPluginRegistry(registry)
|
|
||||||
server.SetJSPluginStore(clientStore) // 设置 JS 插件存储,用于客户端重连时恢复插件
|
|
||||||
|
|
||||||
// 加载 JS 插件配置
|
|
||||||
if len(cfg.JSPlugins) > 0 {
|
|
||||||
jsPlugins := loadJSPlugins(cfg.JSPlugins)
|
|
||||||
server.LoadJSPlugins(jsPlugins)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 启动 Web 控制台
|
// 启动 Web 控制台
|
||||||
if cfg.Web.Enabled {
|
if cfg.Server.Web.Enabled {
|
||||||
// 强制生成 Web 凭据(如果未配置)
|
// 强制生成 Web 凭据(如果未配置)
|
||||||
if config.GenerateWebCredentials(cfg) {
|
if config.GenerateWebCredentials(cfg) {
|
||||||
log.Printf("[Web] Auto-generated credentials - Username: %s, Password: %s",
|
log.Printf("[Web] Auto-generated credentials - Username: %s, Password: %s",
|
||||||
cfg.Web.Username, cfg.Web.Password)
|
cfg.Server.Web.Username, cfg.Server.Web.Password)
|
||||||
log.Printf("[Web] Please save these credentials and update your config file")
|
log.Printf("[Web] Please save these credentials and update your config file")
|
||||||
// 保存配置以持久化凭据
|
// 保存配置以持久化凭据
|
||||||
if err := config.SaveServerConfig(*configPath, cfg); err != nil {
|
if err := config.SaveServerConfig(*configPath, cfg); err != nil {
|
||||||
@@ -95,11 +96,11 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ws := app.NewWebServer(clientStore, server, cfg, *configPath, clientStore)
|
ws := app.NewWebServer(clientStore, server, cfg, *configPath, clientStore)
|
||||||
addr := fmt.Sprintf("%s:%d", cfg.Web.BindAddr, cfg.Web.BindPort)
|
addr := fmt.Sprintf("%s:%d", cfg.Server.BindAddr, cfg.Server.Web.BindPort)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
// 始终使用 JWT 认证
|
// 始终使用 JWT 认证
|
||||||
err := ws.RunWithJWT(addr, cfg.Web.Username, cfg.Web.Password, cfg.Server.Token)
|
err := ws.RunWithJWT(addr, cfg.Server.Web.Username, cfg.Server.Web.Password, cfg.Server.Token)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("[Web] Server error: %v", err)
|
log.Printf("[Web] Server error: %v", err)
|
||||||
}
|
}
|
||||||
@@ -120,69 +121,3 @@ func main() {
|
|||||||
|
|
||||||
log.Fatal(server.Run())
|
log.Fatal(server.Run())
|
||||||
}
|
}
|
||||||
|
|
||||||
// loadJSPlugins 加载 JS 插件文件
|
|
||||||
func loadJSPlugins(configs []config.JSPluginConfig) []tunnel.JSPluginEntry {
|
|
||||||
var plugins []tunnel.JSPluginEntry
|
|
||||||
|
|
||||||
for _, cfg := range configs {
|
|
||||||
source, err := os.ReadFile(cfg.Path)
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("[JSPlugin] Failed to load %s: %v", cfg.Path, err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// 加载签名文件
|
|
||||||
sigPath := cfg.SigPath
|
|
||||||
if sigPath == "" {
|
|
||||||
sigPath = cfg.Path + ".sig"
|
|
||||||
}
|
|
||||||
signature, err := os.ReadFile(sigPath)
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("[JSPlugin] Failed to load signature for %s: %v", cfg.Name, err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// 服务端也验证签名,防止配置文件被篡改
|
|
||||||
if err := verifyPluginSignature(cfg.Name, string(source), string(signature)); err != nil {
|
|
||||||
log.Printf("[JSPlugin] Signature verification failed for %s: %v", cfg.Name, err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
plugins = append(plugins, tunnel.JSPluginEntry{
|
|
||||||
Name: cfg.Name,
|
|
||||||
Source: string(source),
|
|
||||||
Signature: string(signature),
|
|
||||||
AutoPush: cfg.AutoPush,
|
|
||||||
Config: cfg.Config,
|
|
||||||
AutoStart: cfg.AutoStart,
|
|
||||||
})
|
|
||||||
|
|
||||||
log.Printf("[JSPlugin] Loaded: %s from %s (verified)", cfg.Name, cfg.Path)
|
|
||||||
}
|
|
||||||
|
|
||||||
return plugins
|
|
||||||
}
|
|
||||||
|
|
||||||
// verifyPluginSignature 验证插件签名
|
|
||||||
func verifyPluginSignature(name, source, signature string) error {
|
|
||||||
// 解码签名
|
|
||||||
signed, err := sign.DecodeSignedPlugin(signature)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("decode signature: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取公钥
|
|
||||||
pubKey, err := sign.GetPublicKeyByID(signed.Payload.KeyID)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// 验证插件名称
|
|
||||||
if signed.Payload.Name != name {
|
|
||||||
return fmt.Errorf("name mismatch: %s vs %s", signed.Payload.Name, name)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 验证签名
|
|
||||||
return sign.VerifyPlugin(pubKey, signed, source)
|
|
||||||
}
|
|
||||||
|
|||||||
45
go.mod
45
go.mod
@@ -3,31 +3,35 @@ module github.com/gotunnel
|
|||||||
go 1.24.0
|
go 1.24.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/gin-gonic/gin v1.11.0
|
||||||
|
github.com/go-playground/validator/v10 v10.30.1
|
||||||
github.com/golang-jwt/jwt/v5 v5.3.0
|
github.com/golang-jwt/jwt/v5 v5.3.0
|
||||||
|
github.com/google/uuid v1.6.0
|
||||||
|
github.com/gorilla/websocket v1.5.3
|
||||||
github.com/hashicorp/yamux v0.1.1
|
github.com/hashicorp/yamux v0.1.1
|
||||||
|
github.com/kbinani/screenshot v0.0.0-20250624051815-089614a94018
|
||||||
|
github.com/shirou/gopsutil/v3 v3.24.5
|
||||||
|
github.com/swaggo/files v1.0.1
|
||||||
|
github.com/swaggo/gin-swagger v1.6.1
|
||||||
|
github.com/swaggo/swag v1.16.6
|
||||||
gopkg.in/yaml.v3 v3.0.1
|
gopkg.in/yaml.v3 v3.0.1
|
||||||
modernc.org/sqlite v1.41.0
|
modernc.org/sqlite v1.41.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/KyleBanks/depth v1.2.1 // indirect
|
github.com/KyleBanks/depth v1.2.1 // indirect
|
||||||
github.com/PuerkitoBio/purell v1.2.1 // indirect
|
|
||||||
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
|
|
||||||
github.com/bytedance/gopkg v0.1.3 // indirect
|
github.com/bytedance/gopkg v0.1.3 // indirect
|
||||||
github.com/bytedance/sonic v1.14.2 // indirect
|
github.com/bytedance/sonic v1.14.2 // indirect
|
||||||
github.com/bytedance/sonic/loader v0.4.0 // indirect
|
github.com/bytedance/sonic/loader v0.4.0 // indirect
|
||||||
github.com/cloudwego/base64x v0.1.6 // indirect
|
github.com/cloudwego/base64x v0.1.6 // indirect
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.7 // indirect
|
|
||||||
github.com/dlclark/regexp2 v1.11.4 // indirect
|
|
||||||
github.com/dop251/goja v0.0.0-20251201205617-2bb4c724c0f9 // indirect
|
|
||||||
github.com/dustin/go-humanize v1.0.1 // indirect
|
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||||
github.com/gabriel-vasile/mimetype v1.4.12 // indirect
|
github.com/gabriel-vasile/mimetype v1.4.12 // indirect
|
||||||
|
github.com/gen2brain/shm v0.1.0 // indirect
|
||||||
github.com/gin-contrib/sse v1.1.0 // indirect
|
github.com/gin-contrib/sse v1.1.0 // indirect
|
||||||
github.com/gin-gonic/gin v1.11.0 // indirect
|
github.com/go-ole/go-ole v1.2.6 // indirect
|
||||||
github.com/go-openapi/jsonpointer v0.22.4 // indirect
|
github.com/go-openapi/jsonpointer v0.22.4 // indirect
|
||||||
github.com/go-openapi/jsonreference v0.21.4 // indirect
|
github.com/go-openapi/jsonreference v0.21.4 // indirect
|
||||||
github.com/go-openapi/spec v0.22.3 // indirect
|
github.com/go-openapi/spec v0.22.3 // indirect
|
||||||
github.com/go-openapi/swag v0.25.4 // indirect
|
|
||||||
github.com/go-openapi/swag/conv v0.25.4 // indirect
|
github.com/go-openapi/swag/conv v0.25.4 // indirect
|
||||||
github.com/go-openapi/swag/jsonname v0.25.4 // indirect
|
github.com/go-openapi/swag/jsonname v0.25.4 // indirect
|
||||||
github.com/go-openapi/swag/jsonutils v0.25.4 // indirect
|
github.com/go-openapi/swag/jsonutils v0.25.4 // indirect
|
||||||
@@ -37,37 +41,32 @@ require (
|
|||||||
github.com/go-openapi/swag/yamlutils v0.25.4 // indirect
|
github.com/go-openapi/swag/yamlutils v0.25.4 // indirect
|
||||||
github.com/go-playground/locales v0.14.1 // indirect
|
github.com/go-playground/locales v0.14.1 // indirect
|
||||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||||
github.com/go-playground/validator/v10 v10.30.1 // indirect
|
|
||||||
github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect
|
|
||||||
github.com/goccy/go-json v0.10.5 // indirect
|
github.com/goccy/go-json v0.10.5 // indirect
|
||||||
github.com/goccy/go-yaml v1.19.1 // indirect
|
github.com/goccy/go-yaml v1.19.1 // indirect
|
||||||
github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e // indirect
|
github.com/godbus/dbus/v5 v5.1.0 // indirect
|
||||||
github.com/google/uuid v1.6.0 // indirect
|
github.com/jezek/xgb v1.1.1 // indirect
|
||||||
github.com/gorilla/websocket v1.5.3 // indirect
|
|
||||||
github.com/josharian/intern v1.0.0 // indirect
|
|
||||||
github.com/json-iterator/go v1.1.12 // indirect
|
github.com/json-iterator/go v1.1.12 // indirect
|
||||||
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
|
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
|
||||||
|
github.com/kr/text v0.2.0 // indirect
|
||||||
github.com/leodido/go-urn v1.4.0 // indirect
|
github.com/leodido/go-urn v1.4.0 // indirect
|
||||||
github.com/mailru/easyjson v0.9.1 // indirect
|
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
|
||||||
|
github.com/lxn/win v0.0.0-20210218163916-a377121e959e // indirect
|
||||||
github.com/mattn/go-isatty v0.0.20 // 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/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||||
github.com/ncruces/go-strftime v0.1.9 // indirect
|
github.com/ncruces/go-strftime v0.1.9 // indirect
|
||||||
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
|
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
|
||||||
|
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
|
||||||
github.com/quic-go/qpack v0.6.0 // indirect
|
github.com/quic-go/qpack v0.6.0 // indirect
|
||||||
github.com/quic-go/quic-go v0.58.0 // indirect
|
github.com/quic-go/quic-go v0.58.0 // indirect
|
||||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
|
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
|
||||||
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
github.com/shoenig/go-m1cpu v0.1.7 // indirect
|
||||||
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
|
github.com/tklauser/go-sysconf v0.3.12 // indirect
|
||||||
github.com/swaggo/files v1.0.1 // indirect
|
github.com/tklauser/numcpus v0.6.1 // indirect
|
||||||
github.com/swaggo/gin-swagger v1.6.1 // indirect
|
|
||||||
github.com/swaggo/swag v1.16.6 // indirect
|
|
||||||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||||
github.com/ugorji/go/codec v1.3.1 // indirect
|
github.com/ugorji/go/codec v1.3.1 // indirect
|
||||||
github.com/urfave/cli/v2 v2.27.7 // indirect
|
github.com/yusufpapurcu/wmi v1.2.4 // indirect
|
||||||
github.com/xrash/smetrics v0.0.0-20250705151800-55b8f293f342 // indirect
|
|
||||||
go.uber.org/mock v0.6.0 // indirect
|
go.uber.org/mock v0.6.0 // indirect
|
||||||
go.yaml.in/yaml/v2 v2.4.3 // indirect
|
|
||||||
go.yaml.in/yaml/v3 v3.0.4 // indirect
|
go.yaml.in/yaml/v3 v3.0.4 // indirect
|
||||||
golang.org/x/arch v0.23.0 // indirect
|
golang.org/x/arch v0.23.0 // indirect
|
||||||
golang.org/x/crypto v0.46.0 // indirect
|
golang.org/x/crypto v0.46.0 // indirect
|
||||||
@@ -79,9 +78,7 @@ require (
|
|||||||
golang.org/x/text v0.32.0 // indirect
|
golang.org/x/text v0.32.0 // indirect
|
||||||
golang.org/x/tools v0.40.0 // indirect
|
golang.org/x/tools v0.40.0 // indirect
|
||||||
google.golang.org/protobuf v1.36.11 // indirect
|
google.golang.org/protobuf v1.36.11 // indirect
|
||||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
|
||||||
modernc.org/libc v1.66.10 // indirect
|
modernc.org/libc v1.66.10 // indirect
|
||||||
modernc.org/mathutil v1.7.1 // indirect
|
modernc.org/mathutil v1.7.1 // indirect
|
||||||
modernc.org/memory v1.11.0 // indirect
|
modernc.org/memory v1.11.0 // indirect
|
||||||
sigs.k8s.io/yaml v1.6.0 // indirect
|
|
||||||
)
|
)
|
||||||
|
|||||||
135
go.sum
135
go.sum
@@ -1,53 +1,46 @@
|
|||||||
github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc=
|
github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc=
|
||||||
github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE=
|
github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE=
|
||||||
github.com/PuerkitoBio/purell v1.2.1 h1:QsZ4TjvwiMpat6gBCBxEQI0rcS9ehtkKtSpiUnd9N28=
|
|
||||||
github.com/PuerkitoBio/purell v1.2.1/go.mod h1:ZwHcC/82TOaovDi//J/804umJFFmbOHPngi8iYYv/Eo=
|
|
||||||
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M=
|
|
||||||
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
|
|
||||||
github.com/bytedance/gopkg v0.1.3 h1:TPBSwH8RsouGCBcMBktLt1AymVo2TVsBVCY4b6TnZ/M=
|
github.com/bytedance/gopkg v0.1.3 h1:TPBSwH8RsouGCBcMBktLt1AymVo2TVsBVCY4b6TnZ/M=
|
||||||
github.com/bytedance/gopkg v0.1.3/go.mod h1:576VvJ+eJgyCzdjS+c4+77QF3p7ubbtiKARP3TxducM=
|
github.com/bytedance/gopkg v0.1.3/go.mod h1:576VvJ+eJgyCzdjS+c4+77QF3p7ubbtiKARP3TxducM=
|
||||||
github.com/bytedance/sonic v1.14.0 h1:/OfKt8HFw0kh2rj8N0F6C/qPGRESq0BbaNZgcNXXzQQ=
|
|
||||||
github.com/bytedance/sonic v1.14.0/go.mod h1:WoEbx8WTcFJfzCe0hbmyTGrfjt8PzNEBdxlNUO24NhA=
|
|
||||||
github.com/bytedance/sonic v1.14.2 h1:k1twIoe97C1DtYUo+fZQy865IuHia4PR5RPiuGPPIIE=
|
github.com/bytedance/sonic v1.14.2 h1:k1twIoe97C1DtYUo+fZQy865IuHia4PR5RPiuGPPIIE=
|
||||||
github.com/bytedance/sonic v1.14.2/go.mod h1:T80iDELeHiHKSc0C9tubFygiuXoGzrkjKzX2quAx980=
|
github.com/bytedance/sonic v1.14.2/go.mod h1:T80iDELeHiHKSc0C9tubFygiuXoGzrkjKzX2quAx980=
|
||||||
github.com/bytedance/sonic/loader v0.3.0 h1:dskwH8edlzNMctoruo8FPTJDF3vLtDT0sXZwvZJyqeA=
|
|
||||||
github.com/bytedance/sonic/loader v0.3.0/go.mod h1:N8A3vUdtUebEY2/VQC0MyhYeKUFosQU6FxH2JmUe6VI=
|
|
||||||
github.com/bytedance/sonic/loader v0.4.0 h1:olZ7lEqcxtZygCK9EKYKADnpQoYkRQxaeY2NYzevs+o=
|
github.com/bytedance/sonic/loader v0.4.0 h1:olZ7lEqcxtZygCK9EKYKADnpQoYkRQxaeY2NYzevs+o=
|
||||||
github.com/bytedance/sonic/loader v0.4.0/go.mod h1:AR4NYCk5DdzZizZ5djGqQ92eEhCCcdf5x77udYiSJRo=
|
github.com/bytedance/sonic/loader v0.4.0/go.mod h1:AR4NYCk5DdzZizZ5djGqQ92eEhCCcdf5x77udYiSJRo=
|
||||||
github.com/cloudwego/base64x v0.1.6 h1:t11wG9AECkCDk5fMSoxmufanudBtJ+/HemLstXDLI2M=
|
github.com/cloudwego/base64x v0.1.6 h1:t11wG9AECkCDk5fMSoxmufanudBtJ+/HemLstXDLI2M=
|
||||||
github.com/cloudwego/base64x v0.1.6/go.mod h1:OFcloc187FXDaYHvrNIjxSe8ncn0OOM8gEHfghB2IPU=
|
github.com/cloudwego/base64x v0.1.6/go.mod h1:OFcloc187FXDaYHvrNIjxSe8ncn0OOM8gEHfghB2IPU=
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.7 h1:zbFlGlXEAKlwXpmvle3d8Oe3YnkKIK4xSRTd3sHPnBo=
|
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.7/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
|
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
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/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/dlclark/regexp2 v1.11.4 h1:rPYF9/LECdNymJufQKmri9gV604RvvABwgOA8un7yAo=
|
|
||||||
github.com/dlclark/regexp2 v1.11.4/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
|
|
||||||
github.com/dop251/goja v0.0.0-20251201205617-2bb4c724c0f9 h1:3uSSOd6mVlwcX3k5OYOpiDqFgRmaE2dBfLvVIFWWHrw=
|
|
||||||
github.com/dop251/goja v0.0.0-20251201205617-2bb4c724c0f9/go.mod h1:MxLav0peU43GgvwVgNbLAj1s/bSGboKkhuULvq/7hx4=
|
|
||||||
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
|
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
|
||||||
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
|
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
|
||||||
github.com/gabriel-vasile/mimetype v1.4.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3GqacKw1NM=
|
|
||||||
github.com/gabriel-vasile/mimetype v1.4.8/go.mod h1:ByKUIKGjh1ODkGM1asKUbQZOLGrPjydw3hYPU2YU9t8=
|
|
||||||
github.com/gabriel-vasile/mimetype v1.4.12 h1:e9hWvmLYvtp846tLHam2o++qitpguFiYCKbn0w9jyqw=
|
github.com/gabriel-vasile/mimetype v1.4.12 h1:e9hWvmLYvtp846tLHam2o++qitpguFiYCKbn0w9jyqw=
|
||||||
github.com/gabriel-vasile/mimetype v1.4.12/go.mod h1:d+9Oxyo1wTzWdyVUPMmXFvp4F9tea18J8ufA774AB3s=
|
github.com/gabriel-vasile/mimetype v1.4.12/go.mod h1:d+9Oxyo1wTzWdyVUPMmXFvp4F9tea18J8ufA774AB3s=
|
||||||
|
github.com/gen2brain/shm v0.1.0 h1:MwPeg+zJQXN0RM9o+HqaSFypNoNEcNpeoGp0BTSx2YY=
|
||||||
|
github.com/gen2brain/shm v0.1.0/go.mod h1:UgIcVtvmOu+aCJpqJX7GOtiN7X2ct+TKLg4RTxwPIUA=
|
||||||
|
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 v1.1.0 h1:n0w2GMuUpWDVp7qSpvze6fAu9iRxJY4Hmj6AmBOU05w=
|
github.com/gin-contrib/sse v1.1.0 h1:n0w2GMuUpWDVp7qSpvze6fAu9iRxJY4Hmj6AmBOU05w=
|
||||||
github.com/gin-contrib/sse v1.1.0/go.mod h1:hxRZ5gVpWMT7Z0B0gSNYqqsSCNIJMjzvm6fqCz9vjwM=
|
github.com/gin-contrib/sse v1.1.0/go.mod h1:hxRZ5gVpWMT7Z0B0gSNYqqsSCNIJMjzvm6fqCz9vjwM=
|
||||||
github.com/gin-gonic/gin v1.11.0 h1:OW/6PLjyusp2PPXtyxKHU0RbX6I/l28FTdDlae5ueWk=
|
github.com/gin-gonic/gin v1.11.0 h1:OW/6PLjyusp2PPXtyxKHU0RbX6I/l28FTdDlae5ueWk=
|
||||||
github.com/gin-gonic/gin v1.11.0/go.mod h1:+iq/FyxlGzII0KHiBGjuNn4UNENUlKbGlNmc+W50Dls=
|
github.com/gin-gonic/gin v1.11.0/go.mod h1:+iq/FyxlGzII0KHiBGjuNn4UNENUlKbGlNmc+W50Dls=
|
||||||
|
github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
|
||||||
|
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
|
||||||
github.com/go-openapi/jsonpointer v0.22.4 h1:dZtK82WlNpVLDW2jlA1YCiVJFVqkED1MegOUy9kR5T4=
|
github.com/go-openapi/jsonpointer v0.22.4 h1:dZtK82WlNpVLDW2jlA1YCiVJFVqkED1MegOUy9kR5T4=
|
||||||
github.com/go-openapi/jsonpointer v0.22.4/go.mod h1:elX9+UgznpFhgBuaMQ7iu4lvvX1nvNsesQ3oxmYTw80=
|
github.com/go-openapi/jsonpointer v0.22.4/go.mod h1:elX9+UgznpFhgBuaMQ7iu4lvvX1nvNsesQ3oxmYTw80=
|
||||||
github.com/go-openapi/jsonreference v0.21.4 h1:24qaE2y9bx/q3uRK/qN+TDwbok1NhbSmGjjySRCHtC8=
|
github.com/go-openapi/jsonreference v0.21.4 h1:24qaE2y9bx/q3uRK/qN+TDwbok1NhbSmGjjySRCHtC8=
|
||||||
github.com/go-openapi/jsonreference v0.21.4/go.mod h1:rIENPTjDbLpzQmQWCj5kKj3ZlmEh+EFVbz3RTUh30/4=
|
github.com/go-openapi/jsonreference v0.21.4/go.mod h1:rIENPTjDbLpzQmQWCj5kKj3ZlmEh+EFVbz3RTUh30/4=
|
||||||
github.com/go-openapi/spec v0.22.3 h1:qRSmj6Smz2rEBxMnLRBMeBWxbbOvuOoElvSvObIgwQc=
|
github.com/go-openapi/spec v0.22.3 h1:qRSmj6Smz2rEBxMnLRBMeBWxbbOvuOoElvSvObIgwQc=
|
||||||
github.com/go-openapi/spec v0.22.3/go.mod h1:iIImLODL2loCh3Vnox8TY2YWYJZjMAKYyLH2Mu8lOZs=
|
github.com/go-openapi/spec v0.22.3/go.mod h1:iIImLODL2loCh3Vnox8TY2YWYJZjMAKYyLH2Mu8lOZs=
|
||||||
github.com/go-openapi/swag v0.25.4 h1:OyUPUFYDPDBMkqyxOTkqDYFnrhuhi9NR6QVUvIochMU=
|
github.com/go-openapi/swag v0.19.15 h1:D2NRCBzS9/pEY3gP9Nl8aDqGUcPFrwG2p+CNFrLyrCM=
|
||||||
github.com/go-openapi/swag v0.25.4/go.mod h1:zNfJ9WZABGHCFg2RnY0S4IOkAcVTzJ6z2Bi+Q4i6qFQ=
|
|
||||||
github.com/go-openapi/swag/conv v0.25.4 h1:/Dd7p0LZXczgUcC/Ikm1+YqVzkEeCc9LnOWjfkpkfe4=
|
github.com/go-openapi/swag/conv v0.25.4 h1:/Dd7p0LZXczgUcC/Ikm1+YqVzkEeCc9LnOWjfkpkfe4=
|
||||||
github.com/go-openapi/swag/conv v0.25.4/go.mod h1:3LXfie/lwoAv0NHoEuY1hjoFAYkvlqI/Bn5EQDD3PPU=
|
github.com/go-openapi/swag/conv v0.25.4/go.mod h1:3LXfie/lwoAv0NHoEuY1hjoFAYkvlqI/Bn5EQDD3PPU=
|
||||||
github.com/go-openapi/swag/jsonname v0.25.4 h1:bZH0+MsS03MbnwBXYhuTttMOqk+5KcQ9869Vye1bNHI=
|
github.com/go-openapi/swag/jsonname v0.25.4 h1:bZH0+MsS03MbnwBXYhuTttMOqk+5KcQ9869Vye1bNHI=
|
||||||
github.com/go-openapi/swag/jsonname v0.25.4/go.mod h1:GPVEk9CWVhNvWhZgrnvRA6utbAltopbKwDu8mXNUMag=
|
github.com/go-openapi/swag/jsonname v0.25.4/go.mod h1:GPVEk9CWVhNvWhZgrnvRA6utbAltopbKwDu8mXNUMag=
|
||||||
github.com/go-openapi/swag/jsonutils v0.25.4 h1:VSchfbGhD4UTf4vCdR2F4TLBdLwHyUDTd1/q4i+jGZA=
|
github.com/go-openapi/swag/jsonutils v0.25.4 h1:VSchfbGhD4UTf4vCdR2F4TLBdLwHyUDTd1/q4i+jGZA=
|
||||||
github.com/go-openapi/swag/jsonutils v0.25.4/go.mod h1:7OYGXpvVFPn4PpaSdPHJBtF0iGnbEaTk8AvBkoWnaAY=
|
github.com/go-openapi/swag/jsonutils v0.25.4/go.mod h1:7OYGXpvVFPn4PpaSdPHJBtF0iGnbEaTk8AvBkoWnaAY=
|
||||||
|
github.com/go-openapi/swag/jsonutils/fixtures_test v0.25.4 h1:IACsSvBhiNJwlDix7wq39SS2Fh7lUOCJRmx/4SN4sVo=
|
||||||
|
github.com/go-openapi/swag/jsonutils/fixtures_test v0.25.4/go.mod h1:Mt0Ost9l3cUzVv4OEZG+WSeoHwjWLnarzMePNDAOBiM=
|
||||||
github.com/go-openapi/swag/loading v0.25.4 h1:jN4MvLj0X6yhCDduRsxDDw1aHe+ZWoLjW+9ZQWIKn2s=
|
github.com/go-openapi/swag/loading v0.25.4 h1:jN4MvLj0X6yhCDduRsxDDw1aHe+ZWoLjW+9ZQWIKn2s=
|
||||||
github.com/go-openapi/swag/loading v0.25.4/go.mod h1:rpUM1ZiyEP9+mNLIQUdMiD7dCETXvkkC30z53i+ftTE=
|
github.com/go-openapi/swag/loading v0.25.4/go.mod h1:rpUM1ZiyEP9+mNLIQUdMiD7dCETXvkkC30z53i+ftTE=
|
||||||
github.com/go-openapi/swag/stringutils v0.25.4 h1:O6dU1Rd8bej4HPA3/CLPciNBBDwZj9HiEpdVsb8B5A8=
|
github.com/go-openapi/swag/stringutils v0.25.4 h1:O6dU1Rd8bej4HPA3/CLPciNBBDwZj9HiEpdVsb8B5A8=
|
||||||
@@ -56,26 +49,29 @@ github.com/go-openapi/swag/typeutils v0.25.4 h1:1/fbZOUN472NTc39zpa+YGHn3jzHWhv4
|
|||||||
github.com/go-openapi/swag/typeutils v0.25.4/go.mod h1:Ou7g//Wx8tTLS9vG0UmzfCsjZjKhpjxayRKTHXf2pTE=
|
github.com/go-openapi/swag/typeutils v0.25.4/go.mod h1:Ou7g//Wx8tTLS9vG0UmzfCsjZjKhpjxayRKTHXf2pTE=
|
||||||
github.com/go-openapi/swag/yamlutils v0.25.4 h1:6jdaeSItEUb7ioS9lFoCZ65Cne1/RZtPBZ9A56h92Sw=
|
github.com/go-openapi/swag/yamlutils v0.25.4 h1:6jdaeSItEUb7ioS9lFoCZ65Cne1/RZtPBZ9A56h92Sw=
|
||||||
github.com/go-openapi/swag/yamlutils v0.25.4/go.mod h1:MNzq1ulQu+yd8Kl7wPOut/YHAAU/H6hL91fF+E2RFwc=
|
github.com/go-openapi/swag/yamlutils v0.25.4/go.mod h1:MNzq1ulQu+yd8Kl7wPOut/YHAAU/H6hL91fF+E2RFwc=
|
||||||
|
github.com/go-openapi/testify/enable/yaml/v2 v2.0.2 h1:0+Y41Pz1NkbTHz8NngxTuAXxEodtNSI1WG1c/m5Akw4=
|
||||||
|
github.com/go-openapi/testify/enable/yaml/v2 v2.0.2/go.mod h1:kme83333GCtJQHXQ8UKX3IBZu6z8T5Dvy5+CW3NLUUg=
|
||||||
|
github.com/go-openapi/testify/v2 v2.0.2 h1:X999g3jeLcoY8qctY/c/Z8iBHTbwLz7R2WXd6Ub6wls=
|
||||||
|
github.com/go-openapi/testify/v2 v2.0.2/go.mod h1:HCPmvFFnheKK2BuwSA0TbbdxJ3I16pjwMkYkP4Ywn54=
|
||||||
|
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.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
|
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/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
|
||||||
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
|
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/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
|
||||||
github.com/go-playground/validator/v10 v10.27.0 h1:w8+XrWVMhGkxOaaowyKH35gFydVHOvC0/uWoy2Fzwn4=
|
|
||||||
github.com/go-playground/validator/v10 v10.27.0/go.mod h1:I5QpIEbmr8On7W0TktmJAumgzX4CA1XNl4ZmDuVHKKo=
|
|
||||||
github.com/go-playground/validator/v10 v10.30.1 h1:f3zDSN/zOma+w6+1Wswgd9fLkdwy06ntQJp0BBvFG0w=
|
github.com/go-playground/validator/v10 v10.30.1 h1:f3zDSN/zOma+w6+1Wswgd9fLkdwy06ntQJp0BBvFG0w=
|
||||||
github.com/go-playground/validator/v10 v10.30.1/go.mod h1:oSuBIQzuJxL//3MelwSLD5hc2Tu889bF0Idm9Dg26cM=
|
github.com/go-playground/validator/v10 v10.30.1/go.mod h1:oSuBIQzuJxL//3MelwSLD5hc2Tu889bF0Idm9Dg26cM=
|
||||||
github.com/go-sourcemap/sourcemap v2.1.3+incompatible h1:W1iEw64niKVGogNgBN3ePyLFfuisuzeidWPMPWmECqU=
|
|
||||||
github.com/go-sourcemap/sourcemap v2.1.3+incompatible/go.mod h1:F8jJfvm2KbVjc5NqelyYJmf/v5J0dwNLS2mL4sNA1Jg=
|
|
||||||
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/goccy/go-json v0.10.5 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4=
|
github.com/goccy/go-json v0.10.5 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4=
|
||||||
github.com/goccy/go-json v0.10.5/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
|
github.com/goccy/go-json v0.10.5/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
|
||||||
github.com/goccy/go-yaml v1.18.0 h1:8W7wMFS12Pcas7KU+VVkaiCng+kG8QiFeFwzFb+rwuw=
|
|
||||||
github.com/goccy/go-yaml v1.18.0/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA=
|
|
||||||
github.com/goccy/go-yaml v1.19.1 h1:3rG3+v8pkhRqoQ/88NYNMHYVGYztCOCIZ7UQhu7H+NE=
|
github.com/goccy/go-yaml v1.19.1 h1:3rG3+v8pkhRqoQ/88NYNMHYVGYztCOCIZ7UQhu7H+NE=
|
||||||
github.com/goccy/go-yaml v1.19.1/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA=
|
github.com/goccy/go-yaml v1.19.1/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA=
|
||||||
|
github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=
|
||||||
|
github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||||
github.com/golang-jwt/jwt/v5 v5.3.0 h1:pv4AsKCKKZuqlgs5sUmn4x8UlGa0kEVt/puTpKx9vvo=
|
github.com/golang-jwt/jwt/v5 v5.3.0 h1:pv4AsKCKKZuqlgs5sUmn4x8UlGa0kEVt/puTpKx9vvo=
|
||||||
github.com/golang-jwt/jwt/v5 v5.3.0/go.mod h1:fxCRLWMO43lRc8nhHWY6LGqRcf+1gQWArsqaEUEa5bE=
|
github.com/golang-jwt/jwt/v5 v5.3.0/go.mod h1:fxCRLWMO43lRc8nhHWY6LGqRcf+1gQWArsqaEUEa5bE=
|
||||||
|
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
|
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
||||||
|
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
||||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||||
github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e h1:ijClszYn+mADRFY17kjQEVQ1XRhq2/JR1M3sGqeJoxs=
|
github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e h1:ijClszYn+mADRFY17kjQEVQ1XRhq2/JR1M3sGqeJoxs=
|
||||||
github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e/go.mod h1:boTsfXsheKC2y+lKOCMpSfarhxDeIzfZG1jqGcPl3cA=
|
github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e/go.mod h1:boTsfXsheKC2y+lKOCMpSfarhxDeIzfZG1jqGcPl3cA=
|
||||||
@@ -85,19 +81,26 @@ github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aN
|
|||||||
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||||
github.com/hashicorp/yamux v0.1.1 h1:yrQxtgseBDrq9Y652vSRDvsKCJKOUD+GzTS4Y0Y8pvE=
|
github.com/hashicorp/yamux v0.1.1 h1:yrQxtgseBDrq9Y652vSRDvsKCJKOUD+GzTS4Y0Y8pvE=
|
||||||
github.com/hashicorp/yamux v0.1.1/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ=
|
github.com/hashicorp/yamux v0.1.1/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ=
|
||||||
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
|
github.com/jezek/xgb v1.1.1 h1:bE/r8ZZtSv7l9gk6nU0mYx51aXrvnyb44892TwSaqS4=
|
||||||
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
|
github.com/jezek/xgb v1.1.1/go.mod h1:nrhwO0FX/enq75I7Y7G8iN1ubpSGZEiA3v9e9GyRFlk=
|
||||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
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/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||||
|
github.com/kbinani/screenshot v0.0.0-20250624051815-089614a94018 h1:NQYgMY188uWrS+E/7xMVpydsI48PMHcc7SfR4OxkDF4=
|
||||||
|
github.com/kbinani/screenshot v0.0.0-20250624051815-089614a94018/go.mod h1:Pmpz2BLf55auQZ67u3rvyI2vAQvNetkK/4zYUmpauZQ=
|
||||||
github.com/klauspost/cpuid/v2 v2.3.0 h1:S4CRMLnYUhGeDFDqkGriYKdfoFlDnMtqTiI/sFzhA9Y=
|
github.com/klauspost/cpuid/v2 v2.3.0 h1:S4CRMLnYUhGeDFDqkGriYKdfoFlDnMtqTiI/sFzhA9Y=
|
||||||
github.com/klauspost/cpuid/v2 v2.3.0/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
|
github.com/klauspost/cpuid/v2 v2.3.0/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
|
||||||
|
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||||
|
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||||
|
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.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
|
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/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
|
||||||
github.com/mailru/easyjson v0.9.1 h1:LbtsOm5WAswyWbvTEOqhypdPeZzHavpZx96/n553mR8=
|
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4=
|
||||||
github.com/mailru/easyjson v0.9.1/go.mod h1:1+xMtQp2MRNVL/V1bOzuP3aP8VNwRW55fQUto+XFtTU=
|
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I=
|
||||||
|
github.com/lxn/win v0.0.0-20210218163916-a377121e959e h1:H+t6A/QJMbhCSEH5rAuRxh+CtW96g0Or0Fxa9IKr4uc=
|
||||||
|
github.com/lxn/win v0.0.0-20210218163916-a377121e959e/go.mod h1:KxxjdtRkfNoYDCUP5ryK7XJJNTnpC8atvtmTheChOtk=
|
||||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
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-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
|
|
||||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
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 h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
|
||||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||||
@@ -107,21 +110,24 @@ github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdh
|
|||||||
github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
|
github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
|
||||||
github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4=
|
github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4=
|
||||||
github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
|
github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
|
||||||
|
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/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/quic-go/qpack v0.5.1 h1:giqksBPnT/HDtZ6VhtFKgoLOWmlyo9Ei6u9PqzIMbhI=
|
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c h1:ncq/mPwQF4JjgDlrVEn3C11VoGHZN7m8qihwgMEtzYw=
|
||||||
github.com/quic-go/qpack v0.5.1/go.mod h1:+PC4XFrEskIVkcLzpEkbLqq1uCoxPhQuvK5rH1ZgaEg=
|
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE=
|
||||||
github.com/quic-go/qpack v0.6.0 h1:g7W+BMYynC1LbYLSqRt8PBg5Tgwxn214ZZR34VIOjz8=
|
github.com/quic-go/qpack v0.6.0 h1:g7W+BMYynC1LbYLSqRt8PBg5Tgwxn214ZZR34VIOjz8=
|
||||||
github.com/quic-go/qpack v0.6.0/go.mod h1:lUpLKChi8njB4ty2bFLX2x4gzDqXwUpaO1DP9qMDZII=
|
github.com/quic-go/qpack v0.6.0/go.mod h1:lUpLKChi8njB4ty2bFLX2x4gzDqXwUpaO1DP9qMDZII=
|
||||||
github.com/quic-go/quic-go v0.54.0 h1:6s1YB9QotYI6Ospeiguknbp2Znb/jZYjZLRXn9kMQBg=
|
|
||||||
github.com/quic-go/quic-go v0.54.0/go.mod h1:e68ZEaCdyviluZmy44P6Iey98v/Wfz6HCjQEm+l8zTY=
|
|
||||||
github.com/quic-go/quic-go v0.58.0 h1:ggY2pvZaVdB9EyojxL1p+5mptkuHyX5MOSv4dgWF4Ug=
|
github.com/quic-go/quic-go v0.58.0 h1:ggY2pvZaVdB9EyojxL1p+5mptkuHyX5MOSv4dgWF4Ug=
|
||||||
github.com/quic-go/quic-go v0.58.0/go.mod h1:upnsH4Ju1YkqpLXC305eW3yDZ4NfnNbmQRCMWS58IKU=
|
github.com/quic-go/quic-go v0.58.0/go.mod h1:upnsH4Ju1YkqpLXC305eW3yDZ4NfnNbmQRCMWS58IKU=
|
||||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
|
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
|
||||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
|
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
|
||||||
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
|
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
|
||||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
|
||||||
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
|
github.com/shirou/gopsutil/v3 v3.24.5 h1:i0t8kL+kQTvpAYToeuiVk3TgDeKOFioZO3Ztz/iZ9pI=
|
||||||
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
github.com/shirou/gopsutil/v3 v3.24.5/go.mod h1:bsoOS1aStSs9ErQ1WWfxllSeS1K5D+U30r2NfcubMVk=
|
||||||
|
github.com/shoenig/go-m1cpu v0.1.7 h1:C76Yd0ObKR82W4vhfjZiCp0HxcSZ8Nqd84v+HZ0qyI0=
|
||||||
|
github.com/shoenig/go-m1cpu v0.1.7/go.mod h1:KkDOw6m3ZJQAPHbrzkZki4hnx+pDRR1Lo+ldA56wD5w=
|
||||||
|
github.com/shoenig/test v1.7.0 h1:eWcHtTXa6QLnBvm0jgEabMRN/uJ4DMV3M8xUGgRkZmk=
|
||||||
|
github.com/shoenig/test v1.7.0/go.mod h1:UxJ6u/x2v/TNs/LoLxBNJRV9DiwBBKYxXSyczsBHFoI=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
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.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||||
@@ -129,74 +135,64 @@ github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/
|
|||||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||||
github.com/stretchr/testify v1.7.1/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.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/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
|
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
||||||
|
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
||||||
github.com/swaggo/files v1.0.1 h1:J1bVJ4XHZNq0I46UU90611i9/YzdrF7x92oX1ig5IdE=
|
github.com/swaggo/files v1.0.1 h1:J1bVJ4XHZNq0I46UU90611i9/YzdrF7x92oX1ig5IdE=
|
||||||
github.com/swaggo/files v1.0.1/go.mod h1:0qXmMNH6sXNf+73t65aKeB+ApmgxdnkQzVTAj2uaMUg=
|
github.com/swaggo/files v1.0.1/go.mod h1:0qXmMNH6sXNf+73t65aKeB+ApmgxdnkQzVTAj2uaMUg=
|
||||||
github.com/swaggo/gin-swagger v1.6.1 h1:Ri06G4gc9N4t4k8hekMigJ9zKTFSlqj/9paAQCQs7cY=
|
github.com/swaggo/gin-swagger v1.6.1 h1:Ri06G4gc9N4t4k8hekMigJ9zKTFSlqj/9paAQCQs7cY=
|
||||||
github.com/swaggo/gin-swagger v1.6.1/go.mod h1:LQ+hJStHakCWRiK/YNYtJOu4mR2FP+pxLnILT/qNiTw=
|
github.com/swaggo/gin-swagger v1.6.1/go.mod h1:LQ+hJStHakCWRiK/YNYtJOu4mR2FP+pxLnILT/qNiTw=
|
||||||
github.com/swaggo/swag v1.16.6 h1:qBNcx53ZaX+M5dxVyTrgQ0PJ/ACK+NzhwcbieTt+9yI=
|
github.com/swaggo/swag v1.16.6 h1:qBNcx53ZaX+M5dxVyTrgQ0PJ/ACK+NzhwcbieTt+9yI=
|
||||||
github.com/swaggo/swag v1.16.6/go.mod h1:ngP2etMK5a0P3QBizic5MEwpRmluJZPHjXcMoj4Xesg=
|
github.com/swaggo/swag v1.16.6/go.mod h1:ngP2etMK5a0P3QBizic5MEwpRmluJZPHjXcMoj4Xesg=
|
||||||
|
github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU=
|
||||||
|
github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI=
|
||||||
|
github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk=
|
||||||
|
github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY=
|
||||||
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
|
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/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
|
||||||
github.com/ugorji/go/codec v1.3.0 h1:Qd2W2sQawAfG8XSvzwhBeoGq71zXOC/Q1E9y/wUcsUA=
|
|
||||||
github.com/ugorji/go/codec v1.3.0/go.mod h1:pRBVtBSKl77K30Bv8R2P+cLSGaTtex6fsA2Wjqmfxj4=
|
|
||||||
github.com/ugorji/go/codec v1.3.1 h1:waO7eEiFDwidsBN6agj1vJQ4AG7lh2yqXyOXqhgQuyY=
|
github.com/ugorji/go/codec v1.3.1 h1:waO7eEiFDwidsBN6agj1vJQ4AG7lh2yqXyOXqhgQuyY=
|
||||||
github.com/ugorji/go/codec v1.3.1/go.mod h1:pRBVtBSKl77K30Bv8R2P+cLSGaTtex6fsA2Wjqmfxj4=
|
github.com/ugorji/go/codec v1.3.1/go.mod h1:pRBVtBSKl77K30Bv8R2P+cLSGaTtex6fsA2Wjqmfxj4=
|
||||||
github.com/urfave/cli/v2 v2.27.7 h1:bH59vdhbjLv3LAvIu6gd0usJHgoTTPhCFib8qqOwXYU=
|
|
||||||
github.com/urfave/cli/v2 v2.27.7/go.mod h1:CyNAG/xg+iAOg0N4MPGZqVmv2rCoP267496AOXUZjA4=
|
|
||||||
github.com/xrash/smetrics v0.0.0-20250705151800-55b8f293f342 h1:FnBeRrxr7OU4VvAzt5X7s6266i6cSVkkFPS0TuXWbIg=
|
|
||||||
github.com/xrash/smetrics v0.0.0-20250705151800-55b8f293f342/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM=
|
|
||||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||||
go.uber.org/mock v0.5.0 h1:KAMbZvZPyBPWgD14IrIQ38QCyjwpvVVV6K/bHl1IwQU=
|
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
|
||||||
go.uber.org/mock v0.5.0/go.mod h1:ge71pBPLYDk7QIi1LupWxdAykm7KIEFchiOqd6z7qMM=
|
github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
|
||||||
go.uber.org/mock v0.6.0 h1:hyF9dfmbgIX5EfOdasqLsWD6xqpNZlXblLB/Dbnwv3Y=
|
go.uber.org/mock v0.6.0 h1:hyF9dfmbgIX5EfOdasqLsWD6xqpNZlXblLB/Dbnwv3Y=
|
||||||
go.uber.org/mock v0.6.0/go.mod h1:KiVJ4BqZJaMj4svdfmHM0AUx4NJYO8ZNpPnZn1Z+BBU=
|
go.uber.org/mock v0.6.0/go.mod h1:KiVJ4BqZJaMj4svdfmHM0AUx4NJYO8ZNpPnZn1Z+BBU=
|
||||||
go.yaml.in/yaml/v2 v2.4.3 h1:6gvOSjQoTB3vt1l+CU+tSyi/HOjfOjRLJ4YwYZGwRO0=
|
|
||||||
go.yaml.in/yaml/v2 v2.4.3/go.mod h1:zSxWcmIDjOzPXpjlTTbAsKokqkDNAVtZO0WOMiT90s8=
|
|
||||||
go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=
|
go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=
|
||||||
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
|
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
|
||||||
golang.org/x/arch v0.20.0 h1:dx1zTU0MAE98U+TQ8BLl7XsJbgze2WnNKF/8tGp/Q6c=
|
|
||||||
golang.org/x/arch v0.20.0/go.mod h1:bdwinDaKcfZUGpH09BB7ZmOfhalA8lQdzl62l8gGWsk=
|
|
||||||
golang.org/x/arch v0.23.0 h1:lKF64A2jF6Zd8L0knGltUnegD62JMFBiCPBmQpToHhg=
|
golang.org/x/arch v0.23.0 h1:lKF64A2jF6Zd8L0knGltUnegD62JMFBiCPBmQpToHhg=
|
||||||
golang.org/x/arch v0.23.0/go.mod h1:dNHoOeKiyja7GTvF9NJS1l3Z2yntpQNzgrjh1cU103A=
|
golang.org/x/arch v0.23.0/go.mod h1:dNHoOeKiyja7GTvF9NJS1l3Z2yntpQNzgrjh1cU103A=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||||
golang.org/x/crypto v0.41.0 h1:WKYxWedPGCTVVl5+WHSSrOBT0O8lx32+zxmHxijgXp4=
|
|
||||||
golang.org/x/crypto v0.41.0/go.mod h1:pO5AFd7FA68rFak7rOAGVuygIISepHftHnr8dr6+sUc=
|
|
||||||
golang.org/x/crypto v0.46.0 h1:cKRW/pmt1pKAfetfu+RCEvjvZkA9RimPbh7bhFjGVBU=
|
golang.org/x/crypto v0.46.0 h1:cKRW/pmt1pKAfetfu+RCEvjvZkA9RimPbh7bhFjGVBU=
|
||||||
golang.org/x/crypto v0.46.0/go.mod h1:Evb/oLKmMraqjZ2iQTwDwvCtJkczlDuTmdJXoZVzqU0=
|
golang.org/x/crypto v0.46.0/go.mod h1:Evb/oLKmMraqjZ2iQTwDwvCtJkczlDuTmdJXoZVzqU0=
|
||||||
golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b h1:M2rDM6z3Fhozi9O7NWsxAkg/yqS/lQJ6PmkyIV3YP+o=
|
golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b h1:M2rDM6z3Fhozi9O7NWsxAkg/yqS/lQJ6PmkyIV3YP+o=
|
||||||
golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b/go.mod h1:3//PLf8L/X+8b4vuAfHzxeRUl04Adcb341+IGKfnqS8=
|
golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b/go.mod h1:3//PLf8L/X+8b4vuAfHzxeRUl04Adcb341+IGKfnqS8=
|
||||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||||
golang.org/x/mod v0.27.0 h1:kb+q2PyFnEADO2IEF935ehFUXlWiNjJWtRNgBLSfbxQ=
|
|
||||||
golang.org/x/mod v0.27.0/go.mod h1:rWI627Fq0DEoudcK+MBkNkCe0EetEaDSwJJkCcjpazc=
|
|
||||||
golang.org/x/mod v0.31.0 h1:HaW9xtz0+kOcWKwli0ZXy79Ix+UW/vOfmWI5QVd2tgI=
|
golang.org/x/mod v0.31.0 h1:HaW9xtz0+kOcWKwli0ZXy79Ix+UW/vOfmWI5QVd2tgI=
|
||||||
golang.org/x/mod v0.31.0/go.mod h1:43JraMp9cGx1Rx3AqioxrbrhNsLl2l/iNAvuBkrezpg=
|
golang.org/x/mod v0.31.0/go.mod h1:43JraMp9cGx1Rx3AqioxrbrhNsLl2l/iNAvuBkrezpg=
|
||||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||||
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||||
golang.org/x/net v0.43.0 h1:lat02VYK2j4aLzMzecihNvTlJNQUq316m2Mr9rnM6YE=
|
|
||||||
golang.org/x/net v0.43.0/go.mod h1:vhO1fvI4dGsIjh73sWfUVjj3N7CA9WkKJNQm2svM6Jg=
|
|
||||||
golang.org/x/net v0.48.0 h1:zyQRTTrjc33Lhh0fBgT/H3oZq9WuvRR5gPC70xpDiQU=
|
golang.org/x/net v0.48.0 h1:zyQRTTrjc33Lhh0fBgT/H3oZq9WuvRR5gPC70xpDiQU=
|
||||||
golang.org/x/net v0.48.0/go.mod h1:+ndRgGjkh8FGtu1w1FGbEC31if4VrNVMuKTgcAAnQRY=
|
golang.org/x/net v0.48.0/go.mod h1:+ndRgGjkh8FGtu1w1FGbEC31if4VrNVMuKTgcAAnQRY=
|
||||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.16.0 h1:ycBJEhp9p4vXvUZNszeOq0kGTPghopOL8q0fq3vstxw=
|
|
||||||
golang.org/x/sync v0.16.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
|
|
||||||
golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4=
|
golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4=
|
||||||
golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
|
golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
|
||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20201018230417-eeed37f84f13/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/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-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.5.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.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc=
|
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
|
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.39.0 h1:CvCKL8MeisomCi6qNZ+wbb0DN9E5AATixKsvNtMoMFk=
|
golang.org/x/sys v0.39.0 h1:CvCKL8MeisomCi6qNZ+wbb0DN9E5AATixKsvNtMoMFk=
|
||||||
golang.org/x/sys v0.39.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
|
golang.org/x/sys v0.39.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
@@ -205,30 +201,21 @@ golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
|||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||||
golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY=
|
|
||||||
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
|
|
||||||
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||||
golang.org/x/text v0.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng=
|
|
||||||
golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU=
|
|
||||||
golang.org/x/text v0.32.0 h1:ZD01bjUt1FQ9WJ0ClOL5vxgxOI/sVCNgX1YtKwcY0mU=
|
golang.org/x/text v0.32.0 h1:ZD01bjUt1FQ9WJ0ClOL5vxgxOI/sVCNgX1YtKwcY0mU=
|
||||||
golang.org/x/text v0.32.0/go.mod h1:o/rUWzghvpD5TXrTIBuJU77MTaN0ljMWE47kxGJQ7jY=
|
golang.org/x/text v0.32.0/go.mod h1:o/rUWzghvpD5TXrTIBuJU77MTaN0ljMWE47kxGJQ7jY=
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||||
golang.org/x/tools v0.36.0 h1:kWS0uv/zsvHEle1LbV5LE8QujrxB3wfQyxHfhOk0Qkg=
|
|
||||||
golang.org/x/tools v0.36.0/go.mod h1:WBDiHKJK8YgLHlcQPYQzNCkUxUypCaa5ZegCVutKm+s=
|
|
||||||
golang.org/x/tools v0.40.0 h1:yLkxfA+Qnul4cs9QA3KnlFu0lVmd8JJfoq+E41uSutA=
|
golang.org/x/tools v0.40.0 h1:yLkxfA+Qnul4cs9QA3KnlFu0lVmd8JJfoq+E41uSutA=
|
||||||
golang.org/x/tools v0.40.0/go.mod h1:Ik/tzLRlbscWpqqMRjyWYDisX8bG13FrdXp3o4Sr9lc=
|
golang.org/x/tools v0.40.0/go.mod h1:Ik/tzLRlbscWpqqMRjyWYDisX8bG13FrdXp3o4Sr9lc=
|
||||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
google.golang.org/protobuf v1.36.9 h1:w2gp2mA27hUeUzj9Ex9FBjsBm40zfaDtEWow293U7Iw=
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
google.golang.org/protobuf v1.36.9/go.mod h1:fuxRtAxBytpl4zzqUh6/eyUujkJdNiuEkXntxiD/uRU=
|
|
||||||
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
|
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
|
||||||
google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
|
google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/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 h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||||
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-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
@@ -258,5 +245,3 @@ modernc.org/strutil v1.2.1 h1:UneZBkQA+DX2Rp35KcM69cSsNES9ly8mQWD71HKlOA0=
|
|||||||
modernc.org/strutil v1.2.1/go.mod h1:EHkiggD70koQxjVdSBM3JKM7k6L0FbGE5eymy9i3B9A=
|
modernc.org/strutil v1.2.1/go.mod h1:EHkiggD70koQxjVdSBM3JKM7k6L0FbGE5eymy9i3B9A=
|
||||||
modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y=
|
modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y=
|
||||||
modernc.org/token v1.1.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=
|
modernc.org/token v1.1.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=
|
||||||
sigs.k8s.io/yaml v1.6.0 h1:G8fkbMSAFqgEFgh4b1wmtzDnioxFCUgTZhlbj5P9QYs=
|
|
||||||
sigs.k8s.io/yaml v1.6.0/go.mod h1:796bPqUfzR/0jLAl6XjHl3Ck7MiyVv8dbTdyT3/pMf4=
|
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import (
|
|||||||
type ClientConfig struct {
|
type ClientConfig struct {
|
||||||
Server string `yaml:"server"` // 服务器地址
|
Server string `yaml:"server"` // 服务器地址
|
||||||
Token string `yaml:"token"` // 认证 Token
|
Token string `yaml:"token"` // 认证 Token
|
||||||
ID string `yaml:"id"` // 客户端 ID
|
|
||||||
NoTLS bool `yaml:"no_tls"` // 禁用 TLS
|
NoTLS bool `yaml:"no_tls"` // 禁用 TLS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
152
internal/client/tunnel/machine_id.go
Normal file
152
internal/client/tunnel/machine_id.go
Normal file
@@ -0,0 +1,152 @@
|
|||||||
|
package tunnel
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/sha256"
|
||||||
|
"encoding/hex"
|
||||||
|
"net"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"runtime"
|
||||||
|
"sort"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// getMachineID builds a stable fingerprint from multiple host identifiers
|
||||||
|
// and hashes the combined result into the client ID we expose externally.
|
||||||
|
func getMachineID() string {
|
||||||
|
return hashID(strings.Join(collectMachineIDParts(), "|"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func collectMachineIDParts() []string {
|
||||||
|
parts := []string{"os=" + runtime.GOOS, "arch=" + runtime.GOARCH}
|
||||||
|
|
||||||
|
if id := getSystemMachineID(); id != "" {
|
||||||
|
parts = append(parts, "system="+id)
|
||||||
|
}
|
||||||
|
|
||||||
|
if hostname, err := os.Hostname(); err == nil && hostname != "" {
|
||||||
|
parts = append(parts, "host="+hostname)
|
||||||
|
}
|
||||||
|
|
||||||
|
if macs := getMACAddresses(); len(macs) > 0 {
|
||||||
|
parts = append(parts, "macs="+strings.Join(macs, ","))
|
||||||
|
}
|
||||||
|
|
||||||
|
if names := getInterfaceNames(); len(names) > 0 {
|
||||||
|
parts = append(parts, "ifaces="+strings.Join(names, ","))
|
||||||
|
}
|
||||||
|
|
||||||
|
return parts
|
||||||
|
}
|
||||||
|
|
||||||
|
func getSystemMachineID() string {
|
||||||
|
switch runtime.GOOS {
|
||||||
|
case "linux":
|
||||||
|
return getLinuxMachineID()
|
||||||
|
case "darwin":
|
||||||
|
return getDarwinMachineID()
|
||||||
|
case "windows":
|
||||||
|
return getWindowsMachineID()
|
||||||
|
default:
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func getLinuxMachineID() string {
|
||||||
|
if data, err := os.ReadFile("/etc/machine-id"); err == nil {
|
||||||
|
return strings.TrimSpace(string(data))
|
||||||
|
}
|
||||||
|
if data, err := os.ReadFile("/var/lib/dbus/machine-id"); err == nil {
|
||||||
|
return strings.TrimSpace(string(data))
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func getDarwinMachineID() string {
|
||||||
|
cmd := exec.Command("ioreg", "-rd1", "-c", "IOPlatformExpertDevice")
|
||||||
|
output, err := cmd.Output()
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, line := range strings.Split(string(output), "\n") {
|
||||||
|
if !strings.Contains(line, "IOPlatformUUID") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
parts := strings.Split(line, "=")
|
||||||
|
if len(parts) != 2 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
uuid := strings.TrimSpace(parts[1])
|
||||||
|
return strings.Trim(uuid, "\"")
|
||||||
|
}
|
||||||
|
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func getWindowsMachineID() string {
|
||||||
|
cmd := exec.Command("reg", "query", `HKLM\SOFTWARE\Microsoft\Cryptography`, "/v", "MachineGuid")
|
||||||
|
output, err := cmd.Output()
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, line := range strings.Split(string(output), "\n") {
|
||||||
|
if !strings.Contains(line, "MachineGuid") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
fields := strings.Fields(line)
|
||||||
|
if len(fields) >= 3 {
|
||||||
|
return fields[len(fields)-1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func getMACAddresses() []string {
|
||||||
|
interfaces, err := net.Interfaces()
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
macs := make([]string, 0, len(interfaces))
|
||||||
|
for _, iface := range interfaces {
|
||||||
|
if iface.Flags&net.FlagLoopback != 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if len(iface.HardwareAddr) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
macs = append(macs, iface.HardwareAddr.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Strings(macs)
|
||||||
|
return macs
|
||||||
|
}
|
||||||
|
|
||||||
|
func getInterfaceNames() []string {
|
||||||
|
interfaces, err := net.Interfaces()
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
names := make([]string, 0, len(interfaces))
|
||||||
|
for _, iface := range interfaces {
|
||||||
|
if iface.Flags&net.FlagLoopback != 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
names = append(names, iface.Name)
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Strings(names)
|
||||||
|
return names
|
||||||
|
}
|
||||||
|
|
||||||
|
func hashID(id string) string {
|
||||||
|
hash := sha256.Sum256([]byte(id))
|
||||||
|
return hex.EncodeToString(hash[:])[:16]
|
||||||
|
}
|
||||||
@@ -20,17 +20,17 @@ type WebServer struct {
|
|||||||
Server router.ServerInterface
|
Server router.ServerInterface
|
||||||
Config *config.ServerConfig
|
Config *config.ServerConfig
|
||||||
ConfigPath string
|
ConfigPath string
|
||||||
JSPluginStore db.JSPluginStore
|
TrafficStore db.TrafficStore
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewWebServer 创建Web服务
|
// NewWebServer 创建Web服务
|
||||||
func NewWebServer(cs db.ClientStore, srv router.ServerInterface, cfg *config.ServerConfig, cfgPath string, jsStore db.JSPluginStore) *WebServer {
|
func NewWebServer(cs db.ClientStore, srv router.ServerInterface, cfg *config.ServerConfig, cfgPath string, store db.Store) *WebServer {
|
||||||
return &WebServer{
|
return &WebServer{
|
||||||
ClientStore: cs,
|
ClientStore: cs,
|
||||||
Server: srv,
|
Server: srv,
|
||||||
Config: cfg,
|
Config: cfg,
|
||||||
ConfigPath: cfgPath,
|
ConfigPath: cfgPath,
|
||||||
JSPluginStore: jsStore,
|
TrafficStore: store,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,7 +105,7 @@ func (w *WebServer) SaveConfig() error {
|
|||||||
return config.SaveServerConfig(w.ConfigPath, w.Config)
|
return config.SaveServerConfig(w.ConfigPath, w.Config)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetJSPluginStore 获取 JS 插件存储
|
// GetTrafficStore 获取流量存储
|
||||||
func (w *WebServer) GetJSPluginStore() db.JSPluginStore {
|
func (w *WebServer) GetTrafficStore() db.TrafficStore {
|
||||||
return w.JSPluginStore
|
return w.TrafficStore
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,35 +11,6 @@ import (
|
|||||||
// ServerConfig 服务端配置
|
// ServerConfig 服务端配置
|
||||||
type ServerConfig struct {
|
type ServerConfig struct {
|
||||||
Server ServerSettings `yaml:"server"`
|
Server ServerSettings `yaml:"server"`
|
||||||
Web WebSettings `yaml:"web"`
|
|
||||||
PluginStore PluginStoreSettings `yaml:"plugin_store"`
|
|
||||||
JSPlugins []JSPluginConfig `yaml:"js_plugins,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// JSPluginConfig JS 插件配置
|
|
||||||
type JSPluginConfig struct {
|
|
||||||
Name string `yaml:"name"`
|
|
||||||
Path string `yaml:"path"` // JS 文件路径
|
|
||||||
SigPath string `yaml:"sig_path,omitempty"` // 签名文件路径 (默认为 path + ".sig")
|
|
||||||
AutoPush []string `yaml:"auto_push,omitempty"` // 自动推送到的客户端 ID 列表
|
|
||||||
Config map[string]string `yaml:"config,omitempty"` // 插件配置
|
|
||||||
AutoStart bool `yaml:"auto_start,omitempty"` // 是否自动启动
|
|
||||||
}
|
|
||||||
|
|
||||||
// PluginStoreSettings 插件仓库设置
|
|
||||||
type PluginStoreSettings struct {
|
|
||||||
URL string `yaml:"url"` // 插件仓库 URL,为空则使用默认值
|
|
||||||
}
|
|
||||||
|
|
||||||
// 默认插件仓库 URL
|
|
||||||
const DefaultPluginStoreURL = "https://git.92coco.cn/flik/GoTunnel-Plugins/raw/branch/main/store.json"
|
|
||||||
|
|
||||||
// GetPluginStoreURL 获取插件仓库 URL
|
|
||||||
func (s *PluginStoreSettings) GetPluginStoreURL() string {
|
|
||||||
if s.URL != "" {
|
|
||||||
return s.URL
|
|
||||||
}
|
|
||||||
return DefaultPluginStoreURL
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServerSettings 服务端设置
|
// ServerSettings 服务端设置
|
||||||
@@ -50,13 +21,13 @@ type ServerSettings struct {
|
|||||||
HeartbeatSec int `yaml:"heartbeat_sec"`
|
HeartbeatSec int `yaml:"heartbeat_sec"`
|
||||||
HeartbeatTimeout int `yaml:"heartbeat_timeout"`
|
HeartbeatTimeout int `yaml:"heartbeat_timeout"`
|
||||||
DBPath string `yaml:"db_path"`
|
DBPath string `yaml:"db_path"`
|
||||||
TLSDisabled bool `yaml:"tls_disabled"` // 默认启用 TLS,设置为 true 禁用
|
TLSDisabled bool `yaml:"tls_disabled"`
|
||||||
|
Web WebSettings `yaml:"web"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// WebSettings Web控制台设置
|
// WebSettings Web控制台设置
|
||||||
type WebSettings struct {
|
type WebSettings struct {
|
||||||
Enabled bool `yaml:"enabled"`
|
Enabled bool `yaml:"enabled"`
|
||||||
BindAddr string `yaml:"bind_addr"`
|
|
||||||
BindPort int `yaml:"bind_port"`
|
BindPort int `yaml:"bind_port"`
|
||||||
Username string `yaml:"username"`
|
Username string `yaml:"username"`
|
||||||
Password string `yaml:"password"`
|
Password string `yaml:"password"`
|
||||||
@@ -99,12 +70,9 @@ func setDefaults(cfg *ServerConfig) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Web 默认启用
|
// Web 默认启用
|
||||||
if cfg.Web.BindAddr == "" {
|
if cfg.Server.Web.BindPort == 0 {
|
||||||
cfg.Web.BindAddr = "0.0.0.0"
|
cfg.Server.Web.BindPort = 7500
|
||||||
}
|
cfg.Server.Web.Enabled = true
|
||||||
if cfg.Web.BindPort == 0 {
|
|
||||||
cfg.Web.BindPort = 7500
|
|
||||||
cfg.Web.Enabled = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Token 未配置时自动生成 32 位
|
// Token 未配置时自动生成 32 位
|
||||||
@@ -126,11 +94,11 @@ func generateToken(length int) string {
|
|||||||
|
|
||||||
// GenerateWebCredentials 生成 Web 控制台凭据
|
// GenerateWebCredentials 生成 Web 控制台凭据
|
||||||
func GenerateWebCredentials(cfg *ServerConfig) bool {
|
func GenerateWebCredentials(cfg *ServerConfig) bool {
|
||||||
if cfg.Web.Username == "" {
|
if cfg.Server.Web.Username == "" {
|
||||||
cfg.Web.Username = "admin"
|
cfg.Server.Web.Username = "admin"
|
||||||
}
|
}
|
||||||
if cfg.Web.Password == "" {
|
if cfg.Server.Web.Password == "" {
|
||||||
cfg.Web.Password = generateToken(16)
|
cfg.Server.Web.Password = generateToken(16)
|
||||||
return true // 表示生成了新密码
|
return true // 表示生成了新密码
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
|||||||
45
internal/server/db/install_token.go
Normal file
45
internal/server/db/install_token.go
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
package db
|
||||||
|
|
||||||
|
// CreateInstallToken 创建安装token
|
||||||
|
func (s *SQLiteStore) CreateInstallToken(token *InstallToken) error {
|
||||||
|
s.mu.Lock()
|
||||||
|
defer s.mu.Unlock()
|
||||||
|
|
||||||
|
_, err := s.db.Exec(`INSERT INTO install_tokens (token, client_id, created_at, used) VALUES (?, '', ?, ?)`,
|
||||||
|
token.Token, token.CreatedAt, 0)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetInstallToken 获取安装token
|
||||||
|
func (s *SQLiteStore) GetInstallToken(token string) (*InstallToken, error) {
|
||||||
|
s.mu.RLock()
|
||||||
|
defer s.mu.RUnlock()
|
||||||
|
|
||||||
|
var t InstallToken
|
||||||
|
var used int
|
||||||
|
err := s.db.QueryRow(`SELECT token, created_at, used FROM install_tokens WHERE token = ?`, token).
|
||||||
|
Scan(&t.Token, &t.CreatedAt, &used)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
t.Used = used == 1
|
||||||
|
return &t, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarkTokenUsed 标记token已使用
|
||||||
|
func (s *SQLiteStore) MarkTokenUsed(token string) error {
|
||||||
|
s.mu.Lock()
|
||||||
|
defer s.mu.Unlock()
|
||||||
|
|
||||||
|
_, err := s.db.Exec(`UPDATE install_tokens SET used = 1 WHERE token = ?`, token)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteExpiredTokens 删除过期token
|
||||||
|
func (s *SQLiteStore) DeleteExpiredTokens(expireTime int64) error {
|
||||||
|
s.mu.Lock()
|
||||||
|
defer s.mu.Unlock()
|
||||||
|
|
||||||
|
_, err := s.db.Exec(`DELETE FROM install_tokens WHERE created_at < ?`, expireTime)
|
||||||
|
return err
|
||||||
|
}
|
||||||
@@ -2,52 +2,11 @@ package db
|
|||||||
|
|
||||||
import "github.com/gotunnel/pkg/protocol"
|
import "github.com/gotunnel/pkg/protocol"
|
||||||
|
|
||||||
// ConfigField 配置字段定义
|
|
||||||
type ConfigField struct {
|
|
||||||
Key string `json:"key"`
|
|
||||||
Label string `json:"label"`
|
|
||||||
Type string `json:"type"`
|
|
||||||
Default string `json:"default,omitempty"`
|
|
||||||
Required bool `json:"required,omitempty"`
|
|
||||||
Options []string `json:"options,omitempty"`
|
|
||||||
Description string `json:"description,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// ClientPlugin 客户端已安装的插件
|
|
||||||
type ClientPlugin struct {
|
|
||||||
ID string `json:"id"` // 插件实例唯一 ID
|
|
||||||
Name string `json:"name"`
|
|
||||||
Version string `json:"version"`
|
|
||||||
Enabled bool `json:"enabled"`
|
|
||||||
Running bool `json:"running"` // 运行状态
|
|
||||||
Config map[string]string `json:"config,omitempty"` // 插件配置
|
|
||||||
RemotePort int `json:"remote_port,omitempty"` // 远程监听端口
|
|
||||||
ConfigSchema []ConfigField `json:"config_schema,omitempty"` // 配置模式
|
|
||||||
AuthEnabled bool `json:"auth_enabled,omitempty"` // 是否启用认证
|
|
||||||
AuthUsername string `json:"auth_username,omitempty"` // 认证用户名
|
|
||||||
AuthPassword string `json:"auth_password,omitempty"` // 认证密码
|
|
||||||
}
|
|
||||||
|
|
||||||
// Client 客户端数据
|
// Client 客户端数据
|
||||||
type Client struct {
|
type Client struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Nickname string `json:"nickname,omitempty"`
|
Nickname string `json:"nickname,omitempty"`
|
||||||
Rules []protocol.ProxyRule `json:"rules"`
|
Rules []protocol.ProxyRule `json:"rules"`
|
||||||
Plugins []ClientPlugin `json:"plugins,omitempty"` // 已安装的插件
|
|
||||||
}
|
|
||||||
|
|
||||||
// JSPlugin JS 插件数据
|
|
||||||
type JSPlugin struct {
|
|
||||||
Name string `json:"name"`
|
|
||||||
Source string `json:"source"`
|
|
||||||
Signature string `json:"signature"` // 官方签名 (Base64)
|
|
||||||
Description string `json:"description"`
|
|
||||||
Author string `json:"author"`
|
|
||||||
Version string `json:"version,omitempty"`
|
|
||||||
AutoPush []string `json:"auto_push"`
|
|
||||||
Config map[string]string `json:"config"`
|
|
||||||
AutoStart bool `json:"auto_start"`
|
|
||||||
Enabled bool `json:"enabled"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClientStore 客户端存储接口
|
// ClientStore 客户端存储接口
|
||||||
@@ -62,19 +21,39 @@ type ClientStore interface {
|
|||||||
Close() error
|
Close() error
|
||||||
}
|
}
|
||||||
|
|
||||||
// JSPluginStore JS 插件存储接口
|
|
||||||
type JSPluginStore interface {
|
|
||||||
GetAllJSPlugins() ([]JSPlugin, error)
|
|
||||||
GetJSPlugin(name string) (*JSPlugin, error)
|
|
||||||
SaveJSPlugin(p *JSPlugin) error
|
|
||||||
DeleteJSPlugin(name string) error
|
|
||||||
SetJSPluginEnabled(name string, enabled bool) error
|
|
||||||
UpdateJSPluginConfig(name string, config map[string]string) error
|
|
||||||
}
|
|
||||||
|
|
||||||
// Store 统一存储接口
|
// Store 统一存储接口
|
||||||
type Store interface {
|
type Store interface {
|
||||||
ClientStore
|
ClientStore
|
||||||
JSPluginStore
|
TrafficStore
|
||||||
Close() error
|
Close() error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TrafficRecord 流量记录
|
||||||
|
type TrafficRecord struct {
|
||||||
|
Timestamp int64 `json:"timestamp"` // Unix 时间戳(小时级别)
|
||||||
|
Inbound int64 `json:"inbound"` // 入站流量(字节)
|
||||||
|
Outbound int64 `json:"outbound"` // 出站流量(字节)
|
||||||
|
}
|
||||||
|
|
||||||
|
// TrafficStore 流量存储接口
|
||||||
|
type TrafficStore interface {
|
||||||
|
AddTraffic(inbound, outbound int64) error
|
||||||
|
GetTotalTraffic() (inbound, outbound int64, err error)
|
||||||
|
Get24HourTraffic() (inbound, outbound int64, err error)
|
||||||
|
GetHourlyTraffic(hours int) ([]TrafficRecord, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// InstallToken 安装token
|
||||||
|
type InstallToken struct {
|
||||||
|
Token string `json:"token"`
|
||||||
|
CreatedAt int64 `json:"created_at"`
|
||||||
|
Used bool `json:"used"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// InstallTokenStore 安装token存储接口
|
||||||
|
type InstallTokenStore interface {
|
||||||
|
CreateInstallToken(token *InstallToken) error
|
||||||
|
GetInstallToken(token string) (*InstallToken, error)
|
||||||
|
MarkTokenUsed(token string) error
|
||||||
|
DeleteExpiredTokens(expireTime int64) error
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"database/sql"
|
"database/sql"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
_ "modernc.org/sqlite"
|
_ "modernc.org/sqlite"
|
||||||
|
|
||||||
@@ -39,8 +40,7 @@ func (s *SQLiteStore) init() error {
|
|||||||
CREATE TABLE IF NOT EXISTS clients (
|
CREATE TABLE IF NOT EXISTS clients (
|
||||||
id TEXT PRIMARY KEY,
|
id TEXT PRIMARY KEY,
|
||||||
nickname TEXT NOT NULL DEFAULT '',
|
nickname TEXT NOT NULL DEFAULT '',
|
||||||
rules TEXT NOT NULL DEFAULT '[]',
|
rules TEXT NOT NULL DEFAULT '[]'
|
||||||
plugins TEXT NOT NULL DEFAULT '[]'
|
|
||||||
)
|
)
|
||||||
`)
|
`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -49,36 +49,46 @@ func (s *SQLiteStore) init() error {
|
|||||||
|
|
||||||
// 迁移:添加 nickname 列
|
// 迁移:添加 nickname 列
|
||||||
s.db.Exec(`ALTER TABLE clients ADD COLUMN nickname TEXT NOT NULL DEFAULT ''`)
|
s.db.Exec(`ALTER TABLE clients ADD COLUMN nickname TEXT NOT NULL DEFAULT ''`)
|
||||||
// 迁移:添加 plugins 列
|
|
||||||
s.db.Exec(`ALTER TABLE clients ADD COLUMN plugins TEXT NOT NULL DEFAULT '[]'`)
|
|
||||||
|
|
||||||
// 创建 JS 插件表
|
// 创建流量统计表
|
||||||
_, err = s.db.Exec(`
|
_, err = s.db.Exec(`
|
||||||
CREATE TABLE IF NOT EXISTS js_plugins (
|
CREATE TABLE IF NOT EXISTS traffic_stats (
|
||||||
name TEXT PRIMARY KEY,
|
hour_ts INTEGER PRIMARY KEY,
|
||||||
source TEXT NOT NULL,
|
inbound INTEGER NOT NULL DEFAULT 0,
|
||||||
signature TEXT NOT NULL DEFAULT '',
|
outbound INTEGER NOT NULL DEFAULT 0
|
||||||
description TEXT,
|
|
||||||
author TEXT,
|
|
||||||
version TEXT DEFAULT '',
|
|
||||||
auto_push TEXT NOT NULL DEFAULT '[]',
|
|
||||||
config TEXT NOT NULL DEFAULT '{}',
|
|
||||||
auto_start INTEGER DEFAULT 1,
|
|
||||||
enabled INTEGER DEFAULT 1,
|
|
||||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
||||||
)
|
)
|
||||||
`)
|
`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 迁移:添加 signature 列
|
// 创建总流量表
|
||||||
s.db.Exec(`ALTER TABLE js_plugins ADD COLUMN signature TEXT NOT NULL DEFAULT ''`)
|
_, err = s.db.Exec(`
|
||||||
// 迁移:添加 version 列
|
CREATE TABLE IF NOT EXISTS traffic_total (
|
||||||
s.db.Exec(`ALTER TABLE js_plugins ADD COLUMN version TEXT DEFAULT ''`)
|
id INTEGER PRIMARY KEY CHECK (id = 1),
|
||||||
// 迁移:添加 updated_at 列
|
inbound INTEGER NOT NULL DEFAULT 0,
|
||||||
s.db.Exec(`ALTER TABLE js_plugins ADD COLUMN updated_at DATETIME DEFAULT CURRENT_TIMESTAMP`)
|
outbound INTEGER NOT NULL DEFAULT 0
|
||||||
|
)
|
||||||
|
`)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 初始化总流量记录
|
||||||
|
s.db.Exec(`INSERT OR IGNORE INTO traffic_total (id, inbound, outbound) VALUES (1, 0, 0)`)
|
||||||
|
|
||||||
|
// 创建安装token表
|
||||||
|
_, err = s.db.Exec(`
|
||||||
|
CREATE TABLE IF NOT EXISTS install_tokens (
|
||||||
|
token TEXT PRIMARY KEY,
|
||||||
|
client_id TEXT NOT NULL DEFAULT '',
|
||||||
|
created_at INTEGER NOT NULL,
|
||||||
|
used INTEGER NOT NULL DEFAULT 0
|
||||||
|
)
|
||||||
|
`)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -93,7 +103,7 @@ func (s *SQLiteStore) GetAllClients() ([]Client, error) {
|
|||||||
s.mu.RLock()
|
s.mu.RLock()
|
||||||
defer s.mu.RUnlock()
|
defer s.mu.RUnlock()
|
||||||
|
|
||||||
rows, err := s.db.Query(`SELECT id, nickname, rules, plugins FROM clients`)
|
rows, err := s.db.Query(`SELECT id, nickname, rules FROM clients`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -102,16 +112,13 @@ func (s *SQLiteStore) GetAllClients() ([]Client, error) {
|
|||||||
var clients []Client
|
var clients []Client
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var c Client
|
var c Client
|
||||||
var rulesJSON, pluginsJSON string
|
var rulesJSON string
|
||||||
if err := rows.Scan(&c.ID, &c.Nickname, &rulesJSON, &pluginsJSON); err != nil {
|
if err := rows.Scan(&c.ID, &c.Nickname, &rulesJSON); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if err := json.Unmarshal([]byte(rulesJSON), &c.Rules); err != nil {
|
if err := json.Unmarshal([]byte(rulesJSON), &c.Rules); err != nil {
|
||||||
c.Rules = []protocol.ProxyRule{}
|
c.Rules = []protocol.ProxyRule{}
|
||||||
}
|
}
|
||||||
if err := json.Unmarshal([]byte(pluginsJSON), &c.Plugins); err != nil {
|
|
||||||
c.Plugins = []ClientPlugin{}
|
|
||||||
}
|
|
||||||
clients = append(clients, c)
|
clients = append(clients, c)
|
||||||
}
|
}
|
||||||
return clients, nil
|
return clients, nil
|
||||||
@@ -123,17 +130,14 @@ func (s *SQLiteStore) GetClient(id string) (*Client, error) {
|
|||||||
defer s.mu.RUnlock()
|
defer s.mu.RUnlock()
|
||||||
|
|
||||||
var c Client
|
var c Client
|
||||||
var rulesJSON, pluginsJSON string
|
var rulesJSON string
|
||||||
err := s.db.QueryRow(`SELECT id, nickname, rules, plugins FROM clients WHERE id = ?`, id).Scan(&c.ID, &c.Nickname, &rulesJSON, &pluginsJSON)
|
err := s.db.QueryRow(`SELECT id, nickname, rules FROM clients WHERE id = ?`, id).Scan(&c.ID, &c.Nickname, &rulesJSON)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if err := json.Unmarshal([]byte(rulesJSON), &c.Rules); err != nil {
|
if err := json.Unmarshal([]byte(rulesJSON), &c.Rules); err != nil {
|
||||||
c.Rules = []protocol.ProxyRule{}
|
c.Rules = []protocol.ProxyRule{}
|
||||||
}
|
}
|
||||||
if err := json.Unmarshal([]byte(pluginsJSON), &c.Plugins); err != nil {
|
|
||||||
c.Plugins = []ClientPlugin{}
|
|
||||||
}
|
|
||||||
return &c, nil
|
return &c, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,12 +150,8 @@ func (s *SQLiteStore) CreateClient(c *Client) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
pluginsJSON, err := json.Marshal(c.Plugins)
|
_, err = s.db.Exec(`INSERT INTO clients (id, nickname, rules) VALUES (?, ?, ?)`,
|
||||||
if err != nil {
|
c.ID, c.Nickname, string(rulesJSON))
|
||||||
return err
|
|
||||||
}
|
|
||||||
_, err = s.db.Exec(`INSERT INTO clients (id, nickname, rules, plugins) VALUES (?, ?, ?, ?)`,
|
|
||||||
c.ID, c.Nickname, string(rulesJSON), string(pluginsJSON))
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,12 +164,8 @@ func (s *SQLiteStore) UpdateClient(c *Client) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
pluginsJSON, err := json.Marshal(c.Plugins)
|
_, err = s.db.Exec(`UPDATE clients SET nickname = ?, rules = ? WHERE id = ?`,
|
||||||
if err != nil {
|
c.Nickname, string(rulesJSON), c.ID)
|
||||||
return err
|
|
||||||
}
|
|
||||||
_, err = s.db.Exec(`UPDATE clients SET nickname = ?, rules = ?, plugins = ? WHERE id = ?`,
|
|
||||||
c.Nickname, string(rulesJSON), string(pluginsJSON), c.ID)
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -201,117 +197,99 @@ func (s *SQLiteStore) GetClientRules(id string) ([]protocol.ProxyRule, error) {
|
|||||||
return c.Rules, nil
|
return c.Rules, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ========== JS 插件存储方法 ==========
|
// ========== 流量统计方法 ==========
|
||||||
|
|
||||||
// GetAllJSPlugins 获取所有 JS 插件
|
// getHourTimestamp 获取当前小时的时间戳
|
||||||
func (s *SQLiteStore) GetAllJSPlugins() ([]JSPlugin, error) {
|
func getHourTimestamp() int64 {
|
||||||
|
now := time.Now()
|
||||||
|
return time.Date(now.Year(), now.Month(), now.Day(), now.Hour(), 0, 0, 0, now.Location()).Unix()
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddTraffic 添加流量记录
|
||||||
|
func (s *SQLiteStore) AddTraffic(inbound, outbound int64) error {
|
||||||
|
s.mu.Lock()
|
||||||
|
defer s.mu.Unlock()
|
||||||
|
|
||||||
|
hourTs := getHourTimestamp()
|
||||||
|
|
||||||
|
// 更新小时统计
|
||||||
|
_, err := s.db.Exec(`
|
||||||
|
INSERT INTO traffic_stats (hour_ts, inbound, outbound) VALUES (?, ?, ?)
|
||||||
|
ON CONFLICT(hour_ts) DO UPDATE SET inbound = inbound + ?, outbound = outbound + ?
|
||||||
|
`, hourTs, inbound, outbound, inbound, outbound)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新总流量
|
||||||
|
_, err = s.db.Exec(`
|
||||||
|
UPDATE traffic_total SET inbound = inbound + ?, outbound = outbound + ? WHERE id = 1
|
||||||
|
`, inbound, outbound)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetTotalTraffic 获取总流量
|
||||||
|
func (s *SQLiteStore) GetTotalTraffic() (inbound, outbound int64, err error) {
|
||||||
s.mu.RLock()
|
s.mu.RLock()
|
||||||
defer s.mu.RUnlock()
|
defer s.mu.RUnlock()
|
||||||
|
|
||||||
|
err = s.db.QueryRow(`SELECT inbound, outbound FROM traffic_total WHERE id = 1`).Scan(&inbound, &outbound)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get24HourTraffic 获取24小时流量
|
||||||
|
func (s *SQLiteStore) Get24HourTraffic() (inbound, outbound int64, err error) {
|
||||||
|
s.mu.RLock()
|
||||||
|
defer s.mu.RUnlock()
|
||||||
|
|
||||||
|
cutoff := time.Now().Add(-24 * time.Hour).Unix()
|
||||||
|
err = s.db.QueryRow(`
|
||||||
|
SELECT COALESCE(SUM(inbound), 0), COALESCE(SUM(outbound), 0)
|
||||||
|
FROM traffic_stats WHERE hour_ts >= ?
|
||||||
|
`, cutoff).Scan(&inbound, &outbound)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetHourlyTraffic 获取每小时流量记录(始终返回完整的 hours 小时数据)
|
||||||
|
func (s *SQLiteStore) GetHourlyTraffic(hours int) ([]TrafficRecord, error) {
|
||||||
|
s.mu.RLock()
|
||||||
|
defer s.mu.RUnlock()
|
||||||
|
|
||||||
|
// 计算当前小时的起始时间戳
|
||||||
|
now := time.Now()
|
||||||
|
currentHour := time.Date(now.Year(), now.Month(), now.Day(), now.Hour(), 0, 0, 0, now.Location())
|
||||||
|
|
||||||
|
// 查询数据库中的记录
|
||||||
|
cutoff := currentHour.Add(-time.Duration(hours-1) * time.Hour).Unix()
|
||||||
rows, err := s.db.Query(`
|
rows, err := s.db.Query(`
|
||||||
SELECT name, source, signature, description, author, version, auto_push, config, auto_start, enabled
|
SELECT hour_ts, inbound, outbound FROM traffic_stats
|
||||||
FROM js_plugins
|
WHERE hour_ts >= ? ORDER BY hour_ts ASC
|
||||||
`)
|
`, cutoff)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
|
|
||||||
var plugins []JSPlugin
|
// 将数据库记录放入 map 以便快速查找
|
||||||
|
dbRecords := make(map[int64]TrafficRecord)
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var p JSPlugin
|
var r TrafficRecord
|
||||||
var autoPushJSON, configJSON string
|
if err := rows.Scan(&r.Timestamp, &r.Inbound, &r.Outbound); err != nil {
|
||||||
var version sql.NullString
|
|
||||||
var autoStart, enabled int
|
|
||||||
err := rows.Scan(&p.Name, &p.Source, &p.Signature, &p.Description, &p.Author,
|
|
||||||
&version, &autoPushJSON, &configJSON, &autoStart, &enabled)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
p.Version = version.String
|
dbRecords[r.Timestamp] = r
|
||||||
json.Unmarshal([]byte(autoPushJSON), &p.AutoPush)
|
|
||||||
json.Unmarshal([]byte(configJSON), &p.Config)
|
|
||||||
p.AutoStart = autoStart == 1
|
|
||||||
p.Enabled = enabled == 1
|
|
||||||
plugins = append(plugins, p)
|
|
||||||
}
|
|
||||||
return plugins, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetJSPlugin 获取单个 JS 插件
|
|
||||||
func (s *SQLiteStore) GetJSPlugin(name string) (*JSPlugin, error) {
|
|
||||||
s.mu.RLock()
|
|
||||||
defer s.mu.RUnlock()
|
|
||||||
|
|
||||||
var p JSPlugin
|
|
||||||
var autoPushJSON, configJSON string
|
|
||||||
var version sql.NullString
|
|
||||||
var autoStart, enabled int
|
|
||||||
err := s.db.QueryRow(`
|
|
||||||
SELECT name, source, signature, description, author, version, auto_push, config, auto_start, enabled
|
|
||||||
FROM js_plugins WHERE name = ?
|
|
||||||
`, name).Scan(&p.Name, &p.Source, &p.Signature, &p.Description, &p.Author,
|
|
||||||
&version, &autoPushJSON, &configJSON, &autoStart, &enabled)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
p.Version = version.String
|
|
||||||
json.Unmarshal([]byte(autoPushJSON), &p.AutoPush)
|
|
||||||
json.Unmarshal([]byte(configJSON), &p.Config)
|
|
||||||
p.AutoStart = autoStart == 1
|
|
||||||
p.Enabled = enabled == 1
|
|
||||||
return &p, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// SaveJSPlugin 保存 JS 插件
|
|
||||||
func (s *SQLiteStore) SaveJSPlugin(p *JSPlugin) error {
|
|
||||||
s.mu.Lock()
|
|
||||||
defer s.mu.Unlock()
|
|
||||||
|
|
||||||
autoPushJSON, _ := json.Marshal(p.AutoPush)
|
|
||||||
configJSON, _ := json.Marshal(p.Config)
|
|
||||||
autoStart, enabled := 0, 0
|
|
||||||
if p.AutoStart {
|
|
||||||
autoStart = 1
|
|
||||||
}
|
|
||||||
if p.Enabled {
|
|
||||||
enabled = 1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := s.db.Exec(`
|
// 生成完整的 hours 小时数据
|
||||||
INSERT OR REPLACE INTO js_plugins
|
records := make([]TrafficRecord, hours)
|
||||||
(name, source, signature, description, author, version, auto_push, config, auto_start, enabled, updated_at)
|
for i := 0; i < hours; i++ {
|
||||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP)
|
ts := currentHour.Add(-time.Duration(hours-1-i) * time.Hour).Unix()
|
||||||
`, p.Name, p.Source, p.Signature, p.Description, p.Author, p.Version,
|
if r, ok := dbRecords[ts]; ok {
|
||||||
string(autoPushJSON), string(configJSON), autoStart, enabled)
|
records[i] = r
|
||||||
return err
|
} else {
|
||||||
}
|
records[i] = TrafficRecord{Timestamp: ts, Inbound: 0, Outbound: 0}
|
||||||
|
}
|
||||||
// DeleteJSPlugin 删除 JS 插件
|
|
||||||
func (s *SQLiteStore) DeleteJSPlugin(name string) error {
|
|
||||||
s.mu.Lock()
|
|
||||||
defer s.mu.Unlock()
|
|
||||||
_, err := s.db.Exec(`DELETE FROM js_plugins WHERE name = ?`, name)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetJSPluginEnabled 设置 JS 插件启用状态
|
|
||||||
func (s *SQLiteStore) SetJSPluginEnabled(name string, enabled bool) error {
|
|
||||||
s.mu.Lock()
|
|
||||||
defer s.mu.Unlock()
|
|
||||||
val := 0
|
|
||||||
if enabled {
|
|
||||||
val = 1
|
|
||||||
}
|
}
|
||||||
_, err := s.db.Exec(`UPDATE js_plugins SET enabled = ?, updated_at = CURRENT_TIMESTAMP WHERE name = ?`, val, name)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// UpdateJSPluginConfig 更新 JS 插件配置
|
return records, nil
|
||||||
func (s *SQLiteStore) UpdateJSPluginConfig(name string, config map[string]string) error {
|
|
||||||
s.mu.Lock()
|
|
||||||
defer s.mu.Unlock()
|
|
||||||
configJSON, _ := json.Marshal(config)
|
|
||||||
_, err := s.db.Exec(`UPDATE js_plugins SET config = ?, updated_at = CURRENT_TIMESTAMP WHERE name = ?`, string(configJSON), name)
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,34 +0,0 @@
|
|||||||
package plugin
|
|
||||||
|
|
||||||
import (
|
|
||||||
"sync"
|
|
||||||
|
|
||||||
"github.com/gotunnel/pkg/plugin"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Manager 服务端 plugin 管理器
|
|
||||||
type Manager struct {
|
|
||||||
registry *plugin.Registry
|
|
||||||
mu sync.RWMutex
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewManager 创建 plugin 管理器
|
|
||||||
func NewManager() (*Manager, error) {
|
|
||||||
registry := plugin.NewRegistry()
|
|
||||||
|
|
||||||
m := &Manager{
|
|
||||||
registry: registry,
|
|
||||||
}
|
|
||||||
|
|
||||||
return m, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ListPlugins 返回所有插件
|
|
||||||
func (m *Manager) ListPlugins() []plugin.Info {
|
|
||||||
return m.registry.List()
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetRegistry 返回插件注册表
|
|
||||||
func (m *Manager) GetRegistry() *plugin.Registry {
|
|
||||||
return m.registry
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
package dto
|
package dto
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gotunnel/internal/server/db"
|
|
||||||
"github.com/gotunnel/pkg/protocol"
|
"github.com/gotunnel/pkg/protocol"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -17,7 +16,6 @@ type CreateClientRequest struct {
|
|||||||
type UpdateClientRequest struct {
|
type UpdateClientRequest struct {
|
||||||
Nickname string `json:"nickname" binding:"max=128" example:"My Client"`
|
Nickname string `json:"nickname" binding:"max=128" example:"My Client"`
|
||||||
Rules []protocol.ProxyRule `json:"rules"`
|
Rules []protocol.ProxyRule `json:"rules"`
|
||||||
Plugins []db.ClientPlugin `json:"plugins"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClientResponse 客户端详情响应
|
// ClientResponse 客户端详情响应
|
||||||
@@ -26,10 +24,12 @@ type ClientResponse struct {
|
|||||||
ID string `json:"id" example:"client-001"`
|
ID string `json:"id" example:"client-001"`
|
||||||
Nickname string `json:"nickname,omitempty" example:"My Client"`
|
Nickname string `json:"nickname,omitempty" example:"My Client"`
|
||||||
Rules []protocol.ProxyRule `json:"rules"`
|
Rules []protocol.ProxyRule `json:"rules"`
|
||||||
Plugins []db.ClientPlugin `json:"plugins,omitempty"`
|
|
||||||
Online bool `json:"online" example:"true"`
|
Online bool `json:"online" example:"true"`
|
||||||
LastPing string `json:"last_ping,omitempty" example:"2025-01-02T10:30:00Z"`
|
LastPing string `json:"last_ping,omitempty" example:"2025-01-02T10:30:00Z"`
|
||||||
RemoteAddr string `json:"remote_addr,omitempty" example:"192.168.1.100:54321"`
|
RemoteAddr string `json:"remote_addr,omitempty" example:"192.168.1.100:54321"`
|
||||||
|
OS string `json:"os,omitempty" example:"linux"`
|
||||||
|
Arch string `json:"arch,omitempty" example:"amd64"`
|
||||||
|
Version string `json:"version,omitempty" example:"1.0.0"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClientListItem 客户端列表项
|
// ClientListItem 客户端列表项
|
||||||
@@ -41,18 +41,6 @@ type ClientListItem struct {
|
|||||||
LastPing string `json:"last_ping,omitempty"`
|
LastPing string `json:"last_ping,omitempty"`
|
||||||
RemoteAddr string `json:"remote_addr,omitempty"`
|
RemoteAddr string `json:"remote_addr,omitempty"`
|
||||||
RuleCount int `json:"rule_count" example:"3"`
|
RuleCount int `json:"rule_count" example:"3"`
|
||||||
}
|
OS string `json:"os,omitempty" example:"linux"`
|
||||||
|
Arch string `json:"arch,omitempty" example:"amd64"`
|
||||||
// InstallPluginsRequest 安装插件到客户端请求
|
|
||||||
// @Description 安装插件到指定客户端
|
|
||||||
type InstallPluginsRequest struct {
|
|
||||||
Plugins []string `json:"plugins" binding:"required,min=1,dive,required" example:"socks5,http-proxy"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// ClientPluginActionRequest 客户端插件操作请求
|
|
||||||
// @Description 对客户端插件执行操作
|
|
||||||
type ClientPluginActionRequest struct {
|
|
||||||
RuleName string `json:"rule_name"`
|
|
||||||
Config map[string]string `json:"config,omitempty"`
|
|
||||||
Restart bool `json:"restart"`
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,12 @@
|
|||||||
package dto
|
package dto
|
||||||
|
|
||||||
// UpdateServerConfigRequest 更新服务器配置请求
|
// UpdateServerConfigRequest is the config update payload.
|
||||||
// @Description 更新服务器配置
|
|
||||||
type UpdateServerConfigRequest struct {
|
type UpdateServerConfigRequest struct {
|
||||||
Server *ServerConfigPart `json:"server"`
|
Server *ServerConfigPart `json:"server"`
|
||||||
Web *WebConfigPart `json:"web"`
|
Web *WebConfigPart `json:"web"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServerConfigPart 服务器配置部分
|
// ServerConfigPart is the server config subset.
|
||||||
// @Description 隧道服务器配置
|
|
||||||
type ServerConfigPart struct {
|
type ServerConfigPart struct {
|
||||||
BindAddr string `json:"bind_addr" binding:"omitempty"`
|
BindAddr string `json:"bind_addr" binding:"omitempty"`
|
||||||
BindPort int `json:"bind_port" binding:"omitempty,min=1,max=65535"`
|
BindPort int `json:"bind_port" binding:"omitempty,min=1,max=65535"`
|
||||||
@@ -17,37 +15,33 @@ type ServerConfigPart struct {
|
|||||||
HeartbeatTimeout int `json:"heartbeat_timeout" binding:"omitempty,min=1,max=600"`
|
HeartbeatTimeout int `json:"heartbeat_timeout" binding:"omitempty,min=1,max=600"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// WebConfigPart Web 配置部分
|
// WebConfigPart is the web console config subset.
|
||||||
// @Description Web 控制台配置
|
|
||||||
type WebConfigPart struct {
|
type WebConfigPart struct {
|
||||||
Enabled bool `json:"enabled"`
|
Enabled bool `json:"enabled"`
|
||||||
BindAddr string `json:"bind_addr" binding:"omitempty"`
|
|
||||||
BindPort int `json:"bind_port" binding:"omitempty,min=1,max=65535"`
|
BindPort int `json:"bind_port" binding:"omitempty,min=1,max=65535"`
|
||||||
Username string `json:"username" binding:"omitempty,min=3,max=32"`
|
Username string `json:"username" binding:"omitempty,min=3,max=32"`
|
||||||
Password string `json:"password" binding:"omitempty,min=6,max=64"`
|
Password string `json:"password" binding:"omitempty,min=6,max=64"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServerConfigResponse 服务器配置响应
|
// ServerConfigResponse is the config response payload.
|
||||||
// @Description 服务器配置信息
|
|
||||||
type ServerConfigResponse struct {
|
type ServerConfigResponse struct {
|
||||||
Server ServerConfigInfo `json:"server"`
|
Server ServerConfigInfo `json:"server"`
|
||||||
Web WebConfigInfo `json:"web"`
|
Web WebConfigInfo `json:"web"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServerConfigInfo 服务器配置信息
|
// ServerConfigInfo describes the server config.
|
||||||
type ServerConfigInfo struct {
|
type ServerConfigInfo struct {
|
||||||
BindAddr string `json:"bind_addr"`
|
BindAddr string `json:"bind_addr"`
|
||||||
BindPort int `json:"bind_port"`
|
BindPort int `json:"bind_port"`
|
||||||
Token string `json:"token"` // 脱敏后的 token
|
Token string `json:"token"`
|
||||||
HeartbeatSec int `json:"heartbeat_sec"`
|
HeartbeatSec int `json:"heartbeat_sec"`
|
||||||
HeartbeatTimeout int `json:"heartbeat_timeout"`
|
HeartbeatTimeout int `json:"heartbeat_timeout"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// WebConfigInfo Web 配置信息
|
// WebConfigInfo describes the web console config.
|
||||||
type WebConfigInfo struct {
|
type WebConfigInfo struct {
|
||||||
Enabled bool `json:"enabled"`
|
Enabled bool `json:"enabled"`
|
||||||
BindAddr string `json:"bind_addr"`
|
|
||||||
BindPort int `json:"bind_port"`
|
BindPort int `json:"bind_port"`
|
||||||
Username string `json:"username"`
|
Username string `json:"username"`
|
||||||
Password string `json:"password"` // 显示为 ****
|
Password string `json:"password"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,119 +0,0 @@
|
|||||||
package dto
|
|
||||||
|
|
||||||
// PluginConfigRequest 更新插件配置请求
|
|
||||||
// @Description 更新客户端插件配置
|
|
||||||
type PluginConfigRequest struct {
|
|
||||||
Config map[string]string `json:"config" binding:"required"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// PluginConfigResponse 插件配置响应
|
|
||||||
// @Description 插件配置详情
|
|
||||||
type PluginConfigResponse struct {
|
|
||||||
PluginName string `json:"plugin_name"`
|
|
||||||
Schema []ConfigField `json:"schema"`
|
|
||||||
Config map[string]string `json:"config"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// ConfigField 配置字段定义
|
|
||||||
// @Description 配置表单字段
|
|
||||||
type ConfigField struct {
|
|
||||||
Key string `json:"key"`
|
|
||||||
Label string `json:"label"`
|
|
||||||
Type string `json:"type"`
|
|
||||||
Default string `json:"default,omitempty"`
|
|
||||||
Required bool `json:"required,omitempty"`
|
|
||||||
Options []string `json:"options,omitempty"`
|
|
||||||
Description string `json:"description,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// RuleSchema 规则表单模式
|
|
||||||
// @Description 代理规则的配置模式
|
|
||||||
type RuleSchema struct {
|
|
||||||
NeedsLocalAddr bool `json:"needs_local_addr"`
|
|
||||||
ExtraFields []ConfigField `json:"extra_fields,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// PluginInfo 插件信息
|
|
||||||
// @Description 服务端插件信息
|
|
||||||
type PluginInfo struct {
|
|
||||||
Name string `json:"name"`
|
|
||||||
Version string `json:"version"`
|
|
||||||
Type string `json:"type"`
|
|
||||||
Description string `json:"description"`
|
|
||||||
Source string `json:"source"`
|
|
||||||
Icon string `json:"icon,omitempty"`
|
|
||||||
Enabled bool `json:"enabled"`
|
|
||||||
RuleSchema *RuleSchema `json:"rule_schema,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// JSPluginCreateRequest 创建 JS 插件请求
|
|
||||||
// @Description 创建新的 JS 插件
|
|
||||||
type JSPluginCreateRequest struct {
|
|
||||||
Name string `json:"name" binding:"required,min=1,max=64"`
|
|
||||||
Source string `json:"source" binding:"required"`
|
|
||||||
Signature string `json:"signature"`
|
|
||||||
Description string `json:"description" binding:"max=500"`
|
|
||||||
Author string `json:"author" binding:"max=64"`
|
|
||||||
Config map[string]string `json:"config"`
|
|
||||||
AutoStart bool `json:"auto_start"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// JSPluginUpdateRequest 更新 JS 插件请求
|
|
||||||
// @Description 更新 JS 插件
|
|
||||||
type JSPluginUpdateRequest struct {
|
|
||||||
Source string `json:"source"`
|
|
||||||
Signature string `json:"signature"`
|
|
||||||
Description string `json:"description" binding:"max=500"`
|
|
||||||
Author string `json:"author" binding:"max=64"`
|
|
||||||
Config map[string]string `json:"config"`
|
|
||||||
AutoStart bool `json:"auto_start"`
|
|
||||||
Enabled bool `json:"enabled"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// JSPluginInstallRequest JS 插件安装请求
|
|
||||||
// @Description 安装 JS 插件到客户端
|
|
||||||
type JSPluginInstallRequest struct {
|
|
||||||
PluginName string `json:"plugin_name" binding:"required"`
|
|
||||||
Source string `json:"source" binding:"required"`
|
|
||||||
Signature string `json:"signature"`
|
|
||||||
RuleName string `json:"rule_name"`
|
|
||||||
RemotePort int `json:"remote_port"`
|
|
||||||
Config map[string]string `json:"config"`
|
|
||||||
AutoStart bool `json:"auto_start"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// StorePluginInfo 扩展商店插件信息
|
|
||||||
// @Description 插件商店中的插件信息
|
|
||||||
type StorePluginInfo struct {
|
|
||||||
Name string `json:"name"`
|
|
||||||
Version string `json:"version"`
|
|
||||||
Type string `json:"type"`
|
|
||||||
Description string `json:"description"`
|
|
||||||
Author string `json:"author"`
|
|
||||||
Icon string `json:"icon,omitempty"`
|
|
||||||
DownloadURL string `json:"download_url,omitempty"`
|
|
||||||
SignatureURL string `json:"signature_url,omitempty"`
|
|
||||||
ConfigSchema []ConfigField `json:"config_schema,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// StoreInstallRequest 从商店安装插件请求
|
|
||||||
// @Description 从插件商店安装插件到客户端
|
|
||||||
type StoreInstallRequest struct {
|
|
||||||
PluginName string `json:"plugin_name" binding:"required"`
|
|
||||||
Version string `json:"version"`
|
|
||||||
DownloadURL string `json:"download_url" binding:"required,url"`
|
|
||||||
SignatureURL string `json:"signature_url" binding:"required,url"`
|
|
||||||
ClientID string `json:"client_id" binding:"required"`
|
|
||||||
RemotePort int `json:"remote_port"`
|
|
||||||
ConfigSchema []ConfigField `json:"config_schema,omitempty"`
|
|
||||||
// HTTP Basic Auth 配置
|
|
||||||
AuthEnabled bool `json:"auth_enabled,omitempty"`
|
|
||||||
AuthUsername string `json:"auth_username,omitempty"`
|
|
||||||
AuthPassword string `json:"auth_password,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// JSPluginPushRequest 推送 JS 插件到客户端请求
|
|
||||||
// @Description 推送 JS 插件到指定客户端
|
|
||||||
type JSPluginPushRequest struct {
|
|
||||||
RemotePort int `json:"remote_port"`
|
|
||||||
}
|
|
||||||
@@ -39,7 +39,8 @@ type VersionInfo struct {
|
|||||||
GitCommit string `json:"git_commit,omitempty"`
|
GitCommit string `json:"git_commit,omitempty"`
|
||||||
BuildTime string `json:"build_time,omitempty"`
|
BuildTime string `json:"build_time,omitempty"`
|
||||||
GoVersion string `json:"go_version,omitempty"`
|
GoVersion string `json:"go_version,omitempty"`
|
||||||
Platform string `json:"platform,omitempty"`
|
OS string `json:"os,omitempty"`
|
||||||
|
Arch string `json:"arch,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// StatusResponse 服务器状态响应
|
// StatusResponse 服务器状态响应
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import (
|
|||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/gotunnel/internal/server/db"
|
"github.com/gotunnel/internal/server/db"
|
||||||
"github.com/gotunnel/internal/server/router/dto"
|
"github.com/gotunnel/internal/server/router/dto"
|
||||||
"github.com/gotunnel/pkg/protocol"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ClientHandler 客户端处理器
|
// ClientHandler 客户端处理器
|
||||||
@@ -47,6 +46,8 @@ func (h *ClientHandler) List(c *gin.Context) {
|
|||||||
item.Online = status.Online
|
item.Online = status.Online
|
||||||
item.LastPing = status.LastPing
|
item.LastPing = status.LastPing
|
||||||
item.RemoteAddr = status.RemoteAddr
|
item.RemoteAddr = status.RemoteAddr
|
||||||
|
item.OS = status.OS
|
||||||
|
item.Arch = status.Arch
|
||||||
}
|
}
|
||||||
result = append(result, item)
|
result = append(result, item)
|
||||||
}
|
}
|
||||||
@@ -113,44 +114,24 @@ func (h *ClientHandler) Get(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
online, lastPing, remoteAddr := h.app.GetServer().GetClientStatus(clientID)
|
online, lastPing, remoteAddr, clientName, clientOS, clientArch, clientVersion := h.app.GetServer().GetClientStatus(clientID)
|
||||||
|
|
||||||
// 复制插件列表
|
// 如果客户端在线且有名称,优先使用在线名称
|
||||||
plugins := make([]db.ClientPlugin, len(client.Plugins))
|
nickname := client.Nickname
|
||||||
copy(plugins, client.Plugins)
|
if online && clientName != "" && nickname == "" {
|
||||||
|
nickname = clientName
|
||||||
// 如果客户端在线,获取实时插件运行状态
|
|
||||||
if online {
|
|
||||||
if statusList, err := h.app.GetServer().GetClientPluginStatus(clientID); err == nil {
|
|
||||||
// 创建运行中插件的映射
|
|
||||||
runningPlugins := make(map[string]bool)
|
|
||||||
for _, s := range statusList {
|
|
||||||
runningPlugins[s.PluginName] = s.Running
|
|
||||||
}
|
|
||||||
// 更新插件状态
|
|
||||||
for i := range plugins {
|
|
||||||
if running, ok := runningPlugins[plugins[i].Name]; ok {
|
|
||||||
plugins[i].Running = running
|
|
||||||
} else {
|
|
||||||
plugins[i].Running = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// 客户端离线时,所有插件都标记为未运行
|
|
||||||
for i := range plugins {
|
|
||||||
plugins[i].Running = false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resp := dto.ClientResponse{
|
resp := dto.ClientResponse{
|
||||||
ID: client.ID,
|
ID: client.ID,
|
||||||
Nickname: client.Nickname,
|
Nickname: nickname,
|
||||||
Rules: client.Rules,
|
Rules: client.Rules,
|
||||||
Plugins: plugins,
|
|
||||||
Online: online,
|
Online: online,
|
||||||
LastPing: lastPing,
|
LastPing: lastPing,
|
||||||
RemoteAddr: remoteAddr,
|
RemoteAddr: remoteAddr,
|
||||||
|
OS: clientOS,
|
||||||
|
Arch: clientArch,
|
||||||
|
Version: clientVersion,
|
||||||
}
|
}
|
||||||
|
|
||||||
Success(c, resp)
|
Success(c, resp)
|
||||||
@@ -185,9 +166,6 @@ func (h *ClientHandler) Update(c *gin.Context) {
|
|||||||
|
|
||||||
client.Nickname = req.Nickname
|
client.Nickname = req.Nickname
|
||||||
client.Rules = req.Rules
|
client.Rules = req.Rules
|
||||||
if req.Plugins != nil {
|
|
||||||
client.Plugins = req.Plugins
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := h.app.GetClientStore().UpdateClient(client); err != nil {
|
if err := h.app.GetClientStore().UpdateClient(client); err != nil {
|
||||||
InternalError(c, err.Error())
|
InternalError(c, err.Error())
|
||||||
@@ -237,8 +215,7 @@ func (h *ClientHandler) Delete(c *gin.Context) {
|
|||||||
func (h *ClientHandler) PushConfig(c *gin.Context) {
|
func (h *ClientHandler) PushConfig(c *gin.Context) {
|
||||||
clientID := c.Param("id")
|
clientID := c.Param("id")
|
||||||
|
|
||||||
online, _, _ := h.app.GetServer().GetClientStatus(clientID)
|
if !h.app.GetServer().IsClientOnline(clientID) {
|
||||||
if !online {
|
|
||||||
ClientNotOnline(c)
|
ClientNotOnline(c)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -291,159 +268,63 @@ func (h *ClientHandler) Restart(c *gin.Context) {
|
|||||||
SuccessWithMessage(c, gin.H{"status": "ok"}, "client restart initiated")
|
SuccessWithMessage(c, gin.H{"status": "ok"}, "client restart initiated")
|
||||||
}
|
}
|
||||||
|
|
||||||
// InstallPlugins 安装插件到客户端
|
|
||||||
// @Summary 安装插件
|
|
||||||
// @Description 将指定插件安装到客户端
|
|
||||||
// @Tags 客户端
|
|
||||||
// @Accept json
|
|
||||||
// @Produce json
|
|
||||||
// @Security Bearer
|
|
||||||
// @Param id path string true "客户端ID"
|
|
||||||
// @Param request body dto.InstallPluginsRequest true "插件列表"
|
|
||||||
// @Success 200 {object} Response
|
|
||||||
// @Failure 400 {object} Response
|
// @Failure 400 {object} Response
|
||||||
// @Router /api/client/{id}/install-plugins [post]
|
// @Router /api/client/{id}/install-plugins [post]
|
||||||
func (h *ClientHandler) InstallPlugins(c *gin.Context) {
|
|
||||||
clientID := c.Param("id")
|
|
||||||
|
|
||||||
online, _, _ := h.app.GetServer().GetClientStatus(clientID)
|
// @Failure 400 {object} Response
|
||||||
if !online {
|
// @Router /api/client/{id}/plugin/{pluginID}/{action} [post]
|
||||||
|
|
||||||
|
|
||||||
|
// GetSystemStats 获取客户端系统状态
|
||||||
|
func (h *ClientHandler) GetSystemStats(c *gin.Context) {
|
||||||
|
clientID := c.Param("id")
|
||||||
|
stats, err := h.app.GetServer().GetClientSystemStats(clientID)
|
||||||
|
if err != nil {
|
||||||
ClientNotOnline(c)
|
ClientNotOnline(c)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Success(c, stats)
|
||||||
var req dto.InstallPluginsRequest
|
|
||||||
if !BindJSON(c, &req) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := h.app.GetServer().InstallPluginsToClient(clientID, req.Plugins); err != nil {
|
|
||||||
InternalError(c, err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
Success(c, gin.H{"status": "ok"})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// PluginAction 客户端插件操作
|
// GetScreenshot 获取客户端截图
|
||||||
// @Summary 插件操作
|
func (h *ClientHandler) GetScreenshot(c *gin.Context) {
|
||||||
// @Description 对客户端插件执行操作(start/stop/restart/config/delete)
|
|
||||||
// @Tags 客户端
|
|
||||||
// @Accept json
|
|
||||||
// @Produce json
|
|
||||||
// @Security Bearer
|
|
||||||
// @Param id path string true "客户端ID"
|
|
||||||
// @Param pluginID path string true "插件实例ID"
|
|
||||||
// @Param action path string true "操作类型" Enums(start, stop, restart, config, delete)
|
|
||||||
// @Param request body dto.ClientPluginActionRequest false "操作参数"
|
|
||||||
// @Success 200 {object} Response
|
|
||||||
// @Failure 400 {object} Response
|
|
||||||
// @Router /api/client/{id}/plugin/{pluginID}/{action} [post]
|
|
||||||
func (h *ClientHandler) PluginAction(c *gin.Context) {
|
|
||||||
clientID := c.Param("id")
|
clientID := c.Param("id")
|
||||||
pluginID := c.Param("pluginID")
|
quality := 0
|
||||||
action := c.Param("action")
|
if q, ok := c.GetQuery("quality"); ok {
|
||||||
|
fmt.Sscanf(q, "%d", &quality)
|
||||||
var req dto.ClientPluginActionRequest
|
|
||||||
c.ShouldBindJSON(&req) // 忽略错误,使用默认值
|
|
||||||
|
|
||||||
// 通过 pluginID 查找插件信息
|
|
||||||
client, err := h.app.GetClientStore().GetClient(clientID)
|
|
||||||
if err != nil {
|
|
||||||
NotFound(c, "client not found")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var pluginName string
|
|
||||||
for _, p := range client.Plugins {
|
|
||||||
if p.ID == pluginID {
|
|
||||||
pluginName = p.Name
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if pluginName == "" {
|
|
||||||
NotFound(c, "plugin not found")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if req.RuleName == "" {
|
|
||||||
req.RuleName = pluginName
|
|
||||||
}
|
|
||||||
|
|
||||||
switch action {
|
|
||||||
case "start":
|
|
||||||
err = h.app.GetServer().StartClientPlugin(clientID, pluginID, pluginName, req.RuleName)
|
|
||||||
case "stop":
|
|
||||||
err = h.app.GetServer().StopClientPlugin(clientID, pluginID, pluginName, req.RuleName)
|
|
||||||
case "restart":
|
|
||||||
err = h.app.GetServer().RestartClientPlugin(clientID, pluginID, pluginName, req.RuleName)
|
|
||||||
case "config":
|
|
||||||
if req.Config == nil {
|
|
||||||
BadRequest(c, "config required")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
err = h.app.GetServer().UpdateClientPluginConfig(clientID, pluginID, pluginName, req.RuleName, req.Config, req.Restart)
|
|
||||||
case "delete":
|
|
||||||
err = h.deleteClientPlugin(clientID, pluginID)
|
|
||||||
default:
|
|
||||||
BadRequest(c, "unknown action: "+action)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
screenshot, err := h.app.GetServer().GetClientScreenshot(clientID, quality)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
InternalError(c, err.Error())
|
InternalError(c, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
Success(c, gin.H{
|
Success(c, screenshot)
|
||||||
"status": "ok",
|
|
||||||
"action": action,
|
|
||||||
"plugin_id": pluginID,
|
|
||||||
"plugin": pluginName,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *ClientHandler) deleteClientPlugin(clientID, pluginID string) error {
|
// ExecuteShellRequest Shell 执行请求体
|
||||||
client, err := h.app.GetClientStore().GetClient(clientID)
|
type ExecuteShellRequest struct {
|
||||||
|
Command string `json:"command" binding:"required"`
|
||||||
|
Timeout int `json:"timeout"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecuteShell 执行 Shell 命令
|
||||||
|
func (h *ClientHandler) ExecuteShell(c *gin.Context) {
|
||||||
|
clientID := c.Param("id")
|
||||||
|
var req ExecuteShellRequest
|
||||||
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
|
BadRequest(c, "Invalid request: "+err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := h.app.GetServer().ExecuteClientShell(clientID, req.Command, req.Timeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("client not found")
|
InternalError(c, err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var newPlugins []db.ClientPlugin
|
Success(c, result)
|
||||||
var pluginName string
|
|
||||||
var pluginPort int
|
|
||||||
found := false
|
|
||||||
for _, p := range client.Plugins {
|
|
||||||
if p.ID == pluginID {
|
|
||||||
found = true
|
|
||||||
pluginName = p.Name
|
|
||||||
pluginPort = p.RemotePort
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
newPlugins = append(newPlugins, p)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !found {
|
|
||||||
return fmt.Errorf("plugin %s not found", pluginID)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 删除插件管理的代理规则
|
|
||||||
var newRules []protocol.ProxyRule
|
|
||||||
for _, r := range client.Rules {
|
|
||||||
if r.PluginManaged && r.Name == pluginName {
|
|
||||||
continue // 跳过此插件的规则
|
|
||||||
}
|
|
||||||
newRules = append(newRules, r)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 停止端口监听器
|
|
||||||
if pluginPort > 0 {
|
|
||||||
h.app.GetServer().StopPluginRule(clientID, pluginPort)
|
|
||||||
}
|
|
||||||
|
|
||||||
client.Plugins = newPlugins
|
|
||||||
client.Rules = newRules
|
|
||||||
return h.app.GetClientStore().UpdateClient(client)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// validateClientID 验证客户端 ID 格式
|
// validateClientID 验证客户端 ID 格式
|
||||||
|
|||||||
@@ -42,10 +42,9 @@ func (h *ConfigHandler) Get(c *gin.Context) {
|
|||||||
HeartbeatTimeout: cfg.Server.HeartbeatTimeout,
|
HeartbeatTimeout: cfg.Server.HeartbeatTimeout,
|
||||||
},
|
},
|
||||||
Web: dto.WebConfigInfo{
|
Web: dto.WebConfigInfo{
|
||||||
Enabled: cfg.Web.Enabled,
|
Enabled: cfg.Server.Web.Enabled,
|
||||||
BindAddr: cfg.Web.BindAddr,
|
BindPort: cfg.Server.Web.BindPort,
|
||||||
BindPort: cfg.Web.BindPort,
|
Username: cfg.Server.Web.Username,
|
||||||
Username: cfg.Web.Username,
|
|
||||||
Password: "****",
|
Password: "****",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -93,15 +92,12 @@ func (h *ConfigHandler) Update(c *gin.Context) {
|
|||||||
|
|
||||||
// 更新 Web 配置
|
// 更新 Web 配置
|
||||||
if req.Web != nil {
|
if req.Web != nil {
|
||||||
cfg.Web.Enabled = req.Web.Enabled
|
cfg.Server.Web.Enabled = req.Web.Enabled
|
||||||
if req.Web.BindAddr != "" {
|
|
||||||
cfg.Web.BindAddr = req.Web.BindAddr
|
|
||||||
}
|
|
||||||
if req.Web.BindPort > 0 {
|
if req.Web.BindPort > 0 {
|
||||||
cfg.Web.BindPort = req.Web.BindPort
|
cfg.Server.Web.BindPort = req.Web.BindPort
|
||||||
}
|
}
|
||||||
cfg.Web.Username = req.Web.Username
|
cfg.Server.Web.Username = req.Web.Username
|
||||||
cfg.Web.Password = req.Web.Password
|
cfg.Server.Web.Password = req.Web.Password
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := h.app.SaveConfig(); err != nil {
|
if err := h.app.SaveConfig(); err != nil {
|
||||||
|
|||||||
@@ -165,6 +165,12 @@ func performSelfUpdate(downloadURL string, restart bool) error {
|
|||||||
// performWindowsUpdate Windows 平台更新
|
// performWindowsUpdate Windows 平台更新
|
||||||
func performWindowsUpdate(newFile, currentPath string, restart bool) error {
|
func performWindowsUpdate(newFile, currentPath string, restart bool) error {
|
||||||
batchScript := fmt.Sprintf(`@echo off
|
batchScript := fmt.Sprintf(`@echo off
|
||||||
|
:: Check for admin rights, request UAC elevation if needed
|
||||||
|
net session >nul 2>&1
|
||||||
|
if %%errorlevel%% neq 0 (
|
||||||
|
powershell -Command "Start-Process cmd -ArgumentList '/C \\"\"%%~f0\"\"' -Verb RunAs"
|
||||||
|
exit /b
|
||||||
|
)
|
||||||
ping 127.0.0.1 -n 2 > nul
|
ping 127.0.0.1 -n 2 > nul
|
||||||
del "%s"
|
del "%s"
|
||||||
move "%s" "%s"
|
move "%s" "%s"
|
||||||
|
|||||||
89
internal/server/router/handler/install.go
Normal file
89
internal/server/router/handler/install.go
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
package handler
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/rand"
|
||||||
|
"encoding/hex"
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/gotunnel/internal/server/db"
|
||||||
|
)
|
||||||
|
|
||||||
|
// InstallHandler 安装处理器
|
||||||
|
type InstallHandler struct {
|
||||||
|
app AppInterface
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewInstallHandler 创建安装处理器
|
||||||
|
func NewInstallHandler(app AppInterface) *InstallHandler {
|
||||||
|
return &InstallHandler{app: app}
|
||||||
|
}
|
||||||
|
|
||||||
|
// InstallCommandResponse 安装命令响应
|
||||||
|
type InstallCommandResponse struct {
|
||||||
|
Token string `json:"token"`
|
||||||
|
Commands map[string]string `json:"commands"`
|
||||||
|
ExpiresAt int64 `json:"expires_at"`
|
||||||
|
ServerAddr string `json:"server_addr"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GenerateInstallCommand 生成安装命令
|
||||||
|
// @Summary 生成客户端安装命令
|
||||||
|
// @Tags install
|
||||||
|
// @Produce json
|
||||||
|
// @Success 200 {object} InstallCommandResponse
|
||||||
|
// @Router /api/install/generate [post]
|
||||||
|
func (h *InstallHandler) GenerateInstallCommand(c *gin.Context) {
|
||||||
|
// 生成随机token
|
||||||
|
tokenBytes := make([]byte, 32)
|
||||||
|
if _, err := rand.Read(tokenBytes); err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "生成token失败"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
token := hex.EncodeToString(tokenBytes)
|
||||||
|
|
||||||
|
// 保存到数据库
|
||||||
|
now := time.Now().Unix()
|
||||||
|
installToken := &db.InstallToken{
|
||||||
|
Token: token,
|
||||||
|
CreatedAt: now,
|
||||||
|
Used: false,
|
||||||
|
}
|
||||||
|
|
||||||
|
store, ok := h.app.GetClientStore().(db.InstallTokenStore)
|
||||||
|
if !ok {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "存储不支持安装token"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := store.CreateInstallToken(installToken); err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "保存token失败"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取服务器地址
|
||||||
|
serverAddr := fmt.Sprintf("%s:%d", h.app.GetConfig().Server.BindAddr, h.app.GetServer().GetBindPort())
|
||||||
|
if h.app.GetConfig().Server.BindAddr == "" || h.app.GetConfig().Server.BindAddr == "0.0.0.0" {
|
||||||
|
serverAddr = fmt.Sprintf("your-server-ip:%d", h.app.GetServer().GetBindPort())
|
||||||
|
}
|
||||||
|
|
||||||
|
// 生成安装命令
|
||||||
|
expiresAt := now + 3600 // 1小时过期
|
||||||
|
commands := map[string]string{
|
||||||
|
"linux": fmt.Sprintf("curl -fsSL https://raw.githubusercontent.com/gotunnel/gotunnel/main/scripts/install.sh | bash -s -- -s %s -t %s",
|
||||||
|
serverAddr, token),
|
||||||
|
"macos": fmt.Sprintf("curl -fsSL https://raw.githubusercontent.com/gotunnel/gotunnel/main/scripts/install.sh | bash -s -- -s %s -t %s",
|
||||||
|
serverAddr, token),
|
||||||
|
"windows": fmt.Sprintf("powershell -c \"irm https://raw.githubusercontent.com/gotunnel/gotunnel/main/scripts/install.ps1 | iex; Install-GoTunnel -Server '%s' -Token '%s'\"",
|
||||||
|
serverAddr, token),
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(http.StatusOK, InstallCommandResponse{
|
||||||
|
Token: token,
|
||||||
|
Commands: commands,
|
||||||
|
ExpiresAt: expiresAt,
|
||||||
|
ServerAddr: serverAddr,
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -13,86 +13,38 @@ type AppInterface interface {
|
|||||||
GetConfig() *config.ServerConfig
|
GetConfig() *config.ServerConfig
|
||||||
GetConfigPath() string
|
GetConfigPath() string
|
||||||
SaveConfig() error
|
SaveConfig() error
|
||||||
GetJSPluginStore() db.JSPluginStore
|
GetTrafficStore() db.TrafficStore
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServerInterface 服务端接口
|
// ServerInterface 服务端接口
|
||||||
type ServerInterface interface {
|
type ServerInterface interface {
|
||||||
GetClientStatus(clientID string) (online bool, lastPing string, remoteAddr string)
|
IsClientOnline(clientID string) bool
|
||||||
|
GetClientStatus(clientID string) (online bool, lastPing, remoteAddr, clientName, clientOS, clientArch, clientVersion string)
|
||||||
GetAllClientStatus() map[string]struct {
|
GetAllClientStatus() map[string]struct {
|
||||||
Online bool
|
Online bool
|
||||||
LastPing string
|
LastPing string
|
||||||
RemoteAddr string
|
RemoteAddr string
|
||||||
|
Name string
|
||||||
|
OS string
|
||||||
|
Arch string
|
||||||
|
Version string
|
||||||
}
|
}
|
||||||
ReloadConfig() error
|
ReloadConfig() error
|
||||||
GetBindAddr() string
|
GetBindAddr() string
|
||||||
GetBindPort() int
|
GetBindPort() int
|
||||||
PushConfigToClient(clientID string) error
|
PushConfigToClient(clientID string) error
|
||||||
DisconnectClient(clientID string) error
|
DisconnectClient(clientID string) error
|
||||||
GetPluginList() []PluginInfo
|
|
||||||
EnablePlugin(name string) error
|
|
||||||
DisablePlugin(name string) error
|
|
||||||
InstallPluginsToClient(clientID string, plugins []string) error
|
|
||||||
GetPluginConfigSchema(name string) ([]ConfigField, error)
|
|
||||||
SyncPluginConfigToClient(clientID string, pluginName string, config map[string]string) error
|
|
||||||
InstallJSPluginToClient(clientID string, req JSPluginInstallRequest) error
|
|
||||||
RestartClient(clientID string) error
|
RestartClient(clientID string) error
|
||||||
StartClientPlugin(clientID, pluginID, pluginName, ruleName string) error
|
|
||||||
StopClientPlugin(clientID, pluginID, pluginName, ruleName string) error
|
|
||||||
RestartClientPlugin(clientID, pluginID, pluginName, ruleName string) error
|
|
||||||
UpdateClientPluginConfig(clientID, pluginID, pluginName, ruleName string, config map[string]string, restart bool) error
|
|
||||||
SendUpdateToClient(clientID, downloadURL string) error
|
SendUpdateToClient(clientID, downloadURL string) error
|
||||||
// 日志流
|
// 日志流
|
||||||
StartClientLogStream(clientID, sessionID string, lines int, follow bool, level string) (<-chan protocol.LogEntry, error)
|
StartClientLogStream(clientID, sessionID string, lines int, follow bool, level string) (<-chan protocol.LogEntry, error)
|
||||||
StopClientLogStream(sessionID string)
|
StopClientLogStream(sessionID string)
|
||||||
// 插件状态查询
|
|
||||||
GetClientPluginStatus(clientID string) ([]protocol.PluginStatusEntry, error)
|
|
||||||
// 插件规则管理
|
|
||||||
StartPluginRule(clientID string, rule protocol.ProxyRule) error
|
|
||||||
StopPluginRule(clientID string, remotePort int) error
|
|
||||||
// 端口检查
|
// 端口检查
|
||||||
IsPortAvailable(port int, excludeClientID string) bool
|
IsPortAvailable(port int, excludeClientID string) bool
|
||||||
// 插件 API 代理
|
// 系统状态
|
||||||
ProxyPluginAPIRequest(clientID string, req protocol.PluginAPIRequest) (*protocol.PluginAPIResponse, error)
|
GetClientSystemStats(clientID string) (*protocol.SystemStatsResponse, error)
|
||||||
}
|
// 截图
|
||||||
|
GetClientScreenshot(clientID string, quality int) (*protocol.ScreenshotResponse, error)
|
||||||
// ConfigField 配置字段
|
// Shell 执行
|
||||||
type ConfigField struct {
|
ExecuteClientShell(clientID, command string, timeout int) (*protocol.ShellExecuteResponse, error)
|
||||||
Key string `json:"key"`
|
|
||||||
Label string `json:"label"`
|
|
||||||
Type string `json:"type"`
|
|
||||||
Default string `json:"default,omitempty"`
|
|
||||||
Required bool `json:"required,omitempty"`
|
|
||||||
Options []string `json:"options,omitempty"`
|
|
||||||
Description string `json:"description,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// RuleSchema 规则表单模式
|
|
||||||
type RuleSchema struct {
|
|
||||||
NeedsLocalAddr bool `json:"needs_local_addr"`
|
|
||||||
ExtraFields []ConfigField `json:"extra_fields,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// PluginInfo 插件信息
|
|
||||||
type PluginInfo struct {
|
|
||||||
Name string `json:"name"`
|
|
||||||
Version string `json:"version"`
|
|
||||||
Type string `json:"type"`
|
|
||||||
Description string `json:"description"`
|
|
||||||
Source string `json:"source"`
|
|
||||||
Icon string `json:"icon,omitempty"`
|
|
||||||
Enabled bool `json:"enabled"`
|
|
||||||
RuleSchema *RuleSchema `json:"rule_schema,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// JSPluginInstallRequest JS 插件安装请求
|
|
||||||
type JSPluginInstallRequest struct {
|
|
||||||
PluginID string `json:"plugin_id"`
|
|
||||||
PluginName string `json:"plugin_name"`
|
|
||||||
Source string `json:"source"`
|
|
||||||
Signature string `json:"signature"`
|
|
||||||
RuleName string `json:"rule_name"`
|
|
||||||
RemotePort int `json:"remote_port"`
|
|
||||||
Config map[string]string `json:"config"`
|
|
||||||
AutoStart bool `json:"auto_start"`
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,220 +0,0 @@
|
|||||||
package handler
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
"github.com/gotunnel/internal/server/db"
|
|
||||||
// removed router import
|
|
||||||
"github.com/gotunnel/internal/server/router/dto"
|
|
||||||
)
|
|
||||||
|
|
||||||
// JSPluginHandler JS 插件处理器
|
|
||||||
type JSPluginHandler struct {
|
|
||||||
app AppInterface
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewJSPluginHandler 创建 JS 插件处理器
|
|
||||||
func NewJSPluginHandler(app AppInterface) *JSPluginHandler {
|
|
||||||
return &JSPluginHandler{app: app}
|
|
||||||
}
|
|
||||||
|
|
||||||
// List 获取 JS 插件列表
|
|
||||||
// @Summary 获取所有 JS 插件
|
|
||||||
// @Description 返回所有注册的 JS 插件
|
|
||||||
// @Tags JS插件
|
|
||||||
// @Produce json
|
|
||||||
// @Security Bearer
|
|
||||||
// @Success 200 {object} Response{data=[]db.JSPlugin}
|
|
||||||
// @Router /api/js-plugins [get]
|
|
||||||
func (h *JSPluginHandler) List(c *gin.Context) {
|
|
||||||
plugins, err := h.app.GetJSPluginStore().GetAllJSPlugins()
|
|
||||||
if err != nil {
|
|
||||||
InternalError(c, err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if plugins == nil {
|
|
||||||
plugins = []db.JSPlugin{}
|
|
||||||
}
|
|
||||||
Success(c, plugins)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create 创建 JS 插件
|
|
||||||
// @Summary 创建 JS 插件
|
|
||||||
// @Description 创建新的 JS 插件
|
|
||||||
// @Tags JS插件
|
|
||||||
// @Accept json
|
|
||||||
// @Produce json
|
|
||||||
// @Security Bearer
|
|
||||||
// @Param request body dto.JSPluginCreateRequest true "插件信息"
|
|
||||||
// @Success 200 {object} Response
|
|
||||||
// @Failure 400 {object} Response
|
|
||||||
// @Router /api/js-plugins [post]
|
|
||||||
func (h *JSPluginHandler) Create(c *gin.Context) {
|
|
||||||
var req dto.JSPluginCreateRequest
|
|
||||||
if !BindJSON(c, &req) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
plugin := &db.JSPlugin{
|
|
||||||
Name: req.Name,
|
|
||||||
Source: req.Source,
|
|
||||||
Signature: req.Signature,
|
|
||||||
Description: req.Description,
|
|
||||||
Author: req.Author,
|
|
||||||
Config: req.Config,
|
|
||||||
AutoStart: req.AutoStart,
|
|
||||||
Enabled: true,
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := h.app.GetJSPluginStore().SaveJSPlugin(plugin); err != nil {
|
|
||||||
InternalError(c, err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
Success(c, gin.H{"status": "ok"})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get 获取单个 JS 插件
|
|
||||||
// @Summary 获取 JS 插件详情
|
|
||||||
// @Description 获取指定 JS 插件的详细信息
|
|
||||||
// @Tags JS插件
|
|
||||||
// @Produce json
|
|
||||||
// @Security Bearer
|
|
||||||
// @Param name path string true "插件名称"
|
|
||||||
// @Success 200 {object} Response{data=db.JSPlugin}
|
|
||||||
// @Failure 404 {object} Response
|
|
||||||
// @Router /api/js-plugin/{name} [get]
|
|
||||||
func (h *JSPluginHandler) Get(c *gin.Context) {
|
|
||||||
name := c.Param("name")
|
|
||||||
|
|
||||||
plugin, err := h.app.GetJSPluginStore().GetJSPlugin(name)
|
|
||||||
if err != nil {
|
|
||||||
NotFound(c, "plugin not found")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
Success(c, plugin)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update 更新 JS 插件
|
|
||||||
// @Summary 更新 JS 插件
|
|
||||||
// @Description 更新指定 JS 插件的信息
|
|
||||||
// @Tags JS插件
|
|
||||||
// @Accept json
|
|
||||||
// @Produce json
|
|
||||||
// @Security Bearer
|
|
||||||
// @Param name path string true "插件名称"
|
|
||||||
// @Param request body dto.JSPluginUpdateRequest true "更新内容"
|
|
||||||
// @Success 200 {object} Response
|
|
||||||
// @Failure 400 {object} Response
|
|
||||||
// @Router /api/js-plugin/{name} [put]
|
|
||||||
func (h *JSPluginHandler) Update(c *gin.Context) {
|
|
||||||
name := c.Param("name")
|
|
||||||
|
|
||||||
var req dto.JSPluginUpdateRequest
|
|
||||||
if !BindJSON(c, &req) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
plugin := &db.JSPlugin{
|
|
||||||
Name: name,
|
|
||||||
Source: req.Source,
|
|
||||||
Signature: req.Signature,
|
|
||||||
Description: req.Description,
|
|
||||||
Author: req.Author,
|
|
||||||
Config: req.Config,
|
|
||||||
AutoStart: req.AutoStart,
|
|
||||||
Enabled: req.Enabled,
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := h.app.GetJSPluginStore().SaveJSPlugin(plugin); err != nil {
|
|
||||||
InternalError(c, err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
Success(c, gin.H{"status": "ok"})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete 删除 JS 插件
|
|
||||||
// @Summary 删除 JS 插件
|
|
||||||
// @Description 删除指定的 JS 插件
|
|
||||||
// @Tags JS插件
|
|
||||||
// @Produce json
|
|
||||||
// @Security Bearer
|
|
||||||
// @Param name path string true "插件名称"
|
|
||||||
// @Success 200 {object} Response
|
|
||||||
// @Router /api/js-plugin/{name} [delete]
|
|
||||||
func (h *JSPluginHandler) Delete(c *gin.Context) {
|
|
||||||
name := c.Param("name")
|
|
||||||
|
|
||||||
if err := h.app.GetJSPluginStore().DeleteJSPlugin(name); err != nil {
|
|
||||||
InternalError(c, err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
Success(c, gin.H{"status": "ok"})
|
|
||||||
}
|
|
||||||
|
|
||||||
// PushToClient 推送 JS 插件到客户端
|
|
||||||
// @Summary 推送插件到客户端
|
|
||||||
// @Description 将 JS 插件推送到指定客户端
|
|
||||||
// @Tags JS插件
|
|
||||||
// @Accept json
|
|
||||||
// @Produce json
|
|
||||||
// @Security Bearer
|
|
||||||
// @Param name path string true "插件名称"
|
|
||||||
// @Param clientID path string true "客户端ID"
|
|
||||||
// @Param request body dto.JSPluginPushRequest false "推送配置"
|
|
||||||
// @Success 200 {object} Response
|
|
||||||
// @Failure 400 {object} Response
|
|
||||||
// @Failure 404 {object} Response
|
|
||||||
// @Router /api/js-plugin/{name}/push/{clientID} [post]
|
|
||||||
func (h *JSPluginHandler) PushToClient(c *gin.Context) {
|
|
||||||
pluginName := c.Param("name")
|
|
||||||
clientID := c.Param("clientID")
|
|
||||||
|
|
||||||
// 解析请求体(可选)
|
|
||||||
var pushReq dto.JSPluginPushRequest
|
|
||||||
c.ShouldBindJSON(&pushReq) // 忽略错误,允许空请求体
|
|
||||||
|
|
||||||
// 检查客户端是否在线
|
|
||||||
online, _, _ := h.app.GetServer().GetClientStatus(clientID)
|
|
||||||
if !online {
|
|
||||||
ClientNotOnline(c)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取插件
|
|
||||||
plugin, err := h.app.GetJSPluginStore().GetJSPlugin(pluginName)
|
|
||||||
if err != nil {
|
|
||||||
NotFound(c, "plugin not found")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if !plugin.Enabled {
|
|
||||||
Error(c, 400, CodePluginDisabled, "plugin is disabled")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 推送到客户端
|
|
||||||
req := JSPluginInstallRequest{
|
|
||||||
PluginName: plugin.Name,
|
|
||||||
Source: plugin.Source,
|
|
||||||
Signature: plugin.Signature,
|
|
||||||
RuleName: plugin.Name,
|
|
||||||
RemotePort: pushReq.RemotePort,
|
|
||||||
Config: plugin.Config,
|
|
||||||
AutoStart: plugin.AutoStart,
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := h.app.GetServer().InstallJSPluginToClient(clientID, req); err != nil {
|
|
||||||
InternalError(c, err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
Success(c, gin.H{
|
|
||||||
"status": "ok",
|
|
||||||
"plugin": pluginName,
|
|
||||||
"client": clientID,
|
|
||||||
"remote_port": pushReq.RemotePort,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -35,8 +35,7 @@ func (h *LogHandler) StreamLogs(c *gin.Context) {
|
|||||||
clientID := c.Param("id")
|
clientID := c.Param("id")
|
||||||
|
|
||||||
// 检查客户端是否在线
|
// 检查客户端是否在线
|
||||||
online, _, _ := h.app.GetServer().GetClientStatus(clientID)
|
if !h.app.GetServer().IsClientOnline(clientID) {
|
||||||
if !online {
|
|
||||||
c.JSON(400, gin.H{"code": 400, "message": "client not online"})
|
c.JSON(400, gin.H{"code": 400, "message": "client not online"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,417 +0,0 @@
|
|||||||
package handler
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
"github.com/gotunnel/internal/server/db"
|
|
||||||
"github.com/gotunnel/internal/server/router/dto"
|
|
||||||
"github.com/gotunnel/pkg/plugin"
|
|
||||||
)
|
|
||||||
|
|
||||||
// PluginHandler 插件处理器
|
|
||||||
type PluginHandler struct {
|
|
||||||
app AppInterface
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewPluginHandler 创建插件处理器
|
|
||||||
func NewPluginHandler(app AppInterface) *PluginHandler {
|
|
||||||
return &PluginHandler{app: app}
|
|
||||||
}
|
|
||||||
|
|
||||||
// List 获取插件列表
|
|
||||||
// @Summary 获取所有插件
|
|
||||||
// @Description 返回服务端所有注册的插件
|
|
||||||
// @Tags 插件
|
|
||||||
// @Produce json
|
|
||||||
// @Security Bearer
|
|
||||||
// @Success 200 {object} Response{data=[]dto.PluginInfo}
|
|
||||||
// @Router /api/plugins [get]
|
|
||||||
func (h *PluginHandler) List(c *gin.Context) {
|
|
||||||
plugins := h.app.GetServer().GetPluginList()
|
|
||||||
|
|
||||||
result := make([]dto.PluginInfo, len(plugins))
|
|
||||||
for i, p := range plugins {
|
|
||||||
result[i] = dto.PluginInfo{
|
|
||||||
Name: p.Name,
|
|
||||||
Version: p.Version,
|
|
||||||
Type: p.Type,
|
|
||||||
Description: p.Description,
|
|
||||||
Source: p.Source,
|
|
||||||
Icon: p.Icon,
|
|
||||||
Enabled: p.Enabled,
|
|
||||||
}
|
|
||||||
if p.RuleSchema != nil {
|
|
||||||
result[i].RuleSchema = &dto.RuleSchema{
|
|
||||||
NeedsLocalAddr: p.RuleSchema.NeedsLocalAddr,
|
|
||||||
ExtraFields: convertRouterConfigFields(p.RuleSchema.ExtraFields),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Success(c, result)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enable 启用插件
|
|
||||||
// @Summary 启用插件
|
|
||||||
// @Description 启用指定插件
|
|
||||||
// @Tags 插件
|
|
||||||
// @Produce json
|
|
||||||
// @Security Bearer
|
|
||||||
// @Param name path string true "插件名称"
|
|
||||||
// @Success 200 {object} Response
|
|
||||||
// @Failure 400 {object} Response
|
|
||||||
// @Router /api/plugin/{name}/enable [post]
|
|
||||||
func (h *PluginHandler) Enable(c *gin.Context) {
|
|
||||||
name := c.Param("name")
|
|
||||||
|
|
||||||
if err := h.app.GetServer().EnablePlugin(name); err != nil {
|
|
||||||
BadRequest(c, err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
Success(c, gin.H{"status": "ok"})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Disable 禁用插件
|
|
||||||
// @Summary 禁用插件
|
|
||||||
// @Description 禁用指定插件
|
|
||||||
// @Tags 插件
|
|
||||||
// @Produce json
|
|
||||||
// @Security Bearer
|
|
||||||
// @Param name path string true "插件名称"
|
|
||||||
// @Success 200 {object} Response
|
|
||||||
// @Failure 400 {object} Response
|
|
||||||
// @Router /api/plugin/{name}/disable [post]
|
|
||||||
func (h *PluginHandler) Disable(c *gin.Context) {
|
|
||||||
name := c.Param("name")
|
|
||||||
|
|
||||||
if err := h.app.GetServer().DisablePlugin(name); err != nil {
|
|
||||||
BadRequest(c, err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
Success(c, gin.H{"status": "ok"})
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetRuleSchemas 获取规则配置模式
|
|
||||||
// @Summary 获取规则模式
|
|
||||||
// @Description 返回所有协议类型的配置模式
|
|
||||||
// @Tags 插件
|
|
||||||
// @Produce json
|
|
||||||
// @Security Bearer
|
|
||||||
// @Success 200 {object} Response{data=map[string]dto.RuleSchema}
|
|
||||||
// @Router /api/rule-schemas [get]
|
|
||||||
func (h *PluginHandler) GetRuleSchemas(c *gin.Context) {
|
|
||||||
// 获取内置协议模式
|
|
||||||
schemas := make(map[string]dto.RuleSchema)
|
|
||||||
for name, schema := range plugin.BuiltinRuleSchemas() {
|
|
||||||
schemas[name] = dto.RuleSchema{
|
|
||||||
NeedsLocalAddr: schema.NeedsLocalAddr,
|
|
||||||
ExtraFields: convertConfigFields(schema.ExtraFields),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 添加已注册插件的模式
|
|
||||||
plugins := h.app.GetServer().GetPluginList()
|
|
||||||
for _, p := range plugins {
|
|
||||||
if p.RuleSchema != nil {
|
|
||||||
schemas[p.Name] = dto.RuleSchema{
|
|
||||||
NeedsLocalAddr: p.RuleSchema.NeedsLocalAddr,
|
|
||||||
ExtraFields: convertRouterConfigFields(p.RuleSchema.ExtraFields),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Success(c, schemas)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetClientConfig 获取客户端插件配置
|
|
||||||
// @Summary 获取客户端插件配置
|
|
||||||
// @Description 获取客户端上指定插件的配置
|
|
||||||
// @Tags 插件
|
|
||||||
// @Produce json
|
|
||||||
// @Security Bearer
|
|
||||||
// @Param clientID path string true "客户端ID"
|
|
||||||
// @Param pluginName path string true "插件名称"
|
|
||||||
// @Success 200 {object} Response{data=dto.PluginConfigResponse}
|
|
||||||
// @Failure 404 {object} Response
|
|
||||||
// @Router /api/client-plugin/{clientID}/{pluginName}/config [get]
|
|
||||||
func (h *PluginHandler) GetClientConfig(c *gin.Context) {
|
|
||||||
clientID := c.Param("clientID")
|
|
||||||
pluginName := c.Param("pluginName")
|
|
||||||
|
|
||||||
client, err := h.app.GetClientStore().GetClient(clientID)
|
|
||||||
if err != nil {
|
|
||||||
NotFound(c, "client not found")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 查找客户端的插件
|
|
||||||
var clientPlugin *db.ClientPlugin
|
|
||||||
for i, p := range client.Plugins {
|
|
||||||
if p.Name == pluginName {
|
|
||||||
clientPlugin = &client.Plugins[i]
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if clientPlugin == nil {
|
|
||||||
NotFound(c, "plugin not installed on client")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var schemaFields []dto.ConfigField
|
|
||||||
|
|
||||||
// 优先使用客户端插件保存的 ConfigSchema
|
|
||||||
if len(clientPlugin.ConfigSchema) > 0 {
|
|
||||||
for _, f := range clientPlugin.ConfigSchema {
|
|
||||||
schemaFields = append(schemaFields, dto.ConfigField{
|
|
||||||
Key: f.Key,
|
|
||||||
Label: f.Label,
|
|
||||||
Type: f.Type,
|
|
||||||
Default: f.Default,
|
|
||||||
Required: f.Required,
|
|
||||||
Options: f.Options,
|
|
||||||
Description: f.Description,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// 尝试从内置插件获取配置模式
|
|
||||||
schema, err := h.app.GetServer().GetPluginConfigSchema(pluginName)
|
|
||||||
if err != nil {
|
|
||||||
// 如果内置插件中找不到,尝试从 JS 插件获取
|
|
||||||
jsPlugin, jsErr := h.app.GetJSPluginStore().GetJSPlugin(pluginName)
|
|
||||||
if jsErr == nil {
|
|
||||||
// 使用 JS 插件的 config 作为动态 schema
|
|
||||||
for key := range jsPlugin.Config {
|
|
||||||
schemaFields = append(schemaFields, dto.ConfigField{
|
|
||||||
Key: key,
|
|
||||||
Label: key,
|
|
||||||
Type: "string",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
schemaFields = convertRouterConfigFields(schema)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 添加 remote_port 作为系统配置字段(始终显示)
|
|
||||||
schemaFields = append([]dto.ConfigField{{
|
|
||||||
Key: "remote_port",
|
|
||||||
Label: "远程端口",
|
|
||||||
Type: "number",
|
|
||||||
Description: "服务端监听端口,修改后需重启插件生效",
|
|
||||||
}}, schemaFields...)
|
|
||||||
|
|
||||||
// 添加 Auth 配置字段
|
|
||||||
schemaFields = append(schemaFields, dto.ConfigField{
|
|
||||||
Key: "auth_enabled",
|
|
||||||
Label: "启用认证",
|
|
||||||
Type: "bool",
|
|
||||||
Description: "启用 HTTP Basic Auth 保护",
|
|
||||||
}, dto.ConfigField{
|
|
||||||
Key: "auth_username",
|
|
||||||
Label: "认证用户名",
|
|
||||||
Type: "string",
|
|
||||||
Description: "HTTP Basic Auth 用户名",
|
|
||||||
}, dto.ConfigField{
|
|
||||||
Key: "auth_password",
|
|
||||||
Label: "认证密码",
|
|
||||||
Type: "password",
|
|
||||||
Description: "HTTP Basic Auth 密码",
|
|
||||||
})
|
|
||||||
|
|
||||||
// 构建配置值
|
|
||||||
config := clientPlugin.Config
|
|
||||||
if config == nil {
|
|
||||||
config = make(map[string]string)
|
|
||||||
}
|
|
||||||
// 将 remote_port 加入配置
|
|
||||||
if clientPlugin.RemotePort > 0 {
|
|
||||||
config["remote_port"] = fmt.Sprintf("%d", clientPlugin.RemotePort)
|
|
||||||
}
|
|
||||||
// 将 Auth 配置加入
|
|
||||||
if clientPlugin.AuthEnabled {
|
|
||||||
config["auth_enabled"] = "true"
|
|
||||||
} else {
|
|
||||||
config["auth_enabled"] = "false"
|
|
||||||
}
|
|
||||||
config["auth_username"] = clientPlugin.AuthUsername
|
|
||||||
config["auth_password"] = clientPlugin.AuthPassword
|
|
||||||
|
|
||||||
Success(c, dto.PluginConfigResponse{
|
|
||||||
PluginName: pluginName,
|
|
||||||
Schema: schemaFields,
|
|
||||||
Config: config,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// UpdateClientConfig 更新客户端插件配置
|
|
||||||
// @Summary 更新客户端插件配置
|
|
||||||
// @Description 更新客户端上指定插件的配置
|
|
||||||
// @Tags 插件
|
|
||||||
// @Accept json
|
|
||||||
// @Produce json
|
|
||||||
// @Security Bearer
|
|
||||||
// @Param clientID path string true "客户端ID"
|
|
||||||
// @Param pluginName path string true "插件名称"
|
|
||||||
// @Param request body dto.PluginConfigRequest true "配置内容"
|
|
||||||
// @Success 200 {object} Response
|
|
||||||
// @Failure 400 {object} Response
|
|
||||||
// @Failure 404 {object} Response
|
|
||||||
// @Router /api/client-plugin/{clientID}/{pluginName}/config [put]
|
|
||||||
func (h *PluginHandler) UpdateClientConfig(c *gin.Context) {
|
|
||||||
clientID := c.Param("clientID")
|
|
||||||
pluginName := c.Param("pluginName")
|
|
||||||
|
|
||||||
var req dto.PluginConfigRequest
|
|
||||||
if !BindJSON(c, &req) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
client, err := h.app.GetClientStore().GetClient(clientID)
|
|
||||||
if err != nil {
|
|
||||||
NotFound(c, "client not found")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 更新插件配置
|
|
||||||
found := false
|
|
||||||
portChanged := false
|
|
||||||
authChanged := false
|
|
||||||
var oldPort, newPort int
|
|
||||||
for i, p := range client.Plugins {
|
|
||||||
if p.Name == pluginName {
|
|
||||||
oldPort = client.Plugins[i].RemotePort
|
|
||||||
// 提取 remote_port 并单独处理
|
|
||||||
if portStr, ok := req.Config["remote_port"]; ok {
|
|
||||||
fmt.Sscanf(portStr, "%d", &newPort)
|
|
||||||
if newPort > 0 && newPort != oldPort {
|
|
||||||
// 检查新端口是否可用
|
|
||||||
if !h.app.GetServer().IsPortAvailable(newPort, clientID) {
|
|
||||||
BadRequest(c, fmt.Sprintf("port %d is already in use", newPort))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
client.Plugins[i].RemotePort = newPort
|
|
||||||
portChanged = true
|
|
||||||
}
|
|
||||||
delete(req.Config, "remote_port") // 不保存到 Config map
|
|
||||||
}
|
|
||||||
// 提取 Auth 配置并单独处理
|
|
||||||
if authEnabledStr, ok := req.Config["auth_enabled"]; ok {
|
|
||||||
newAuthEnabled := authEnabledStr == "true"
|
|
||||||
if newAuthEnabled != client.Plugins[i].AuthEnabled {
|
|
||||||
client.Plugins[i].AuthEnabled = newAuthEnabled
|
|
||||||
authChanged = true
|
|
||||||
}
|
|
||||||
delete(req.Config, "auth_enabled")
|
|
||||||
}
|
|
||||||
if authUsername, ok := req.Config["auth_username"]; ok {
|
|
||||||
if authUsername != client.Plugins[i].AuthUsername {
|
|
||||||
client.Plugins[i].AuthUsername = authUsername
|
|
||||||
authChanged = true
|
|
||||||
}
|
|
||||||
delete(req.Config, "auth_username")
|
|
||||||
}
|
|
||||||
if authPassword, ok := req.Config["auth_password"]; ok {
|
|
||||||
if authPassword != client.Plugins[i].AuthPassword {
|
|
||||||
client.Plugins[i].AuthPassword = authPassword
|
|
||||||
authChanged = true
|
|
||||||
}
|
|
||||||
delete(req.Config, "auth_password")
|
|
||||||
}
|
|
||||||
client.Plugins[i].Config = req.Config
|
|
||||||
found = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !found {
|
|
||||||
NotFound(c, "plugin not installed on client")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 如果端口变更,同步更新代理规则
|
|
||||||
if portChanged {
|
|
||||||
for i, r := range client.Rules {
|
|
||||||
if r.Name == pluginName && r.PluginManaged {
|
|
||||||
client.Rules[i].RemotePort = newPort
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 停止旧端口监听器
|
|
||||||
if oldPort > 0 {
|
|
||||||
h.app.GetServer().StopPluginRule(clientID, oldPort)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 如果 Auth 配置变更,同步更新代理规则
|
|
||||||
if authChanged {
|
|
||||||
for i, p := range client.Plugins {
|
|
||||||
if p.Name == pluginName {
|
|
||||||
for j, r := range client.Rules {
|
|
||||||
if r.Name == pluginName && r.PluginManaged {
|
|
||||||
client.Rules[j].AuthEnabled = client.Plugins[i].AuthEnabled
|
|
||||||
client.Rules[j].AuthUsername = client.Plugins[i].AuthUsername
|
|
||||||
client.Rules[j].AuthPassword = client.Plugins[i].AuthPassword
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 保存到数据库
|
|
||||||
if err := h.app.GetClientStore().UpdateClient(client); err != nil {
|
|
||||||
InternalError(c, err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 如果客户端在线,同步配置
|
|
||||||
online, _, _ := h.app.GetServer().GetClientStatus(clientID)
|
|
||||||
if online {
|
|
||||||
if err := h.app.GetServer().SyncPluginConfigToClient(clientID, pluginName, req.Config); err != nil {
|
|
||||||
PartialSuccess(c, gin.H{"status": "partial", "port_changed": portChanged}, "config saved but sync failed: "+err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Success(c, gin.H{"status": "ok", "port_changed": portChanged})
|
|
||||||
}
|
|
||||||
|
|
||||||
// convertConfigFields 转换插件配置字段到 DTO
|
|
||||||
func convertConfigFields(fields []plugin.ConfigField) []dto.ConfigField {
|
|
||||||
result := make([]dto.ConfigField, len(fields))
|
|
||||||
for i, f := range fields {
|
|
||||||
result[i] = dto.ConfigField{
|
|
||||||
Key: f.Key,
|
|
||||||
Label: f.Label,
|
|
||||||
Type: string(f.Type),
|
|
||||||
Default: f.Default,
|
|
||||||
Required: f.Required,
|
|
||||||
Options: f.Options,
|
|
||||||
Description: f.Description,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
// convertRouterConfigFields 转换 ConfigField 到 dto.ConfigField
|
|
||||||
func convertRouterConfigFields(fields []ConfigField) []dto.ConfigField {
|
|
||||||
result := make([]dto.ConfigField, len(fields))
|
|
||||||
for i, f := range fields {
|
|
||||||
result[i] = dto.ConfigField{
|
|
||||||
Key: f.Key,
|
|
||||||
Label: f.Label,
|
|
||||||
Type: f.Type,
|
|
||||||
Default: f.Default,
|
|
||||||
Required: f.Required,
|
|
||||||
Options: f.Options,
|
|
||||||
Description: f.Description,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
@@ -1,140 +0,0 @@
|
|||||||
package handler
|
|
||||||
|
|
||||||
import (
|
|
||||||
"io"
|
|
||||||
"net/http"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
"github.com/gotunnel/pkg/protocol"
|
|
||||||
)
|
|
||||||
|
|
||||||
// PluginAPIHandler 插件 API 代理处理器
|
|
||||||
type PluginAPIHandler struct {
|
|
||||||
app AppInterface
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewPluginAPIHandler 创建插件 API 代理处理器
|
|
||||||
func NewPluginAPIHandler(app AppInterface) *PluginAPIHandler {
|
|
||||||
return &PluginAPIHandler{app: app}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ProxyRequest 代理请求到客户端插件
|
|
||||||
// @Summary 代理插件 API 请求
|
|
||||||
// @Description 将请求代理到客户端的 JS 插件处理
|
|
||||||
// @Tags 插件 API
|
|
||||||
// @Accept json
|
|
||||||
// @Produce json
|
|
||||||
// @Security Bearer
|
|
||||||
// @Param id path string true "客户端 ID"
|
|
||||||
// @Param pluginID path string true "插件实例 ID"
|
|
||||||
// @Param route path string true "插件路由"
|
|
||||||
// @Success 200 {object} object
|
|
||||||
// @Failure 404 {object} Response
|
|
||||||
// @Failure 502 {object} Response
|
|
||||||
// @Router /api/client/{id}/plugin-api/{pluginID}/{route} [get]
|
|
||||||
func (h *PluginAPIHandler) ProxyRequest(c *gin.Context) {
|
|
||||||
clientID := c.Param("id")
|
|
||||||
pluginID := c.Param("pluginID")
|
|
||||||
route := c.Param("route")
|
|
||||||
|
|
||||||
// 确保路由以 / 开头
|
|
||||||
if !strings.HasPrefix(route, "/") {
|
|
||||||
route = "/" + route
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检查客户端是否在线
|
|
||||||
online, _, _ := h.app.GetServer().GetClientStatus(clientID)
|
|
||||||
if !online {
|
|
||||||
ClientNotOnline(c)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 读取请求体
|
|
||||||
var body string
|
|
||||||
if c.Request.Body != nil {
|
|
||||||
bodyBytes, _ := io.ReadAll(c.Request.Body)
|
|
||||||
body = string(bodyBytes)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 构建请求头
|
|
||||||
headers := make(map[string]string)
|
|
||||||
for key, values := range c.Request.Header {
|
|
||||||
if len(values) > 0 {
|
|
||||||
headers[key] = values[0]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 构建 API 请求
|
|
||||||
apiReq := protocol.PluginAPIRequest{
|
|
||||||
PluginID: pluginID,
|
|
||||||
Method: c.Request.Method,
|
|
||||||
Path: route,
|
|
||||||
Query: c.Request.URL.RawQuery,
|
|
||||||
Headers: headers,
|
|
||||||
Body: body,
|
|
||||||
}
|
|
||||||
|
|
||||||
// 发送请求到客户端
|
|
||||||
resp, err := h.app.GetServer().ProxyPluginAPIRequest(clientID, apiReq)
|
|
||||||
if err != nil {
|
|
||||||
BadGateway(c, "Plugin request failed: "+err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检查错误
|
|
||||||
if resp.Error != "" {
|
|
||||||
c.JSON(http.StatusBadGateway, gin.H{
|
|
||||||
"code": 502,
|
|
||||||
"message": resp.Error,
|
|
||||||
})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 设置响应头
|
|
||||||
for key, value := range resp.Headers {
|
|
||||||
c.Header(key, value)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 返回响应
|
|
||||||
c.String(resp.Status, resp.Body)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ProxyPluginAPIRequest 接口方法声明 - 添加到 ServerInterface
|
|
||||||
type PluginAPIProxyInterface interface {
|
|
||||||
ProxyPluginAPIRequest(clientID string, req protocol.PluginAPIRequest) (*protocol.PluginAPIResponse, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
// AuthConfig 认证配置
|
|
||||||
type AuthConfig struct {
|
|
||||||
Type string `json:"type"` // none, basic, token
|
|
||||||
Username string `json:"username"` // Basic Auth 用户名
|
|
||||||
Password string `json:"password"` // Basic Auth 密码
|
|
||||||
Token string `json:"token"` // Token 认证
|
|
||||||
}
|
|
||||||
|
|
||||||
// BasicAuthMiddleware 创建 Basic Auth 中间件
|
|
||||||
func BasicAuthMiddleware(username, password string) gin.HandlerFunc {
|
|
||||||
return func(c *gin.Context) {
|
|
||||||
user, pass, ok := c.Request.BasicAuth()
|
|
||||||
if !ok || user != username || pass != password {
|
|
||||||
c.Header("WWW-Authenticate", `Basic realm="Plugin"`)
|
|
||||||
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{
|
|
||||||
"code": 401,
|
|
||||||
"message": "Unauthorized",
|
|
||||||
})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
c.Next()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithTimeout 带超时的请求处理
|
|
||||||
func WithTimeout(timeout time.Duration, handler gin.HandlerFunc) gin.HandlerFunc {
|
|
||||||
return func(c *gin.Context) {
|
|
||||||
// 设置请求超时
|
|
||||||
c.Request = c.Request.WithContext(c.Request.Context())
|
|
||||||
handler(c)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,293 +0,0 @@
|
|||||||
package handler
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"net/http"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
"github.com/google/uuid"
|
|
||||||
"github.com/gotunnel/internal/server/db"
|
|
||||||
"github.com/gotunnel/internal/server/router/dto"
|
|
||||||
"github.com/gotunnel/pkg/protocol"
|
|
||||||
)
|
|
||||||
|
|
||||||
// StoreHandler 插件商店处理器
|
|
||||||
type StoreHandler struct {
|
|
||||||
app AppInterface
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewStoreHandler 创建插件商店处理器
|
|
||||||
func NewStoreHandler(app AppInterface) *StoreHandler {
|
|
||||||
return &StoreHandler{app: app}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ListPlugins 获取商店插件列表
|
|
||||||
// @Summary 获取商店插件
|
|
||||||
// @Description 从远程插件商店获取可用插件列表
|
|
||||||
// @Tags 插件商店
|
|
||||||
// @Produce json
|
|
||||||
// @Security Bearer
|
|
||||||
// @Success 200 {object} Response{data=object{plugins=[]dto.StorePluginInfo}}
|
|
||||||
// @Failure 502 {object} Response
|
|
||||||
// @Router /api/store/plugins [get]
|
|
||||||
func (h *StoreHandler) ListPlugins(c *gin.Context) {
|
|
||||||
cfg := h.app.GetConfig()
|
|
||||||
storeURL := cfg.PluginStore.GetPluginStoreURL()
|
|
||||||
|
|
||||||
// 从远程 URL 获取插件列表
|
|
||||||
client := &http.Client{Timeout: 10 * time.Second}
|
|
||||||
resp, err := client.Get(storeURL)
|
|
||||||
if err != nil {
|
|
||||||
BadGateway(c, "Failed to fetch store: "+err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
|
||||||
BadGateway(c, "Store returned error")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
body, err := io.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
InternalError(c, "Failed to read response")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 直接返回原始 JSON(已经是数组格式)
|
|
||||||
c.Header("Content-Type", "application/json")
|
|
||||||
c.Writer.Write([]byte(`{"code":0,"data":{"plugins":`))
|
|
||||||
c.Writer.Write(body)
|
|
||||||
c.Writer.Write([]byte(`}}`))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Install 从商店安装插件到客户端
|
|
||||||
// @Summary 安装商店插件
|
|
||||||
// @Description 从插件商店下载并安装插件到指定客户端
|
|
||||||
// @Tags 插件商店
|
|
||||||
// @Accept json
|
|
||||||
// @Produce json
|
|
||||||
// @Security Bearer
|
|
||||||
// @Param request body dto.StoreInstallRequest true "安装请求"
|
|
||||||
// @Success 200 {object} Response
|
|
||||||
// @Failure 400 {object} Response
|
|
||||||
// @Failure 502 {object} Response
|
|
||||||
// @Router /api/store/install [post]
|
|
||||||
func (h *StoreHandler) Install(c *gin.Context) {
|
|
||||||
var req dto.StoreInstallRequest
|
|
||||||
if !BindJSON(c, &req) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检查客户端是否在线
|
|
||||||
online, _, _ := h.app.GetServer().GetClientStatus(req.ClientID)
|
|
||||||
if !online {
|
|
||||||
ClientNotOnline(c)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 下载插件
|
|
||||||
client := &http.Client{Timeout: 30 * time.Second}
|
|
||||||
resp, err := client.Get(req.DownloadURL)
|
|
||||||
if err != nil {
|
|
||||||
BadGateway(c, "Failed to download plugin: "+err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
|
||||||
BadGateway(c, "Plugin download failed with status: "+resp.Status)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
source, err := io.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
InternalError(c, "Failed to read plugin: "+err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 下载签名文件
|
|
||||||
sigResp, err := client.Get(req.SignatureURL)
|
|
||||||
if err != nil {
|
|
||||||
BadGateway(c, "Failed to download signature: "+err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer sigResp.Body.Close()
|
|
||||||
|
|
||||||
if sigResp.StatusCode != http.StatusOK {
|
|
||||||
BadGateway(c, "Signature download failed with status: "+sigResp.Status)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
signature, err := io.ReadAll(sigResp.Body)
|
|
||||||
if err != nil {
|
|
||||||
InternalError(c, "Failed to read signature: "+err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检查插件是否已存在,决定使用已有 ID 还是生成新 ID
|
|
||||||
pluginID := ""
|
|
||||||
dbClient, err := h.app.GetClientStore().GetClient(req.ClientID)
|
|
||||||
if err == nil {
|
|
||||||
for _, p := range dbClient.Plugins {
|
|
||||||
if p.Name == req.PluginName && p.ID != "" {
|
|
||||||
pluginID = p.ID
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if pluginID == "" {
|
|
||||||
pluginID = uuid.New().String()
|
|
||||||
}
|
|
||||||
|
|
||||||
// 安装到客户端
|
|
||||||
installReq := JSPluginInstallRequest{
|
|
||||||
PluginID: pluginID,
|
|
||||||
PluginName: req.PluginName,
|
|
||||||
Source: string(source),
|
|
||||||
Signature: string(signature),
|
|
||||||
RuleName: req.PluginName,
|
|
||||||
RemotePort: req.RemotePort,
|
|
||||||
AutoStart: true,
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := h.app.GetServer().InstallJSPluginToClient(req.ClientID, installReq); err != nil {
|
|
||||||
InternalError(c, "Failed to install plugin: "+err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 将插件保存到 JSPluginStore(用于客户端重连时恢复)
|
|
||||||
jsPlugin := &db.JSPlugin{
|
|
||||||
Name: req.PluginName,
|
|
||||||
Source: string(source),
|
|
||||||
Signature: string(signature),
|
|
||||||
AutoStart: true,
|
|
||||||
Enabled: true,
|
|
||||||
}
|
|
||||||
// 尝试保存,忽略错误(可能已存在)
|
|
||||||
h.app.GetJSPluginStore().SaveJSPlugin(jsPlugin)
|
|
||||||
|
|
||||||
// 将插件信息保存到客户端记录
|
|
||||||
// 重新获取 dbClient(可能已被修改)
|
|
||||||
dbClient, err = h.app.GetClientStore().GetClient(req.ClientID)
|
|
||||||
if err == nil {
|
|
||||||
// 检查插件是否已存在(通过名称匹配)
|
|
||||||
pluginExists := false
|
|
||||||
for i, p := range dbClient.Plugins {
|
|
||||||
if p.Name == req.PluginName {
|
|
||||||
dbClient.Plugins[i].Enabled = true
|
|
||||||
dbClient.Plugins[i].RemotePort = req.RemotePort
|
|
||||||
dbClient.Plugins[i].AuthEnabled = req.AuthEnabled
|
|
||||||
dbClient.Plugins[i].AuthUsername = req.AuthUsername
|
|
||||||
dbClient.Plugins[i].AuthPassword = req.AuthPassword
|
|
||||||
// 确保有 ID
|
|
||||||
if dbClient.Plugins[i].ID == "" {
|
|
||||||
dbClient.Plugins[i].ID = pluginID
|
|
||||||
}
|
|
||||||
pluginExists = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !pluginExists {
|
|
||||||
version := req.Version
|
|
||||||
if version == "" {
|
|
||||||
version = "1.0.0"
|
|
||||||
}
|
|
||||||
// 转换 ConfigSchema
|
|
||||||
var configSchema []db.ConfigField
|
|
||||||
for _, f := range req.ConfigSchema {
|
|
||||||
configSchema = append(configSchema, db.ConfigField{
|
|
||||||
Key: f.Key,
|
|
||||||
Label: f.Label,
|
|
||||||
Type: f.Type,
|
|
||||||
Default: f.Default,
|
|
||||||
Required: f.Required,
|
|
||||||
Options: f.Options,
|
|
||||||
Description: f.Description,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
dbClient.Plugins = append(dbClient.Plugins, db.ClientPlugin{
|
|
||||||
ID: pluginID,
|
|
||||||
Name: req.PluginName,
|
|
||||||
Version: version,
|
|
||||||
Enabled: true,
|
|
||||||
RemotePort: req.RemotePort,
|
|
||||||
ConfigSchema: configSchema,
|
|
||||||
AuthEnabled: req.AuthEnabled,
|
|
||||||
AuthUsername: req.AuthUsername,
|
|
||||||
AuthPassword: req.AuthPassword,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// 自动创建代理规则(如果指定了端口)
|
|
||||||
if req.RemotePort > 0 {
|
|
||||||
// 检查端口是否可用
|
|
||||||
if !h.app.GetServer().IsPortAvailable(req.RemotePort, req.ClientID) {
|
|
||||||
InternalError(c, fmt.Sprintf("port %d is already in use", req.RemotePort))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
ruleExists := false
|
|
||||||
for i, r := range dbClient.Rules {
|
|
||||||
if r.Name == req.PluginName {
|
|
||||||
// 更新现有规则
|
|
||||||
dbClient.Rules[i].Type = req.PluginName
|
|
||||||
dbClient.Rules[i].RemotePort = req.RemotePort
|
|
||||||
dbClient.Rules[i].Enabled = boolPtr(true)
|
|
||||||
dbClient.Rules[i].PluginID = pluginID
|
|
||||||
dbClient.Rules[i].AuthEnabled = req.AuthEnabled
|
|
||||||
dbClient.Rules[i].AuthUsername = req.AuthUsername
|
|
||||||
dbClient.Rules[i].AuthPassword = req.AuthPassword
|
|
||||||
dbClient.Rules[i].PluginManaged = true
|
|
||||||
ruleExists = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !ruleExists {
|
|
||||||
// 创建新规则
|
|
||||||
dbClient.Rules = append(dbClient.Rules, protocol.ProxyRule{
|
|
||||||
Name: req.PluginName,
|
|
||||||
Type: req.PluginName,
|
|
||||||
RemotePort: req.RemotePort,
|
|
||||||
Enabled: boolPtr(true),
|
|
||||||
PluginID: pluginID,
|
|
||||||
AuthEnabled: req.AuthEnabled,
|
|
||||||
AuthUsername: req.AuthUsername,
|
|
||||||
AuthPassword: req.AuthPassword,
|
|
||||||
PluginManaged: true,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
h.app.GetClientStore().UpdateClient(dbClient)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 启动服务端监听器(让外部用户可以通过 RemotePort 访问插件)
|
|
||||||
if req.RemotePort > 0 {
|
|
||||||
pluginRule := protocol.ProxyRule{
|
|
||||||
Name: req.PluginName,
|
|
||||||
Type: req.PluginName, // 使用插件名作为类型,让 isClientPlugin 识别
|
|
||||||
RemotePort: req.RemotePort,
|
|
||||||
Enabled: boolPtr(true),
|
|
||||||
PluginID: pluginID,
|
|
||||||
AuthEnabled: req.AuthEnabled,
|
|
||||||
AuthUsername: req.AuthUsername,
|
|
||||||
AuthPassword: req.AuthPassword,
|
|
||||||
}
|
|
||||||
// 启动监听器(忽略错误,可能端口已被占用)
|
|
||||||
h.app.GetServer().StartPluginRule(req.ClientID, pluginRule)
|
|
||||||
}
|
|
||||||
|
|
||||||
Success(c, gin.H{
|
|
||||||
"status": "ok",
|
|
||||||
"plugin": req.PluginName,
|
|
||||||
"plugin_id": pluginID,
|
|
||||||
"client": req.ClientID,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// boolPtr 返回 bool 值的指针
|
|
||||||
func boolPtr(b bool) *bool {
|
|
||||||
return &b
|
|
||||||
}
|
|
||||||
76
internal/server/router/handler/traffic.go
Normal file
76
internal/server/router/handler/traffic.go
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
package handler
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TrafficHandler 流量统计处理器
|
||||||
|
type TrafficHandler struct {
|
||||||
|
app AppInterface
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewTrafficHandler 创建流量统计处理器
|
||||||
|
func NewTrafficHandler(app AppInterface) *TrafficHandler {
|
||||||
|
return &TrafficHandler{app: app}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetStats 获取流量统计
|
||||||
|
// @Summary 获取流量统计
|
||||||
|
// @Description 获取24小时和总流量统计
|
||||||
|
// @Tags 流量
|
||||||
|
// @Produce json
|
||||||
|
// @Security Bearer
|
||||||
|
// @Success 200 {object} Response
|
||||||
|
// @Router /api/traffic/stats [get]
|
||||||
|
func (h *TrafficHandler) GetStats(c *gin.Context) {
|
||||||
|
store := h.app.GetTrafficStore()
|
||||||
|
|
||||||
|
// 获取24小时流量
|
||||||
|
in24h, out24h, err := store.Get24HourTraffic()
|
||||||
|
if err != nil {
|
||||||
|
InternalError(c, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取总流量
|
||||||
|
inTotal, outTotal, err := store.GetTotalTraffic()
|
||||||
|
if err != nil {
|
||||||
|
InternalError(c, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
Success(c, gin.H{
|
||||||
|
"traffic_24h": gin.H{
|
||||||
|
"inbound": in24h,
|
||||||
|
"outbound": out24h,
|
||||||
|
},
|
||||||
|
"traffic_total": gin.H{
|
||||||
|
"inbound": inTotal,
|
||||||
|
"outbound": outTotal,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetHourly 获取每小时流量
|
||||||
|
// @Summary 获取每小时流量
|
||||||
|
// @Description 获取最近N小时的流量记录
|
||||||
|
// @Tags 流量
|
||||||
|
// @Produce json
|
||||||
|
// @Security Bearer
|
||||||
|
// @Param hours query int false "小时数" default(24)
|
||||||
|
// @Success 200 {object} Response
|
||||||
|
// @Router /api/traffic/hourly [get]
|
||||||
|
func (h *TrafficHandler) GetHourly(c *gin.Context) {
|
||||||
|
hours := 24
|
||||||
|
|
||||||
|
store := h.app.GetTrafficStore()
|
||||||
|
records, err := store.GetHourlyTraffic(hours)
|
||||||
|
if err != nil {
|
||||||
|
InternalError(c, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
Success(c, gin.H{
|
||||||
|
"records": records,
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -127,6 +127,7 @@ func getVersionInfo() dto.VersionInfo {
|
|||||||
GitCommit: info.GitCommit,
|
GitCommit: info.GitCommit,
|
||||||
BuildTime: info.BuildTime,
|
BuildTime: info.BuildTime,
|
||||||
GoVersion: info.GoVersion,
|
GoVersion: info.GoVersion,
|
||||||
Platform: info.OS + "/" + info.Arch,
|
OS: info.OS,
|
||||||
|
Arch: info.Arch,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,8 +67,9 @@ func (r *GinRouter) SetupRoutes(app handler.AppInterface, jwtAuth *auth.JWTAuth,
|
|||||||
api.POST("/client/:id/push", clientHandler.PushConfig)
|
api.POST("/client/:id/push", clientHandler.PushConfig)
|
||||||
api.POST("/client/:id/disconnect", clientHandler.Disconnect)
|
api.POST("/client/:id/disconnect", clientHandler.Disconnect)
|
||||||
api.POST("/client/:id/restart", clientHandler.Restart)
|
api.POST("/client/:id/restart", clientHandler.Restart)
|
||||||
api.POST("/client/:id/install-plugins", clientHandler.InstallPlugins)
|
api.GET("/client/:id/system-stats", clientHandler.GetSystemStats)
|
||||||
api.POST("/client/:id/plugin/:pluginID/:action", clientHandler.PluginAction)
|
api.GET("/client/:id/screenshot", clientHandler.GetScreenshot)
|
||||||
|
api.POST("/client/:id/shell", clientHandler.ExecuteShell)
|
||||||
|
|
||||||
// 配置管理
|
// 配置管理
|
||||||
configHandler := handler.NewConfigHandler(app)
|
configHandler := handler.NewConfigHandler(app)
|
||||||
@@ -76,29 +77,6 @@ func (r *GinRouter) SetupRoutes(app handler.AppInterface, jwtAuth *auth.JWTAuth,
|
|||||||
api.PUT("/config", configHandler.Update)
|
api.PUT("/config", configHandler.Update)
|
||||||
api.POST("/config/reload", configHandler.Reload)
|
api.POST("/config/reload", configHandler.Reload)
|
||||||
|
|
||||||
// 插件管理
|
|
||||||
pluginHandler := handler.NewPluginHandler(app)
|
|
||||||
api.GET("/plugins", pluginHandler.List)
|
|
||||||
api.POST("/plugin/:name/enable", pluginHandler.Enable)
|
|
||||||
api.POST("/plugin/:name/disable", pluginHandler.Disable)
|
|
||||||
api.GET("/rule-schemas", pluginHandler.GetRuleSchemas)
|
|
||||||
api.GET("/client-plugin/:clientID/:pluginName/config", pluginHandler.GetClientConfig)
|
|
||||||
api.PUT("/client-plugin/:clientID/:pluginName/config", pluginHandler.UpdateClientConfig)
|
|
||||||
|
|
||||||
// JS 插件管理
|
|
||||||
jsPluginHandler := handler.NewJSPluginHandler(app)
|
|
||||||
api.GET("/js-plugins", jsPluginHandler.List)
|
|
||||||
api.POST("/js-plugins", jsPluginHandler.Create)
|
|
||||||
api.GET("/js-plugin/:name", jsPluginHandler.Get)
|
|
||||||
api.PUT("/js-plugin/:name", jsPluginHandler.Update)
|
|
||||||
api.DELETE("/js-plugin/:name", jsPluginHandler.Delete)
|
|
||||||
api.POST("/js-plugin/:name/push/:clientID", jsPluginHandler.PushToClient)
|
|
||||||
|
|
||||||
// 插件商店
|
|
||||||
storeHandler := handler.NewStoreHandler(app)
|
|
||||||
api.GET("/store/plugins", storeHandler.ListPlugins)
|
|
||||||
api.POST("/store/install", storeHandler.Install)
|
|
||||||
|
|
||||||
// 更新管理
|
// 更新管理
|
||||||
updateHandler := handler.NewUpdateHandler(app)
|
updateHandler := handler.NewUpdateHandler(app)
|
||||||
api.GET("/update/check/server", updateHandler.CheckServer)
|
api.GET("/update/check/server", updateHandler.CheckServer)
|
||||||
@@ -110,9 +88,14 @@ func (r *GinRouter) SetupRoutes(app handler.AppInterface, jwtAuth *auth.JWTAuth,
|
|||||||
logHandler := handler.NewLogHandler(app)
|
logHandler := handler.NewLogHandler(app)
|
||||||
api.GET("/client/:id/logs", logHandler.StreamLogs)
|
api.GET("/client/:id/logs", logHandler.StreamLogs)
|
||||||
|
|
||||||
// 插件 API 代理 (通过 Web API 访问客户端插件)
|
// 流量统计
|
||||||
pluginAPIHandler := handler.NewPluginAPIHandler(app)
|
trafficHandler := handler.NewTrafficHandler(app)
|
||||||
api.Any("/client/:id/plugin-api/:pluginID/*route", pluginAPIHandler.ProxyRequest)
|
api.GET("/traffic/stats", trafficHandler.GetStats)
|
||||||
|
api.GET("/traffic/hourly", trafficHandler.GetHourly)
|
||||||
|
|
||||||
|
// 安装命令生成
|
||||||
|
installHandler := handler.NewInstallHandler(app)
|
||||||
|
api.POST("/install/generate", installHandler.GenerateInstallCommand)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,8 +177,4 @@ func isStaticAsset(path string) bool {
|
|||||||
type (
|
type (
|
||||||
ServerInterface = handler.ServerInterface
|
ServerInterface = handler.ServerInterface
|
||||||
AppInterface = handler.AppInterface
|
AppInterface = handler.AppInterface
|
||||||
ConfigField = handler.ConfigField
|
|
||||||
RuleSchema = handler.RuleSchema
|
|
||||||
PluginInfo = handler.PluginInfo
|
|
||||||
JSPluginInstallRequest = handler.JSPluginInstallRequest
|
|
||||||
)
|
)
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -142,5 +142,5 @@ func (s *Server) handleWebsocketProxyConn(cs *ClientSession, conn net.Conn, rule
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
relay.Relay(conn, stream)
|
relay.RelayWithStats(conn, stream, s.recordTraffic)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,154 +0,0 @@
|
|||||||
package audit
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"sync"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
// EventType 审计事件类型
|
|
||||||
type EventType string
|
|
||||||
|
|
||||||
const (
|
|
||||||
EventPluginInstall EventType = "plugin_install"
|
|
||||||
EventPluginUninstall EventType = "plugin_uninstall"
|
|
||||||
EventPluginStart EventType = "plugin_start"
|
|
||||||
EventPluginStop EventType = "plugin_stop"
|
|
||||||
EventPluginVerify EventType = "plugin_verify"
|
|
||||||
EventPluginReject EventType = "plugin_reject"
|
|
||||||
EventConfigChange EventType = "config_change"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Event 审计事件
|
|
||||||
type Event struct {
|
|
||||||
Timestamp time.Time `json:"timestamp"`
|
|
||||||
Type EventType `json:"type"`
|
|
||||||
PluginName string `json:"plugin_name,omitempty"`
|
|
||||||
Version string `json:"version,omitempty"`
|
|
||||||
ClientID string `json:"client_id,omitempty"`
|
|
||||||
Success bool `json:"success"`
|
|
||||||
Message string `json:"message,omitempty"`
|
|
||||||
Details map[string]string `json:"details,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Logger 审计日志记录器
|
|
||||||
type Logger struct {
|
|
||||||
path string
|
|
||||||
file *os.File
|
|
||||||
mu sync.Mutex
|
|
||||||
enabled bool
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
defaultLogger *Logger
|
|
||||||
loggerOnce sync.Once
|
|
||||||
)
|
|
||||||
|
|
||||||
// NewLogger 创建审计日志记录器
|
|
||||||
func NewLogger(dataDir string) (*Logger, error) {
|
|
||||||
path := filepath.Join(dataDir, "audit.log")
|
|
||||||
dir := filepath.Dir(path)
|
|
||||||
if err := os.MkdirAll(dir, 0755); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
file, err := os.OpenFile(path, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0600)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &Logger{path: path, file: file, enabled: true}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// InitDefault 初始化默认日志记录器
|
|
||||||
func InitDefault(dataDir string) error {
|
|
||||||
var err error
|
|
||||||
loggerOnce.Do(func() {
|
|
||||||
defaultLogger, err = NewLogger(dataDir)
|
|
||||||
})
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Log 记录审计事件
|
|
||||||
func (l *Logger) Log(event Event) {
|
|
||||||
if l == nil || !l.enabled {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
event.Timestamp = time.Now()
|
|
||||||
l.mu.Lock()
|
|
||||||
defer l.mu.Unlock()
|
|
||||||
|
|
||||||
data, err := json.Marshal(event)
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("[Audit] Marshal error: %v", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, err := l.file.Write(append(data, '\n')); err != nil {
|
|
||||||
log.Printf("[Audit] Write error: %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close 关闭日志文件
|
|
||||||
func (l *Logger) Close() error {
|
|
||||||
if l == nil || l.file == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return l.file.Close()
|
|
||||||
}
|
|
||||||
|
|
||||||
// LogEvent 使用默认记录器记录事件
|
|
||||||
func LogEvent(event Event) {
|
|
||||||
if defaultLogger != nil {
|
|
||||||
defaultLogger.Log(event)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// LogPluginInstall 记录插件安装事件
|
|
||||||
func LogPluginInstall(pluginName, version, clientID string, success bool, msg string) {
|
|
||||||
LogEvent(Event{
|
|
||||||
Type: EventPluginInstall,
|
|
||||||
PluginName: pluginName,
|
|
||||||
Version: version,
|
|
||||||
ClientID: clientID,
|
|
||||||
Success: success,
|
|
||||||
Message: msg,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// LogPluginVerify 记录插件验证事件
|
|
||||||
func LogPluginVerify(pluginName, version string, success bool, msg string) {
|
|
||||||
LogEvent(Event{
|
|
||||||
Type: EventPluginVerify,
|
|
||||||
PluginName: pluginName,
|
|
||||||
Version: version,
|
|
||||||
Success: success,
|
|
||||||
Message: msg,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// LogPluginReject 记录插件拒绝事件
|
|
||||||
func LogPluginReject(pluginName, version, reason string) {
|
|
||||||
LogEvent(Event{
|
|
||||||
Type: EventPluginReject,
|
|
||||||
PluginName: pluginName,
|
|
||||||
Version: version,
|
|
||||||
Success: false,
|
|
||||||
Message: reason,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// LogWithDetails 记录带详情的事件
|
|
||||||
func LogWithDetails(eventType EventType, pluginName string, success bool, msg string, details map[string]string) {
|
|
||||||
LogEvent(Event{
|
|
||||||
Type: eventType,
|
|
||||||
PluginName: pluginName,
|
|
||||||
Success: success,
|
|
||||||
Message: msg,
|
|
||||||
Details: details,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -1,134 +0,0 @@
|
|||||||
package plugin
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"fmt"
|
|
||||||
"sync"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Registry 管理可用的 plugins (仅客户端插件)
|
|
||||||
type Registry struct {
|
|
||||||
clientPlugins map[string]ClientPlugin // 客户端插件
|
|
||||||
enabled map[string]bool // 启用状态
|
|
||||||
mu sync.RWMutex
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewRegistry 创建 plugin 注册表
|
|
||||||
func NewRegistry() *Registry {
|
|
||||||
return &Registry{
|
|
||||||
clientPlugins: make(map[string]ClientPlugin),
|
|
||||||
enabled: make(map[string]bool),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// RegisterClient 注册客户端插件
|
|
||||||
func (r *Registry) RegisterClient(handler ClientPlugin) error {
|
|
||||||
r.mu.Lock()
|
|
||||||
defer r.mu.Unlock()
|
|
||||||
|
|
||||||
meta := handler.Metadata()
|
|
||||||
if meta.Name == "" {
|
|
||||||
return fmt.Errorf("plugin name cannot be empty")
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, exists := r.clientPlugins[meta.Name]; exists {
|
|
||||||
return fmt.Errorf("client plugin %s already registered", meta.Name)
|
|
||||||
}
|
|
||||||
|
|
||||||
r.clientPlugins[meta.Name] = handler
|
|
||||||
r.enabled[meta.Name] = true
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetClient 返回客户端插件
|
|
||||||
func (r *Registry) GetClient(name string) (ClientPlugin, error) {
|
|
||||||
r.mu.RLock()
|
|
||||||
defer r.mu.RUnlock()
|
|
||||||
|
|
||||||
if handler, ok := r.clientPlugins[name]; ok {
|
|
||||||
if !r.enabled[name] {
|
|
||||||
return nil, fmt.Errorf("client plugin %s is disabled", name)
|
|
||||||
}
|
|
||||||
return handler, nil
|
|
||||||
}
|
|
||||||
return nil, fmt.Errorf("client plugin %s not found", name)
|
|
||||||
}
|
|
||||||
|
|
||||||
// List 返回所有可用的 plugins
|
|
||||||
func (r *Registry) List() []Info {
|
|
||||||
r.mu.RLock()
|
|
||||||
defer r.mu.RUnlock()
|
|
||||||
|
|
||||||
var plugins []Info
|
|
||||||
|
|
||||||
for name, handler := range r.clientPlugins {
|
|
||||||
plugins = append(plugins, Info{
|
|
||||||
Metadata: handler.Metadata(),
|
|
||||||
Loaded: true,
|
|
||||||
Enabled: r.enabled[name],
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
return plugins
|
|
||||||
}
|
|
||||||
|
|
||||||
// Has 检查 plugin 是否存在
|
|
||||||
func (r *Registry) Has(name string) bool {
|
|
||||||
r.mu.RLock()
|
|
||||||
defer r.mu.RUnlock()
|
|
||||||
|
|
||||||
_, ok := r.clientPlugins[name]
|
|
||||||
return ok
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close 关闭所有 plugins
|
|
||||||
func (r *Registry) Close(ctx context.Context) error {
|
|
||||||
r.mu.Lock()
|
|
||||||
defer r.mu.Unlock()
|
|
||||||
|
|
||||||
var lastErr error
|
|
||||||
for name, handler := range r.clientPlugins {
|
|
||||||
if err := handler.Stop(); err != nil {
|
|
||||||
lastErr = fmt.Errorf("failed to stop client plugin %s: %w", name, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return lastErr
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enable 启用插件
|
|
||||||
func (r *Registry) Enable(name string) error {
|
|
||||||
r.mu.Lock()
|
|
||||||
defer r.mu.Unlock()
|
|
||||||
|
|
||||||
if !r.has(name) {
|
|
||||||
return fmt.Errorf("plugin %s not found", name)
|
|
||||||
}
|
|
||||||
r.enabled[name] = true
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Disable 禁用插件
|
|
||||||
func (r *Registry) Disable(name string) error {
|
|
||||||
r.mu.Lock()
|
|
||||||
defer r.mu.Unlock()
|
|
||||||
|
|
||||||
if !r.has(name) {
|
|
||||||
return fmt.Errorf("plugin %s not found", name)
|
|
||||||
}
|
|
||||||
r.enabled[name] = false
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// has 内部检查(无锁)
|
|
||||||
func (r *Registry) has(name string) bool {
|
|
||||||
_, ok := r.clientPlugins[name]
|
|
||||||
return ok
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsEnabled 检查插件是否启用
|
|
||||||
func (r *Registry) IsEnabled(name string) bool {
|
|
||||||
r.mu.RLock()
|
|
||||||
defer r.mu.RUnlock()
|
|
||||||
return r.enabled[name]
|
|
||||||
}
|
|
||||||
@@ -1,109 +0,0 @@
|
|||||||
package plugin
|
|
||||||
|
|
||||||
// 内置协议类型配置模式
|
|
||||||
|
|
||||||
// BuiltinRuleSchemas 返回所有内置协议类型的配置模式
|
|
||||||
func BuiltinRuleSchemas() map[string]RuleSchema {
|
|
||||||
return map[string]RuleSchema{
|
|
||||||
"tcp": {
|
|
||||||
NeedsLocalAddr: true,
|
|
||||||
ExtraFields: nil,
|
|
||||||
},
|
|
||||||
"udp": {
|
|
||||||
NeedsLocalAddr: true,
|
|
||||||
ExtraFields: nil,
|
|
||||||
},
|
|
||||||
"http": {
|
|
||||||
NeedsLocalAddr: false,
|
|
||||||
ExtraFields: []ConfigField{
|
|
||||||
{
|
|
||||||
Key: "auth_enabled",
|
|
||||||
Label: "启用认证",
|
|
||||||
Type: ConfigFieldBool,
|
|
||||||
Default: "false",
|
|
||||||
Description: "是否启用 HTTP Basic 认证",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Key: "username",
|
|
||||||
Label: "用户名",
|
|
||||||
Type: ConfigFieldString,
|
|
||||||
Description: "HTTP 代理认证用户名",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Key: "password",
|
|
||||||
Label: "密码",
|
|
||||||
Type: ConfigFieldPassword,
|
|
||||||
Description: "HTTP 代理认证密码",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
"https": {
|
|
||||||
NeedsLocalAddr: false,
|
|
||||||
ExtraFields: []ConfigField{
|
|
||||||
{
|
|
||||||
Key: "auth_enabled",
|
|
||||||
Label: "启用认证",
|
|
||||||
Type: ConfigFieldBool,
|
|
||||||
Default: "false",
|
|
||||||
Description: "是否启用 HTTPS 代理认证",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Key: "username",
|
|
||||||
Label: "用户名",
|
|
||||||
Type: ConfigFieldString,
|
|
||||||
Description: "HTTPS 代理认证用户名",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Key: "password",
|
|
||||||
Label: "密码",
|
|
||||||
Type: ConfigFieldPassword,
|
|
||||||
Description: "HTTPS 代理认证密码",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
"socks5": {
|
|
||||||
NeedsLocalAddr: false,
|
|
||||||
ExtraFields: []ConfigField{
|
|
||||||
{
|
|
||||||
Key: "auth_enabled",
|
|
||||||
Label: "启用认证",
|
|
||||||
Type: ConfigFieldBool,
|
|
||||||
Default: "false",
|
|
||||||
Description: "是否启用 SOCKS5 用户名/密码认证",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Key: "username",
|
|
||||||
Label: "用户名",
|
|
||||||
Type: ConfigFieldString,
|
|
||||||
Description: "SOCKS5 认证用户名",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Key: "password",
|
|
||||||
Label: "密码",
|
|
||||||
Type: ConfigFieldPassword,
|
|
||||||
Description: "SOCKS5 认证密码",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetRuleSchema 获取指定协议类型的配置模式
|
|
||||||
func GetRuleSchema(proxyType string) *RuleSchema {
|
|
||||||
schemas := BuiltinRuleSchemas()
|
|
||||||
if schema, ok := schemas[proxyType]; ok {
|
|
||||||
return &schema
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsBuiltinType 检查是否为内置协议类型
|
|
||||||
func IsBuiltinType(proxyType string) bool {
|
|
||||||
builtinTypes := []string{"tcp", "udp", "http", "https"}
|
|
||||||
for _, t := range builtinTypes {
|
|
||||||
if t == proxyType {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
@@ -1,913 +0,0 @@
|
|||||||
package script
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bufio"
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"net"
|
|
||||||
"net/http"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"sync"
|
|
||||||
|
|
||||||
"github.com/dop251/goja"
|
|
||||||
"github.com/gotunnel/pkg/plugin"
|
|
||||||
)
|
|
||||||
|
|
||||||
// JSPlugin JavaScript 脚本插件
|
|
||||||
type JSPlugin struct {
|
|
||||||
name string
|
|
||||||
source string
|
|
||||||
vm *goja.Runtime
|
|
||||||
metadata plugin.Metadata
|
|
||||||
config map[string]string
|
|
||||||
sandbox *Sandbox
|
|
||||||
running bool
|
|
||||||
mu sync.Mutex
|
|
||||||
eventListeners map[string][]func(goja.Value)
|
|
||||||
storagePath string
|
|
||||||
apiHandlers map[string]map[string]goja.Callable // method -> path -> handler
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewJSPlugin 从 JS 源码创建插件
|
|
||||||
func NewJSPlugin(name, source string) (*JSPlugin, error) {
|
|
||||||
p := &JSPlugin{
|
|
||||||
name: name,
|
|
||||||
source: source,
|
|
||||||
vm: goja.New(),
|
|
||||||
sandbox: DefaultSandbox(),
|
|
||||||
eventListeners: make(map[string][]func(goja.Value)),
|
|
||||||
storagePath: filepath.Join("plugin_data", name+".json"),
|
|
||||||
apiHandlers: make(map[string]map[string]goja.Callable),
|
|
||||||
}
|
|
||||||
|
|
||||||
// 确保存储目录存在
|
|
||||||
os.MkdirAll("plugin_data", 0755)
|
|
||||||
|
|
||||||
if err := p.init(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return p, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetSandbox 设置沙箱配置
|
|
||||||
func (p *JSPlugin) SetSandbox(sandbox *Sandbox) {
|
|
||||||
p.sandbox = sandbox
|
|
||||||
}
|
|
||||||
|
|
||||||
// init 初始化 JS 运行时
|
|
||||||
func (p *JSPlugin) init() error {
|
|
||||||
// 设置栈深度限制(防止递归攻击)
|
|
||||||
if p.sandbox.MaxStackDepth > 0 {
|
|
||||||
p.vm.SetMaxCallStackSize(p.sandbox.MaxStackDepth)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 注入基础 API
|
|
||||||
p.vm.Set("log", p.jsLog)
|
|
||||||
|
|
||||||
// Config API (兼容旧的 config() 调用,同时支持 config.get/getAll)
|
|
||||||
p.vm.Set("config", p.jsGetConfig)
|
|
||||||
if configObj := p.vm.Get("config"); configObj != nil {
|
|
||||||
obj := configObj.ToObject(p.vm)
|
|
||||||
obj.Set("get", p.jsGetConfig)
|
|
||||||
obj.Set("getAll", p.jsGetAllConfig)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 注入增强 API
|
|
||||||
p.vm.Set("logger", p.createLoggerAPI())
|
|
||||||
p.vm.Set("storage", p.createStorageAPI())
|
|
||||||
p.vm.Set("event", p.createEventAPI())
|
|
||||||
p.vm.Set("request", p.createRequestAPI())
|
|
||||||
p.vm.Set("notify", p.createNotifyAPI())
|
|
||||||
|
|
||||||
// 注入文件 API
|
|
||||||
p.vm.Set("fs", p.createFsAPI())
|
|
||||||
|
|
||||||
// 注入 HTTP API
|
|
||||||
p.vm.Set("http", p.createHttpAPI())
|
|
||||||
|
|
||||||
// 注入路由 API
|
|
||||||
p.vm.Set("api", p.createRouteAPI())
|
|
||||||
|
|
||||||
// 执行脚本
|
|
||||||
_, err := p.vm.RunString(p.source)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("run script: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取元数据
|
|
||||||
if err := p.loadMetadata(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// loadMetadata 从 JS 获取元数据
|
|
||||||
func (p *JSPlugin) loadMetadata() error {
|
|
||||||
fn, ok := goja.AssertFunction(p.vm.Get("metadata"))
|
|
||||||
if !ok {
|
|
||||||
// 使用默认元数据
|
|
||||||
p.metadata = plugin.Metadata{
|
|
||||||
Name: p.name,
|
|
||||||
Type: plugin.PluginTypeApp,
|
|
||||||
Source: plugin.PluginSourceScript,
|
|
||||||
RunAt: plugin.SideClient,
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
result, err := fn(goja.Undefined())
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
obj := result.ToObject(p.vm)
|
|
||||||
p.metadata = plugin.Metadata{
|
|
||||||
Name: getString(obj, "name", p.name),
|
|
||||||
Version: getString(obj, "version", "1.0.0"),
|
|
||||||
Type: plugin.PluginType(getString(obj, "type", "app")),
|
|
||||||
Source: plugin.PluginSourceScript,
|
|
||||||
RunAt: plugin.Side(getString(obj, "run_at", "client")),
|
|
||||||
Description: getString(obj, "description", ""),
|
|
||||||
Author: getString(obj, "author", ""),
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Metadata 返回插件元数据
|
|
||||||
func (p *JSPlugin) Metadata() plugin.Metadata {
|
|
||||||
return p.metadata
|
|
||||||
}
|
|
||||||
|
|
||||||
// Init 初始化插件配置
|
|
||||||
func (p *JSPlugin) Init(config map[string]string) error {
|
|
||||||
p.config = config
|
|
||||||
|
|
||||||
// 根据 root_path 配置设置沙箱允许的路径
|
|
||||||
if rootPath := config["root_path"]; rootPath != "" {
|
|
||||||
absPath, err := filepath.Abs(rootPath)
|
|
||||||
if err == nil {
|
|
||||||
p.sandbox.AllowedPaths = append(p.sandbox.AllowedPaths, absPath)
|
|
||||||
p.sandbox.WritablePaths = append(p.sandbox.WritablePaths, absPath)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// 如果没有配置 root_path,默认允许访问当前目录
|
|
||||||
cwd, err := os.Getwd()
|
|
||||||
if err == nil {
|
|
||||||
p.sandbox.AllowedPaths = append(p.sandbox.AllowedPaths, cwd)
|
|
||||||
p.sandbox.WritablePaths = append(p.sandbox.WritablePaths, cwd)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start 启动插件
|
|
||||||
func (p *JSPlugin) Start() (string, error) {
|
|
||||||
p.mu.Lock()
|
|
||||||
defer p.mu.Unlock()
|
|
||||||
|
|
||||||
if p.running {
|
|
||||||
return "", nil
|
|
||||||
}
|
|
||||||
|
|
||||||
fn, ok := goja.AssertFunction(p.vm.Get("start"))
|
|
||||||
if ok {
|
|
||||||
_, err := fn(goja.Undefined())
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
p.running = true
|
|
||||||
return "script-plugin", nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// HandleConn 处理连接
|
|
||||||
func (p *JSPlugin) HandleConn(conn net.Conn) error {
|
|
||||||
defer conn.Close()
|
|
||||||
|
|
||||||
// goja Runtime 不是线程安全的,需要加锁
|
|
||||||
p.mu.Lock()
|
|
||||||
defer p.mu.Unlock()
|
|
||||||
|
|
||||||
// 创建连接包装器
|
|
||||||
jsConn := newJSConn(conn)
|
|
||||||
|
|
||||||
fn, ok := goja.AssertFunction(p.vm.Get("handleConn"))
|
|
||||||
if !ok {
|
|
||||||
return fmt.Errorf("handleConn not defined")
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err := fn(goja.Undefined(), p.vm.ToValue(jsConn))
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Stop 停止插件
|
|
||||||
func (p *JSPlugin) Stop() error {
|
|
||||||
p.mu.Lock()
|
|
||||||
defer p.mu.Unlock()
|
|
||||||
|
|
||||||
if !p.running {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
fn, ok := goja.AssertFunction(p.vm.Get("stop"))
|
|
||||||
if ok {
|
|
||||||
fn(goja.Undefined())
|
|
||||||
}
|
|
||||||
|
|
||||||
p.running = false
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// jsLog JS 日志函数
|
|
||||||
func (p *JSPlugin) jsLog(msg string) {
|
|
||||||
fmt.Printf("[JS:%s] %s\n", p.name, msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
// jsGetConfig 获取配置
|
|
||||||
func (p *JSPlugin) jsGetConfig(key string) string {
|
|
||||||
if p.config == nil {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
return p.config[key]
|
|
||||||
}
|
|
||||||
|
|
||||||
// getString 从 JS 对象获取字符串
|
|
||||||
func getString(obj *goja.Object, key, def string) string {
|
|
||||||
v := obj.Get(key)
|
|
||||||
if v == nil || goja.IsUndefined(v) {
|
|
||||||
return def
|
|
||||||
}
|
|
||||||
return v.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
// jsConn JS 连接包装器
|
|
||||||
type jsConn struct {
|
|
||||||
conn net.Conn
|
|
||||||
}
|
|
||||||
|
|
||||||
func newJSConn(conn net.Conn) *jsConn {
|
|
||||||
return &jsConn{conn: conn}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *jsConn) Read(size int) []byte {
|
|
||||||
buf := make([]byte, size)
|
|
||||||
n, err := c.conn.Read(buf)
|
|
||||||
if err != nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return buf[:n]
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *jsConn) Write(data []byte) int {
|
|
||||||
n, _ := c.conn.Write(data)
|
|
||||||
return n
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *jsConn) Close() {
|
|
||||||
c.conn.Close()
|
|
||||||
}
|
|
||||||
|
|
||||||
// =============================================================================
|
|
||||||
// 文件系统 API
|
|
||||||
// =============================================================================
|
|
||||||
|
|
||||||
// createFsAPI 创建文件系统 API
|
|
||||||
func (p *JSPlugin) createFsAPI() map[string]interface{} {
|
|
||||||
return map[string]interface{}{
|
|
||||||
"readFile": p.fsReadFile,
|
|
||||||
"writeFile": p.fsWriteFile,
|
|
||||||
"readDir": p.fsReadDir,
|
|
||||||
"stat": p.fsStat,
|
|
||||||
"exists": p.fsExists,
|
|
||||||
"mkdir": p.fsMkdir,
|
|
||||||
"remove": p.fsRemove,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *JSPlugin) fsReadFile(path string) map[string]interface{} {
|
|
||||||
if err := p.sandbox.ValidateReadPath(path); err != nil {
|
|
||||||
return map[string]interface{}{"error": err.Error(), "data": ""}
|
|
||||||
}
|
|
||||||
|
|
||||||
info, err := os.Stat(path)
|
|
||||||
if err != nil {
|
|
||||||
return map[string]interface{}{"error": err.Error(), "data": ""}
|
|
||||||
}
|
|
||||||
if info.Size() > p.sandbox.MaxReadSize {
|
|
||||||
return map[string]interface{}{"error": "file too large", "data": ""}
|
|
||||||
}
|
|
||||||
|
|
||||||
data, err := os.ReadFile(path)
|
|
||||||
if err != nil {
|
|
||||||
return map[string]interface{}{"error": err.Error(), "data": ""}
|
|
||||||
}
|
|
||||||
return map[string]interface{}{"error": "", "data": string(data)}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *JSPlugin) fsWriteFile(path, content string) map[string]interface{} {
|
|
||||||
if err := p.sandbox.ValidateWritePath(path); err != nil {
|
|
||||||
return map[string]interface{}{"error": err.Error(), "ok": false}
|
|
||||||
}
|
|
||||||
|
|
||||||
if int64(len(content)) > p.sandbox.MaxWriteSize {
|
|
||||||
return map[string]interface{}{"error": "content too large", "ok": false}
|
|
||||||
}
|
|
||||||
|
|
||||||
err := os.WriteFile(path, []byte(content), 0644)
|
|
||||||
if err != nil {
|
|
||||||
return map[string]interface{}{"error": err.Error(), "ok": false}
|
|
||||||
}
|
|
||||||
return map[string]interface{}{"error": "", "ok": true}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *JSPlugin) fsReadDir(path string) map[string]interface{} {
|
|
||||||
if err := p.sandbox.ValidateReadPath(path); err != nil {
|
|
||||||
return map[string]interface{}{"error": err.Error(), "entries": nil}
|
|
||||||
}
|
|
||||||
|
|
||||||
entries, err := os.ReadDir(path)
|
|
||||||
if err != nil {
|
|
||||||
return map[string]interface{}{"error": err.Error(), "entries": nil}
|
|
||||||
}
|
|
||||||
var result []map[string]interface{}
|
|
||||||
for _, e := range entries {
|
|
||||||
info, _ := e.Info()
|
|
||||||
result = append(result, map[string]interface{}{
|
|
||||||
"name": e.Name(),
|
|
||||||
"isDir": e.IsDir(),
|
|
||||||
"size": info.Size(),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return map[string]interface{}{"error": "", "entries": result}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *JSPlugin) fsStat(path string) map[string]interface{} {
|
|
||||||
if err := p.sandbox.ValidateReadPath(path); err != nil {
|
|
||||||
return map[string]interface{}{"error": err.Error()}
|
|
||||||
}
|
|
||||||
|
|
||||||
info, err := os.Stat(path)
|
|
||||||
if err != nil {
|
|
||||||
return map[string]interface{}{"error": err.Error()}
|
|
||||||
}
|
|
||||||
return map[string]interface{}{
|
|
||||||
"error": "",
|
|
||||||
"name": info.Name(),
|
|
||||||
"size": info.Size(),
|
|
||||||
"isDir": info.IsDir(),
|
|
||||||
"modTime": info.ModTime().Unix(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *JSPlugin) fsExists(path string) map[string]interface{} {
|
|
||||||
if err := p.sandbox.ValidateReadPath(path); err != nil {
|
|
||||||
return map[string]interface{}{"error": err.Error(), "exists": false}
|
|
||||||
}
|
|
||||||
_, err := os.Stat(path)
|
|
||||||
return map[string]interface{}{"error": "", "exists": err == nil}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *JSPlugin) fsMkdir(path string) map[string]interface{} {
|
|
||||||
if err := p.sandbox.ValidateWritePath(path); err != nil {
|
|
||||||
return map[string]interface{}{"error": err.Error(), "ok": false}
|
|
||||||
}
|
|
||||||
err := os.MkdirAll(path, 0755)
|
|
||||||
if err != nil {
|
|
||||||
return map[string]interface{}{"error": err.Error(), "ok": false}
|
|
||||||
}
|
|
||||||
return map[string]interface{}{"error": "", "ok": true}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *JSPlugin) fsRemove(path string) map[string]interface{} {
|
|
||||||
if err := p.sandbox.ValidateWritePath(path); err != nil {
|
|
||||||
return map[string]interface{}{"error": err.Error(), "ok": false}
|
|
||||||
}
|
|
||||||
err := os.RemoveAll(path)
|
|
||||||
if err != nil {
|
|
||||||
return map[string]interface{}{"error": err.Error(), "ok": false}
|
|
||||||
}
|
|
||||||
return map[string]interface{}{"error": "", "ok": true}
|
|
||||||
}
|
|
||||||
|
|
||||||
// =============================================================================
|
|
||||||
// HTTP 服务 API
|
|
||||||
// =============================================================================
|
|
||||||
|
|
||||||
// createHttpAPI 创建 HTTP API
|
|
||||||
func (p *JSPlugin) createHttpAPI() map[string]interface{} {
|
|
||||||
return map[string]interface{}{
|
|
||||||
"serve": p.httpServe,
|
|
||||||
"json": p.httpJSON,
|
|
||||||
"sendFile": p.httpSendFile,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// httpServe 启动 HTTP 服务处理连接
|
|
||||||
func (p *JSPlugin) httpServe(connObj interface{}, handler goja.Callable) {
|
|
||||||
// 从 jsConn 包装器中提取原始 net.Conn
|
|
||||||
var conn net.Conn
|
|
||||||
if jc, ok := connObj.(*jsConn); ok {
|
|
||||||
conn = jc.conn
|
|
||||||
} else if nc, ok := connObj.(net.Conn); ok {
|
|
||||||
conn = nc
|
|
||||||
} else {
|
|
||||||
fmt.Printf("[JS:%s] httpServe: invalid conn type: %T\n", p.name, connObj)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 注意:不要在这里关闭连接,HandleConn 会负责关闭
|
|
||||||
|
|
||||||
// Use bufio to read the request properly
|
|
||||||
reader := bufio.NewReader(conn)
|
|
||||||
|
|
||||||
for {
|
|
||||||
// 1. Read Request Line
|
|
||||||
line, err := reader.ReadString('\n')
|
|
||||||
if err != nil {
|
|
||||||
if err != io.EOF {
|
|
||||||
fmt.Printf("[JS:%s] httpServe read error: %v\n", p.name, err)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
line = strings.TrimSpace(line)
|
|
||||||
if line == "" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
parts := strings.Split(line, " ")
|
|
||||||
if len(parts) < 2 {
|
|
||||||
fmt.Printf("[JS:%s] Invalid request line: %s\n", p.name, line)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
method := parts[0]
|
|
||||||
path := parts[1]
|
|
||||||
|
|
||||||
fmt.Printf("[JS:%s] Request: %s %s\n", p.name, method, path)
|
|
||||||
|
|
||||||
// 2. Read Headers
|
|
||||||
headers := make(map[string]string)
|
|
||||||
contentLength := 0
|
|
||||||
for {
|
|
||||||
hLine, err := reader.ReadString('\n')
|
|
||||||
if err != nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
hLine = strings.TrimSpace(hLine)
|
|
||||||
if hLine == "" {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if idx := strings.Index(hLine, ":"); idx > 0 {
|
|
||||||
key := strings.TrimSpace(hLine[:idx])
|
|
||||||
val := strings.TrimSpace(hLine[idx+1:])
|
|
||||||
headers[strings.ToLower(key)] = val
|
|
||||||
if strings.ToLower(key) == "content-length" {
|
|
||||||
contentLength, _ = strconv.Atoi(val)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. Read Body
|
|
||||||
body := ""
|
|
||||||
if contentLength > 0 {
|
|
||||||
bodyBuf := make([]byte, contentLength)
|
|
||||||
if _, err := io.ReadFull(reader, bodyBuf); err == nil {
|
|
||||||
body = string(bodyBuf)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
req := map[string]interface{}{
|
|
||||||
"method": method,
|
|
||||||
"path": path,
|
|
||||||
"headers": headers,
|
|
||||||
"body": body,
|
|
||||||
}
|
|
||||||
|
|
||||||
// 调用 JS handler 函数
|
|
||||||
result, err := handler(goja.Undefined(), p.vm.ToValue(req))
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("[JS:%s] HTTP handler error: %v\n", p.name, err)
|
|
||||||
conn.Write([]byte("HTTP/1.1 500 Internal Server Error\r\nConnection: close\r\n\r\n"))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 将结果转换为 map
|
|
||||||
if result == nil || goja.IsUndefined(result) || goja.IsNull(result) {
|
|
||||||
conn.Write([]byte("HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n"))
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := make(map[string]interface{})
|
|
||||||
respObj := result.ToObject(p.vm)
|
|
||||||
for _, key := range respObj.Keys() {
|
|
||||||
val := respObj.Get(key)
|
|
||||||
resp[key] = val.Export()
|
|
||||||
}
|
|
||||||
|
|
||||||
writeHTTPResponse(conn, resp)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *JSPlugin) httpJSON(data interface{}) string {
|
|
||||||
b, _ := json.Marshal(data)
|
|
||||||
return string(b)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *JSPlugin) httpSendFile(connObj interface{}, filePath string) {
|
|
||||||
// 从 jsConn 包装器中提取原始 net.Conn
|
|
||||||
var conn net.Conn
|
|
||||||
if jc, ok := connObj.(*jsConn); ok {
|
|
||||||
conn = jc.conn
|
|
||||||
} else if nc, ok := connObj.(net.Conn); ok {
|
|
||||||
conn = nc
|
|
||||||
} else {
|
|
||||||
fmt.Printf("[JS:%s] httpSendFile: invalid conn type: %T\n", p.name, connObj)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
f, err := os.Open(filePath)
|
|
||||||
if err != nil {
|
|
||||||
conn.Write([]byte("HTTP/1.1 404 Not Found\r\n\r\n"))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer f.Close()
|
|
||||||
|
|
||||||
info, _ := f.Stat()
|
|
||||||
contentType := getContentType(filePath)
|
|
||||||
|
|
||||||
header := fmt.Sprintf("HTTP/1.1 200 OK\r\nContent-Type: %s\r\nContent-Length: %d\r\n\r\n",
|
|
||||||
contentType, info.Size())
|
|
||||||
conn.Write([]byte(header))
|
|
||||||
io.Copy(conn, f)
|
|
||||||
}
|
|
||||||
|
|
||||||
// parseHTTPRequest is deprecated, logic moved to httpServe
|
|
||||||
func parseHTTPRequest(data []byte) map[string]interface{} {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// writeHTTPResponse 写入 HTTP 响应
|
|
||||||
func writeHTTPResponse(conn net.Conn, resp map[string]interface{}) {
|
|
||||||
status := 200
|
|
||||||
if s, ok := resp["status"].(int); ok {
|
|
||||||
status = s
|
|
||||||
}
|
|
||||||
|
|
||||||
body := ""
|
|
||||||
if b, ok := resp["body"].(string); ok {
|
|
||||||
body = b
|
|
||||||
}
|
|
||||||
|
|
||||||
contentType := "application/json"
|
|
||||||
if ct, ok := resp["contentType"].(string); ok {
|
|
||||||
contentType = ct
|
|
||||||
}
|
|
||||||
|
|
||||||
header := fmt.Sprintf("HTTP/1.1 %d OK\r\nContent-Type: %s\r\nContent-Length: %d\r\n\r\n",
|
|
||||||
status, contentType, len(body))
|
|
||||||
conn.Write([]byte(header + body))
|
|
||||||
}
|
|
||||||
|
|
||||||
func indexOf(s, substr string) int {
|
|
||||||
for i := 0; i <= len(s)-len(substr); i++ {
|
|
||||||
if s[i:i+len(substr)] == substr {
|
|
||||||
return i
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return -1
|
|
||||||
}
|
|
||||||
|
|
||||||
func getContentType(path string) string {
|
|
||||||
ext := filepath.Ext(path)
|
|
||||||
types := map[string]string{
|
|
||||||
".html": "text/html",
|
|
||||||
".css": "text/css",
|
|
||||||
".js": "application/javascript",
|
|
||||||
".json": "application/json",
|
|
||||||
".png": "image/png",
|
|
||||||
".jpg": "image/jpeg",
|
|
||||||
".gif": "image/gif",
|
|
||||||
".txt": "text/plain",
|
|
||||||
}
|
|
||||||
if ct, ok := types[ext]; ok {
|
|
||||||
return ct
|
|
||||||
}
|
|
||||||
return "application/octet-stream"
|
|
||||||
}
|
|
||||||
|
|
||||||
// =============================================================================
|
|
||||||
// Logger API
|
|
||||||
// =============================================================================
|
|
||||||
|
|
||||||
func (p *JSPlugin) createLoggerAPI() map[string]interface{} {
|
|
||||||
return map[string]interface{}{
|
|
||||||
"info": func(msg string) { fmt.Printf("[JS:%s][INFO] %s\n", p.name, msg) },
|
|
||||||
"warn": func(msg string) { fmt.Printf("[JS:%s][WARN] %s\n", p.name, msg) },
|
|
||||||
"error": func(msg string) { fmt.Printf("[JS:%s][ERROR] %s\n", p.name, msg) },
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// =============================================================================
|
|
||||||
// Config API Enhancements
|
|
||||||
// =============================================================================
|
|
||||||
|
|
||||||
func (p *JSPlugin) jsGetAllConfig() map[string]string {
|
|
||||||
if p.config == nil {
|
|
||||||
return map[string]string{}
|
|
||||||
}
|
|
||||||
return p.config
|
|
||||||
}
|
|
||||||
|
|
||||||
// =============================================================================
|
|
||||||
// Storage API
|
|
||||||
// =============================================================================
|
|
||||||
|
|
||||||
func (p *JSPlugin) createStorageAPI() map[string]interface{} {
|
|
||||||
return map[string]interface{}{
|
|
||||||
"get": p.storageGet,
|
|
||||||
"set": p.storageSet,
|
|
||||||
"delete": p.storageDelete,
|
|
||||||
"keys": p.storageKeys,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *JSPlugin) loadStorage() map[string]interface{} {
|
|
||||||
data := make(map[string]interface{})
|
|
||||||
if _, err := os.Stat(p.storagePath); err == nil {
|
|
||||||
content, _ := os.ReadFile(p.storagePath)
|
|
||||||
json.Unmarshal(content, &data)
|
|
||||||
}
|
|
||||||
return data
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *JSPlugin) saveStorage(data map[string]interface{}) {
|
|
||||||
content, _ := json.MarshalIndent(data, "", " ")
|
|
||||||
os.WriteFile(p.storagePath, content, 0644)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *JSPlugin) storageGet(key string, def interface{}) interface{} {
|
|
||||||
p.mu.Lock()
|
|
||||||
defer p.mu.Unlock()
|
|
||||||
data := p.loadStorage()
|
|
||||||
if v, ok := data[key]; ok {
|
|
||||||
return v
|
|
||||||
}
|
|
||||||
return def
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *JSPlugin) storageSet(key string, value interface{}) {
|
|
||||||
p.mu.Lock()
|
|
||||||
defer p.mu.Unlock()
|
|
||||||
data := p.loadStorage()
|
|
||||||
data[key] = value
|
|
||||||
p.saveStorage(data)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *JSPlugin) storageDelete(key string) {
|
|
||||||
p.mu.Lock()
|
|
||||||
defer p.mu.Unlock()
|
|
||||||
data := p.loadStorage()
|
|
||||||
delete(data, key)
|
|
||||||
p.saveStorage(data)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *JSPlugin) storageKeys() []string {
|
|
||||||
p.mu.Lock()
|
|
||||||
defer p.mu.Unlock()
|
|
||||||
data := p.loadStorage()
|
|
||||||
keys := make([]string, 0, len(data))
|
|
||||||
for k := range data {
|
|
||||||
keys = append(keys, k)
|
|
||||||
}
|
|
||||||
return keys
|
|
||||||
}
|
|
||||||
|
|
||||||
// =============================================================================
|
|
||||||
// Event API
|
|
||||||
// =============================================================================
|
|
||||||
|
|
||||||
func (p *JSPlugin) createEventAPI() map[string]interface{} {
|
|
||||||
return map[string]interface{}{
|
|
||||||
"on": p.eventOn,
|
|
||||||
"emit": p.eventEmit,
|
|
||||||
"off": p.eventOff,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *JSPlugin) eventOn(event string, callback func(goja.Value)) {
|
|
||||||
p.mu.Lock()
|
|
||||||
defer p.mu.Unlock()
|
|
||||||
p.eventListeners[event] = append(p.eventListeners[event], callback)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *JSPlugin) eventEmit(event string, data interface{}) {
|
|
||||||
p.mu.Lock()
|
|
||||||
listeners := p.eventListeners[event]
|
|
||||||
p.mu.Unlock() // 释放锁以允许回调中操作
|
|
||||||
|
|
||||||
val := p.vm.ToValue(data)
|
|
||||||
for _, cb := range listeners {
|
|
||||||
cb(val)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *JSPlugin) eventOff(event string) {
|
|
||||||
p.mu.Lock()
|
|
||||||
defer p.mu.Unlock()
|
|
||||||
delete(p.eventListeners, event)
|
|
||||||
}
|
|
||||||
|
|
||||||
// =============================================================================
|
|
||||||
// Request API (HTTP Client)
|
|
||||||
// =============================================================================
|
|
||||||
|
|
||||||
func (p *JSPlugin) createRequestAPI() map[string]interface{} {
|
|
||||||
return map[string]interface{}{
|
|
||||||
"get": p.requestGet,
|
|
||||||
"post": p.requestPost,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *JSPlugin) requestGet(url string) map[string]interface{} {
|
|
||||||
resp, err := http.Get(url)
|
|
||||||
if err != nil {
|
|
||||||
return map[string]interface{}{"error": err.Error(), "status": 0}
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
body, _ := io.ReadAll(resp.Body)
|
|
||||||
return map[string]interface{}{
|
|
||||||
"status": resp.StatusCode,
|
|
||||||
"body": string(body),
|
|
||||||
"error": "",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *JSPlugin) requestPost(url string, contentType, data string) map[string]interface{} {
|
|
||||||
resp, err := http.Post(url, contentType, strings.NewReader(data))
|
|
||||||
if err != nil {
|
|
||||||
return map[string]interface{}{"error": err.Error(), "status": 0}
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
body, _ := io.ReadAll(resp.Body)
|
|
||||||
return map[string]interface{}{
|
|
||||||
"status": resp.StatusCode,
|
|
||||||
"body": string(body),
|
|
||||||
"error": "",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// =============================================================================
|
|
||||||
// Notify API
|
|
||||||
// =============================================================================
|
|
||||||
|
|
||||||
func (p *JSPlugin) createNotifyAPI() map[string]interface{} {
|
|
||||||
return map[string]interface{}{
|
|
||||||
"send": func(title, msg string) {
|
|
||||||
// 目前仅打印到日志,后续对接系统通知
|
|
||||||
fmt.Printf("[NOTIFY][%s] %s: %s\n", p.name, title, msg)
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// =============================================================================
|
|
||||||
// Route API (用于 Web API 代理)
|
|
||||||
// =============================================================================
|
|
||||||
|
|
||||||
func (p *JSPlugin) createRouteAPI() map[string]interface{} {
|
|
||||||
return map[string]interface{}{
|
|
||||||
"handle": p.apiHandle,
|
|
||||||
"get": func(path string, handler goja.Callable) { p.apiRegister("GET", path, handler) },
|
|
||||||
"post": func(path string, handler goja.Callable) { p.apiRegister("POST", path, handler) },
|
|
||||||
"put": func(path string, handler goja.Callable) { p.apiRegister("PUT", path, handler) },
|
|
||||||
"delete": func(path string, handler goja.Callable) { p.apiRegister("DELETE", path, handler) },
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// apiHandle 注册 API 路由处理函数
|
|
||||||
func (p *JSPlugin) apiHandle(method, path string, handler goja.Callable) {
|
|
||||||
p.apiRegister(method, path, handler)
|
|
||||||
}
|
|
||||||
|
|
||||||
// apiRegister 注册 API 路由
|
|
||||||
func (p *JSPlugin) apiRegister(method, path string, handler goja.Callable) {
|
|
||||||
p.mu.Lock()
|
|
||||||
defer p.mu.Unlock()
|
|
||||||
|
|
||||||
if p.apiHandlers[method] == nil {
|
|
||||||
p.apiHandlers[method] = make(map[string]goja.Callable)
|
|
||||||
}
|
|
||||||
p.apiHandlers[method][path] = handler
|
|
||||||
fmt.Printf("[JS:%s] Registered API: %s %s\n", p.name, method, path)
|
|
||||||
}
|
|
||||||
|
|
||||||
// HandleAPIRequest 处理 API 请求
|
|
||||||
func (p *JSPlugin) HandleAPIRequest(method, path, query string, headers map[string]string, body string) (int, map[string]string, string, error) {
|
|
||||||
p.mu.Lock()
|
|
||||||
handlers := p.apiHandlers[method]
|
|
||||||
p.mu.Unlock()
|
|
||||||
|
|
||||||
if handlers == nil {
|
|
||||||
return 404, nil, `{"error":"method not allowed"}`, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// 查找匹配的路由
|
|
||||||
var handler goja.Callable
|
|
||||||
var matchedPath string
|
|
||||||
|
|
||||||
for registeredPath, h := range handlers {
|
|
||||||
if matchRoute(registeredPath, path) {
|
|
||||||
handler = h
|
|
||||||
matchedPath = registeredPath
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if handler == nil {
|
|
||||||
return 404, nil, `{"error":"route not found"}`, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// 构建请求对象
|
|
||||||
reqObj := map[string]interface{}{
|
|
||||||
"method": method,
|
|
||||||
"path": path,
|
|
||||||
"pattern": matchedPath,
|
|
||||||
"query": query,
|
|
||||||
"headers": headers,
|
|
||||||
"body": body,
|
|
||||||
"params": extractParams(matchedPath, path),
|
|
||||||
}
|
|
||||||
|
|
||||||
// 调用处理函数
|
|
||||||
result, err := handler(goja.Undefined(), p.vm.ToValue(reqObj))
|
|
||||||
if err != nil {
|
|
||||||
return 500, nil, fmt.Sprintf(`{"error":"%s"}`, err.Error()), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// 解析响应
|
|
||||||
if result == nil || goja.IsUndefined(result) || goja.IsNull(result) {
|
|
||||||
return 200, nil, "", nil
|
|
||||||
}
|
|
||||||
|
|
||||||
respObj := result.ToObject(p.vm)
|
|
||||||
status := 200
|
|
||||||
if s := respObj.Get("status"); s != nil && !goja.IsUndefined(s) {
|
|
||||||
status = int(s.ToInteger())
|
|
||||||
}
|
|
||||||
|
|
||||||
respHeaders := make(map[string]string)
|
|
||||||
if h := respObj.Get("headers"); h != nil && !goja.IsUndefined(h) {
|
|
||||||
hObj := h.ToObject(p.vm)
|
|
||||||
for _, key := range hObj.Keys() {
|
|
||||||
respHeaders[key] = hObj.Get(key).String()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
respBody := ""
|
|
||||||
if b := respObj.Get("body"); b != nil && !goja.IsUndefined(b) {
|
|
||||||
respBody = b.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
return status, respHeaders, respBody, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// matchRoute 匹配路由 (支持简单的路径参数)
|
|
||||||
func matchRoute(pattern, path string) bool {
|
|
||||||
patternParts := strings.Split(strings.Trim(pattern, "/"), "/")
|
|
||||||
pathParts := strings.Split(strings.Trim(path, "/"), "/")
|
|
||||||
|
|
||||||
if len(patternParts) != len(pathParts) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
for i, part := range patternParts {
|
|
||||||
if strings.HasPrefix(part, ":") {
|
|
||||||
continue // 路径参数,匹配任意值
|
|
||||||
}
|
|
||||||
if part != pathParts[i] {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
// extractParams 提取路径参数
|
|
||||||
func extractParams(pattern, path string) map[string]string {
|
|
||||||
params := make(map[string]string)
|
|
||||||
patternParts := strings.Split(strings.Trim(pattern, "/"), "/")
|
|
||||||
pathParts := strings.Split(strings.Trim(path, "/"), "/")
|
|
||||||
|
|
||||||
for i, part := range patternParts {
|
|
||||||
if strings.HasPrefix(part, ":") && i < len(pathParts) {
|
|
||||||
paramName := strings.TrimPrefix(part, ":")
|
|
||||||
params[paramName] = pathParts[i]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return params
|
|
||||||
}
|
|
||||||
@@ -1,161 +0,0 @@
|
|||||||
package script
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Sandbox 插件沙箱配置
|
|
||||||
type Sandbox struct {
|
|
||||||
// 允许访问的路径列表(绝对路径)
|
|
||||||
AllowedPaths []string
|
|
||||||
// 允许写入的路径列表(必须是 AllowedPaths 的子集)
|
|
||||||
WritablePaths []string
|
|
||||||
// 禁止访问的路径(黑名单,优先级高于白名单)
|
|
||||||
DeniedPaths []string
|
|
||||||
// 是否允许网络访问
|
|
||||||
AllowNetwork bool
|
|
||||||
// 最大文件读取大小 (bytes)
|
|
||||||
MaxReadSize int64
|
|
||||||
// 最大文件写入大小 (bytes)
|
|
||||||
MaxWriteSize int64
|
|
||||||
// 最大内存使用量 (bytes),0 表示不限制
|
|
||||||
MaxMemory int64
|
|
||||||
// 最大调用栈深度
|
|
||||||
MaxStackDepth int
|
|
||||||
}
|
|
||||||
|
|
||||||
// DefaultSandbox 返回默认沙箱配置(最小权限)
|
|
||||||
func DefaultSandbox() *Sandbox {
|
|
||||||
return &Sandbox{
|
|
||||||
AllowedPaths: []string{},
|
|
||||||
WritablePaths: []string{},
|
|
||||||
DeniedPaths: defaultDeniedPaths(),
|
|
||||||
AllowNetwork: false,
|
|
||||||
MaxReadSize: 10 * 1024 * 1024, // 10MB
|
|
||||||
MaxWriteSize: 1 * 1024 * 1024, // 1MB
|
|
||||||
MaxMemory: 64 * 1024 * 1024, // 64MB
|
|
||||||
MaxStackDepth: 1000, // 最大调用栈深度
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// defaultDeniedPaths 返回默认禁止访问的路径
|
|
||||||
func defaultDeniedPaths() []string {
|
|
||||||
home, _ := os.UserHomeDir()
|
|
||||||
denied := []string{
|
|
||||||
"/etc/passwd",
|
|
||||||
"/etc/shadow",
|
|
||||||
"/etc/sudoers",
|
|
||||||
"/root",
|
|
||||||
"/.ssh",
|
|
||||||
"/.gnupg",
|
|
||||||
"/.aws",
|
|
||||||
"/.kube",
|
|
||||||
"/proc",
|
|
||||||
"/sys",
|
|
||||||
}
|
|
||||||
if home != "" {
|
|
||||||
denied = append(denied,
|
|
||||||
filepath.Join(home, ".ssh"),
|
|
||||||
filepath.Join(home, ".gnupg"),
|
|
||||||
filepath.Join(home, ".aws"),
|
|
||||||
filepath.Join(home, ".kube"),
|
|
||||||
filepath.Join(home, ".config"),
|
|
||||||
filepath.Join(home, ".local"),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
return denied
|
|
||||||
}
|
|
||||||
|
|
||||||
// ValidateReadPath 验证读取路径是否允许
|
|
||||||
func (s *Sandbox) ValidateReadPath(path string) error {
|
|
||||||
return s.validatePath(path, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ValidateWritePath 验证写入路径是否允许
|
|
||||||
func (s *Sandbox) ValidateWritePath(path string) error {
|
|
||||||
return s.validatePath(path, true)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Sandbox) validatePath(path string, write bool) error {
|
|
||||||
// 清理路径,防止路径遍历攻击
|
|
||||||
cleanPath, err := s.cleanPath(path)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检查黑名单(优先级最高)
|
|
||||||
if s.isDenied(cleanPath) {
|
|
||||||
return fmt.Errorf("access denied: path is in denied list")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检查白名单
|
|
||||||
allowedList := s.AllowedPaths
|
|
||||||
if write {
|
|
||||||
allowedList = s.WritablePaths
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(allowedList) == 0 {
|
|
||||||
return fmt.Errorf("access denied: no paths allowed")
|
|
||||||
}
|
|
||||||
|
|
||||||
if !s.isAllowed(cleanPath, allowedList) {
|
|
||||||
if write {
|
|
||||||
return fmt.Errorf("access denied: path not in writable list")
|
|
||||||
}
|
|
||||||
return fmt.Errorf("access denied: path not in allowed list")
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// cleanPath 清理并验证路径
|
|
||||||
func (s *Sandbox) cleanPath(path string) (string, error) {
|
|
||||||
// 转换为绝对路径
|
|
||||||
absPath, err := filepath.Abs(path)
|
|
||||||
if err != nil {
|
|
||||||
return "", fmt.Errorf("invalid path: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 清理路径(解析 .. 和 .)
|
|
||||||
cleanPath := filepath.Clean(absPath)
|
|
||||||
|
|
||||||
// 检查符号链接(防止通过符号链接绕过限制)
|
|
||||||
realPath, err := filepath.EvalSymlinks(cleanPath)
|
|
||||||
if err != nil {
|
|
||||||
// 文件可能不存在,使用清理后的路径
|
|
||||||
if !os.IsNotExist(err) {
|
|
||||||
return "", fmt.Errorf("invalid path: %w", err)
|
|
||||||
}
|
|
||||||
realPath = cleanPath
|
|
||||||
}
|
|
||||||
|
|
||||||
// 再次检查路径遍历
|
|
||||||
if strings.Contains(realPath, "..") {
|
|
||||||
return "", fmt.Errorf("path traversal detected")
|
|
||||||
}
|
|
||||||
|
|
||||||
return realPath, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// isDenied 检查路径是否在黑名单中
|
|
||||||
func (s *Sandbox) isDenied(path string) bool {
|
|
||||||
for _, denied := range s.DeniedPaths {
|
|
||||||
if strings.HasPrefix(path, denied) || path == denied {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// isAllowed 检查路径是否在白名单中
|
|
||||||
func (s *Sandbox) isAllowed(path string, allowedList []string) bool {
|
|
||||||
for _, allowed := range allowedList {
|
|
||||||
if strings.HasPrefix(path, allowed) || path == allowed {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
package sign
|
|
||||||
|
|
||||||
import (
|
|
||||||
"crypto/ed25519"
|
|
||||||
"sync"
|
|
||||||
)
|
|
||||||
|
|
||||||
// 官方固定公钥(客户端内置)
|
|
||||||
const OfficialPublicKeyBase64 = "0A0xRthj0wgPg8X8GJZ6/EnNpAUw5v7O//XLty+P5Yw="
|
|
||||||
|
|
||||||
var (
|
|
||||||
officialPubKey ed25519.PublicKey
|
|
||||||
officialPubKeyOnce sync.Once
|
|
||||||
officialPubKeyErr error
|
|
||||||
)
|
|
||||||
|
|
||||||
// initOfficialKey 初始化官方公钥
|
|
||||||
func initOfficialKey() {
|
|
||||||
officialPubKey, officialPubKeyErr = DecodePublicKey(OfficialPublicKeyBase64)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetOfficialPublicKey 获取官方公钥
|
|
||||||
func GetOfficialPublicKey() (ed25519.PublicKey, error) {
|
|
||||||
officialPubKeyOnce.Do(initOfficialKey)
|
|
||||||
return officialPubKey, officialPubKeyErr
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetPublicKeyByID 根据 ID 获取公钥(兼容旧接口,忽略 keyID)
|
|
||||||
func GetPublicKeyByID(keyID string) (ed25519.PublicKey, error) {
|
|
||||||
return GetOfficialPublicKey()
|
|
||||||
}
|
|
||||||
@@ -1,107 +0,0 @@
|
|||||||
package sign
|
|
||||||
|
|
||||||
import (
|
|
||||||
"crypto/ed25519"
|
|
||||||
"crypto/sha256"
|
|
||||||
"encoding/hex"
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
// PluginPayload 插件签名载荷
|
|
||||||
type PluginPayload struct {
|
|
||||||
Name string `json:"name"` // 插件名称
|
|
||||||
Version string `json:"version"` // 版本号
|
|
||||||
SourceHash string `json:"source_hash"` // 源码 SHA256
|
|
||||||
KeyID string `json:"key_id"` // 签名密钥 ID
|
|
||||||
Timestamp int64 `json:"timestamp"` // 签名时间戳
|
|
||||||
}
|
|
||||||
|
|
||||||
// SignedPlugin 已签名的插件
|
|
||||||
type SignedPlugin struct {
|
|
||||||
Payload PluginPayload `json:"payload"`
|
|
||||||
Signature string `json:"signature"` // Base64 签名
|
|
||||||
}
|
|
||||||
|
|
||||||
// NormalizeSource 规范化源码(统一换行符)
|
|
||||||
func NormalizeSource(source string) string {
|
|
||||||
// 统一换行符为 LF
|
|
||||||
normalized := strings.ReplaceAll(source, "\r\n", "\n")
|
|
||||||
normalized = strings.ReplaceAll(normalized, "\r", "\n")
|
|
||||||
// 去除尾部空白
|
|
||||||
normalized = strings.TrimRight(normalized, " \t\n")
|
|
||||||
return normalized
|
|
||||||
}
|
|
||||||
|
|
||||||
// HashSource 计算源码哈希
|
|
||||||
func HashSource(source string) string {
|
|
||||||
normalized := NormalizeSource(source)
|
|
||||||
hash := sha256.Sum256([]byte(normalized))
|
|
||||||
return hex.EncodeToString(hash[:])
|
|
||||||
}
|
|
||||||
|
|
||||||
// CreatePayload 创建签名载荷
|
|
||||||
func CreatePayload(name, version, source, keyID string) *PluginPayload {
|
|
||||||
return &PluginPayload{
|
|
||||||
Name: name,
|
|
||||||
Version: version,
|
|
||||||
SourceHash: HashSource(source),
|
|
||||||
KeyID: keyID,
|
|
||||||
Timestamp: time.Now().Unix(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// SignPlugin 签名插件
|
|
||||||
func SignPlugin(priv ed25519.PrivateKey, payload *PluginPayload) (*SignedPlugin, error) {
|
|
||||||
// 序列化载荷
|
|
||||||
data, err := json.Marshal(payload)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("marshal payload: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 签名
|
|
||||||
sig := SignBase64(priv, data)
|
|
||||||
|
|
||||||
return &SignedPlugin{
|
|
||||||
Payload: *payload,
|
|
||||||
Signature: sig,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// VerifyPlugin 验证插件签名
|
|
||||||
func VerifyPlugin(pub ed25519.PublicKey, signed *SignedPlugin, source string) error {
|
|
||||||
// 验证源码哈希
|
|
||||||
expectedHash := HashSource(source)
|
|
||||||
if signed.Payload.SourceHash != expectedHash {
|
|
||||||
return fmt.Errorf("source hash mismatch")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 序列化载荷
|
|
||||||
data, err := json.Marshal(signed.Payload)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("marshal payload: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 验证签名
|
|
||||||
return VerifyBase64(pub, data, signed.Signature)
|
|
||||||
}
|
|
||||||
|
|
||||||
// EncodeSignedPlugin 编码已签名插件为 JSON
|
|
||||||
func EncodeSignedPlugin(sp *SignedPlugin) (string, error) {
|
|
||||||
data, err := json.Marshal(sp)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
return string(data), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// DecodeSignedPlugin 从 JSON 解码已签名插件
|
|
||||||
func DecodeSignedPlugin(data string) (*SignedPlugin, error) {
|
|
||||||
var sp SignedPlugin
|
|
||||||
if err := json.Unmarshal([]byte(data), &sp); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &sp, nil
|
|
||||||
}
|
|
||||||
@@ -1,92 +0,0 @@
|
|||||||
package sign
|
|
||||||
|
|
||||||
import (
|
|
||||||
"crypto/ed25519"
|
|
||||||
"crypto/rand"
|
|
||||||
"encoding/base64"
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
ErrInvalidSignature = errors.New("invalid signature")
|
|
||||||
ErrInvalidPublicKey = errors.New("invalid public key")
|
|
||||||
ErrInvalidPrivateKey = errors.New("invalid private key")
|
|
||||||
)
|
|
||||||
|
|
||||||
// KeyPair Ed25519 密钥对
|
|
||||||
type KeyPair struct {
|
|
||||||
PublicKey ed25519.PublicKey
|
|
||||||
PrivateKey ed25519.PrivateKey
|
|
||||||
}
|
|
||||||
|
|
||||||
// GenerateKeyPair 生成新的密钥对
|
|
||||||
func GenerateKeyPair() (*KeyPair, error) {
|
|
||||||
pub, priv, err := ed25519.GenerateKey(rand.Reader)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("generate key: %w", err)
|
|
||||||
}
|
|
||||||
return &KeyPair{PublicKey: pub, PrivateKey: priv}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sign 使用私钥签名数据
|
|
||||||
func Sign(privateKey ed25519.PrivateKey, data []byte) []byte {
|
|
||||||
return ed25519.Sign(privateKey, data)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Verify 使用公钥验证签名
|
|
||||||
func Verify(publicKey ed25519.PublicKey, data, signature []byte) bool {
|
|
||||||
return ed25519.Verify(publicKey, data, signature)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SignBase64 签名并返回 Base64 编码
|
|
||||||
func SignBase64(privateKey ed25519.PrivateKey, data []byte) string {
|
|
||||||
sig := Sign(privateKey, data)
|
|
||||||
return base64.StdEncoding.EncodeToString(sig)
|
|
||||||
}
|
|
||||||
|
|
||||||
// VerifyBase64 验证 Base64 编码的签名
|
|
||||||
func VerifyBase64(publicKey ed25519.PublicKey, data []byte, sigB64 string) error {
|
|
||||||
sig, err := base64.StdEncoding.DecodeString(sigB64)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("decode signature: %w", err)
|
|
||||||
}
|
|
||||||
if !Verify(publicKey, data, sig) {
|
|
||||||
return ErrInvalidSignature
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// EncodePublicKey 编码公钥为 Base64
|
|
||||||
func EncodePublicKey(pub ed25519.PublicKey) string {
|
|
||||||
return base64.StdEncoding.EncodeToString(pub)
|
|
||||||
}
|
|
||||||
|
|
||||||
// DecodePublicKey 从 Base64 解码公钥
|
|
||||||
func DecodePublicKey(s string) (ed25519.PublicKey, error) {
|
|
||||||
data, err := base64.StdEncoding.DecodeString(s)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if len(data) != ed25519.PublicKeySize {
|
|
||||||
return nil, ErrInvalidPublicKey
|
|
||||||
}
|
|
||||||
return ed25519.PublicKey(data), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// EncodePrivateKey 编码私钥为 Base64
|
|
||||||
func EncodePrivateKey(priv ed25519.PrivateKey) string {
|
|
||||||
return base64.StdEncoding.EncodeToString(priv)
|
|
||||||
}
|
|
||||||
|
|
||||||
// DecodePrivateKey 从 Base64 解码私钥
|
|
||||||
func DecodePrivateKey(s string) (ed25519.PrivateKey, error) {
|
|
||||||
data, err := base64.StdEncoding.DecodeString(s)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if len(data) != ed25519.PrivateKeySize {
|
|
||||||
return nil, ErrInvalidPrivateKey
|
|
||||||
}
|
|
||||||
return ed25519.PrivateKey(data), nil
|
|
||||||
}
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
package sign
|
|
||||||
|
|
||||||
import (
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
// CompareVersions 比较两个版本号
|
|
||||||
// 返回: -1 (v1 < v2), 0 (v1 == v2), 1 (v1 > v2)
|
|
||||||
func CompareVersions(v1, v2 string) int {
|
|
||||||
parts1 := parseVersion(v1)
|
|
||||||
parts2 := parseVersion(v2)
|
|
||||||
|
|
||||||
maxLen := len(parts1)
|
|
||||||
if len(parts2) > maxLen {
|
|
||||||
maxLen = len(parts2)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < maxLen; i++ {
|
|
||||||
var p1, p2 int
|
|
||||||
if i < len(parts1) {
|
|
||||||
p1 = parts1[i]
|
|
||||||
}
|
|
||||||
if i < len(parts2) {
|
|
||||||
p2 = parts2[i]
|
|
||||||
}
|
|
||||||
|
|
||||||
if p1 < p2 {
|
|
||||||
return -1
|
|
||||||
}
|
|
||||||
if p1 > p2 {
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func parseVersion(v string) []int {
|
|
||||||
v = strings.TrimPrefix(v, "v")
|
|
||||||
parts := strings.Split(v, ".")
|
|
||||||
result := make([]int, len(parts))
|
|
||||||
for i, p := range parts {
|
|
||||||
n, _ := strconv.Atoi(p)
|
|
||||||
result[i] = n
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
@@ -1,110 +0,0 @@
|
|||||||
package plugin
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
// =============================================================================
|
|
||||||
// 基础类型
|
|
||||||
// =============================================================================
|
|
||||||
|
|
||||||
// Side 运行侧
|
|
||||||
type Side string
|
|
||||||
|
|
||||||
const (
|
|
||||||
SideClient Side = "client"
|
|
||||||
)
|
|
||||||
|
|
||||||
// PluginType 插件类别
|
|
||||||
type PluginType string
|
|
||||||
|
|
||||||
const (
|
|
||||||
PluginTypeProxy PluginType = "proxy" // 代理协议 (SOCKS5 等)
|
|
||||||
PluginTypeApp PluginType = "app" // 应用服务 (VNC, Echo 等)
|
|
||||||
)
|
|
||||||
|
|
||||||
// PluginSource 插件来源
|
|
||||||
type PluginSource string
|
|
||||||
|
|
||||||
const (
|
|
||||||
PluginSourceBuiltin PluginSource = "builtin" // 内置编译
|
|
||||||
PluginSourceScript PluginSource = "script" // 脚本插件
|
|
||||||
)
|
|
||||||
|
|
||||||
// =============================================================================
|
|
||||||
// 配置相关
|
|
||||||
// =============================================================================
|
|
||||||
|
|
||||||
// ConfigFieldType 配置字段类型
|
|
||||||
type ConfigFieldType string
|
|
||||||
|
|
||||||
const (
|
|
||||||
ConfigFieldString ConfigFieldType = "string"
|
|
||||||
ConfigFieldNumber ConfigFieldType = "number"
|
|
||||||
ConfigFieldBool ConfigFieldType = "bool"
|
|
||||||
ConfigFieldSelect ConfigFieldType = "select"
|
|
||||||
ConfigFieldPassword ConfigFieldType = "password"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ConfigField 配置字段定义
|
|
||||||
type ConfigField struct {
|
|
||||||
Key string `json:"key"`
|
|
||||||
Label string `json:"label"`
|
|
||||||
Type ConfigFieldType `json:"type"`
|
|
||||||
Default string `json:"default,omitempty"`
|
|
||||||
Required bool `json:"required,omitempty"`
|
|
||||||
Options []string `json:"options,omitempty"`
|
|
||||||
Description string `json:"description,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// RuleSchema 规则表单模式
|
|
||||||
type RuleSchema struct {
|
|
||||||
NeedsLocalAddr bool `json:"needs_local_addr"`
|
|
||||||
ExtraFields []ConfigField `json:"extra_fields,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// =============================================================================
|
|
||||||
// 元数据
|
|
||||||
// =============================================================================
|
|
||||||
|
|
||||||
// Metadata 插件元数据
|
|
||||||
type Metadata struct {
|
|
||||||
Name string `json:"name"`
|
|
||||||
Version string `json:"version"`
|
|
||||||
Type PluginType `json:"type"`
|
|
||||||
Source PluginSource `json:"source"`
|
|
||||||
RunAt Side `json:"run_at"`
|
|
||||||
Description string `json:"description"`
|
|
||||||
Author string `json:"author,omitempty"`
|
|
||||||
ConfigSchema []ConfigField `json:"config_schema,omitempty"`
|
|
||||||
RuleSchema *RuleSchema `json:"rule_schema,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Info 插件运行时信息
|
|
||||||
type Info struct {
|
|
||||||
Metadata Metadata `json:"metadata"`
|
|
||||||
Loaded bool `json:"loaded"`
|
|
||||||
Enabled bool `json:"enabled"`
|
|
||||||
LoadedAt time.Time `json:"loaded_at,omitempty"`
|
|
||||||
Error string `json:"error,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// =============================================================================
|
|
||||||
// 核心接口
|
|
||||||
// =============================================================================
|
|
||||||
|
|
||||||
// Dialer 网络拨号接口
|
|
||||||
type Dialer interface {
|
|
||||||
Dial(network, address string) (net.Conn, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ClientPlugin 客户端插件接口
|
|
||||||
// 运行在客户端,提供本地服务
|
|
||||||
type ClientPlugin interface {
|
|
||||||
Metadata() Metadata
|
|
||||||
Init(config map[string]string) error
|
|
||||||
Start() (localAddr string, err error)
|
|
||||||
HandleConn(conn net.Conn) error
|
|
||||||
Stop() error
|
|
||||||
}
|
|
||||||
@@ -26,34 +26,11 @@ const (
|
|||||||
MsgTypeProxyConnect uint8 = 9 // 代理连接请求 (SOCKS5/HTTP)
|
MsgTypeProxyConnect uint8 = 9 // 代理连接请求 (SOCKS5/HTTP)
|
||||||
MsgTypeProxyResult uint8 = 10 // 代理连接结果
|
MsgTypeProxyResult uint8 = 10 // 代理连接结果
|
||||||
|
|
||||||
// Plugin 相关消息
|
|
||||||
MsgTypePluginList uint8 = 20 // 请求/响应可用 plugins
|
|
||||||
MsgTypePluginDownload uint8 = 21 // 请求下载 plugin
|
|
||||||
MsgTypePluginData uint8 = 22 // Plugin 二进制数据(分块)
|
|
||||||
MsgTypePluginReady uint8 = 23 // Plugin 加载确认
|
|
||||||
|
|
||||||
// UDP 相关消息
|
// UDP 相关消息
|
||||||
MsgTypeUDPData uint8 = 30 // UDP 数据包
|
MsgTypeUDPData uint8 = 30 // UDP 数据包
|
||||||
|
|
||||||
// 插件安装消息
|
|
||||||
MsgTypeInstallPlugins uint8 = 24 // 服务端推送安装插件列表
|
|
||||||
MsgTypePluginConfig uint8 = 25 // 插件配置同步
|
|
||||||
|
|
||||||
// 客户端插件消息
|
|
||||||
MsgTypeClientPluginStart uint8 = 40 // 启动客户端插件
|
|
||||||
MsgTypeClientPluginStop uint8 = 41 // 停止客户端插件
|
|
||||||
MsgTypeClientPluginStatus uint8 = 42 // 客户端插件状态
|
|
||||||
MsgTypeClientPluginConn uint8 = 43 // 客户端插件连接请求
|
|
||||||
MsgTypePluginStatusQuery uint8 = 44 // 查询所有插件状态
|
|
||||||
MsgTypePluginStatusQueryResp uint8 = 45 // 插件状态查询响应
|
|
||||||
|
|
||||||
// JS 插件动态安装
|
|
||||||
MsgTypeJSPluginInstall uint8 = 50 // 安装 JS 插件
|
|
||||||
MsgTypeJSPluginResult uint8 = 51 // 安装结果
|
|
||||||
|
|
||||||
// 客户端控制消息
|
// 客户端控制消息
|
||||||
MsgTypeClientRestart uint8 = 60 // 重启客户端
|
MsgTypeClientRestart uint8 = 60 // 重启客户端
|
||||||
MsgTypePluginConfigUpdate uint8 = 61 // 更新插件配置
|
|
||||||
|
|
||||||
// 更新相关消息
|
// 更新相关消息
|
||||||
MsgTypeUpdateCheck uint8 = 70 // 检查更新请求
|
MsgTypeUpdateCheck uint8 = 70 // 检查更新请求
|
||||||
@@ -68,9 +45,17 @@ const (
|
|||||||
MsgTypeLogData uint8 = 81 // 日志数据
|
MsgTypeLogData uint8 = 81 // 日志数据
|
||||||
MsgTypeLogStop uint8 = 82 // 停止日志流
|
MsgTypeLogStop uint8 = 82 // 停止日志流
|
||||||
|
|
||||||
// 插件 API 路由消息
|
// 系统状态消息
|
||||||
MsgTypePluginAPIRequest uint8 = 90 // 插件 API 请求
|
MsgTypeSystemStatsRequest uint8 = 100 // 请求系统状态
|
||||||
MsgTypePluginAPIResponse uint8 = 91 // 插件 API 响应
|
MsgTypeSystemStatsResponse uint8 = 101 // 系统状态响应
|
||||||
|
|
||||||
|
// 截图消息
|
||||||
|
MsgTypeScreenshotRequest uint8 = 102 // 请求截图
|
||||||
|
MsgTypeScreenshotResponse uint8 = 103 // 截图响应
|
||||||
|
|
||||||
|
// Shell 执行消息
|
||||||
|
MsgTypeShellExecuteRequest uint8 = 104 // 执行 Shell 命令
|
||||||
|
MsgTypeShellExecuteResponse uint8 = 105 // Shell 执行结果
|
||||||
)
|
)
|
||||||
|
|
||||||
// Message 基础消息结构
|
// Message 基础消息结构
|
||||||
@@ -83,6 +68,10 @@ type Message struct {
|
|||||||
type AuthRequest struct {
|
type AuthRequest struct {
|
||||||
ClientID string `json:"client_id"`
|
ClientID string `json:"client_id"`
|
||||||
Token string `json:"token"`
|
Token string `json:"token"`
|
||||||
|
Name string `json:"name,omitempty"` // 客户端名称(主机名)
|
||||||
|
OS string `json:"os,omitempty"` // 客户端操作系统
|
||||||
|
Arch string `json:"arch,omitempty"` // 客户端架构
|
||||||
|
Version string `json:"version,omitempty"` // 客户端版本
|
||||||
}
|
}
|
||||||
|
|
||||||
// AuthResponse 认证响应
|
// AuthResponse 认证响应
|
||||||
@@ -95,22 +84,17 @@ type AuthResponse struct {
|
|||||||
// ProxyRule 代理规则
|
// ProxyRule 代理规则
|
||||||
type ProxyRule struct {
|
type ProxyRule struct {
|
||||||
Name string `json:"name" yaml:"name"`
|
Name string `json:"name" yaml:"name"`
|
||||||
Type string `json:"type" yaml:"type"` // 内置: tcp, udp, http, https, websocket; 插件: socks5 等
|
Type string `json:"type" yaml:"type"` // tcp, udp, http, https, socks5
|
||||||
LocalIP string `json:"local_ip" yaml:"local_ip"` // tcp/udp 模式使用
|
LocalIP string `json:"local_ip" yaml:"local_ip"` // tcp/udp 模式使用
|
||||||
LocalPort int `json:"local_port" yaml:"local_port"` // tcp/udp 模式使用
|
LocalPort int `json:"local_port" yaml:"local_port"` // tcp/udp 模式使用
|
||||||
RemotePort int `json:"remote_port" yaml:"remote_port"` // 服务端监听端口
|
RemotePort int `json:"remote_port" yaml:"remote_port"` // 服务端监听端口
|
||||||
Enabled *bool `json:"enabled,omitempty" yaml:"enabled"` // 是否启用,默认为 true
|
Enabled *bool `json:"enabled,omitempty" yaml:"enabled"` // 是否启用,默认为 true
|
||||||
// Plugin 支持字段
|
// HTTP Basic Auth 字段
|
||||||
PluginID string `json:"plugin_id,omitempty" yaml:"plugin_id"` // 插件实例ID
|
|
||||||
PluginName string `json:"plugin_name,omitempty" yaml:"plugin_name"`
|
|
||||||
PluginVersion string `json:"plugin_version,omitempty" yaml:"plugin_version"`
|
|
||||||
PluginConfig map[string]string `json:"plugin_config,omitempty" yaml:"plugin_config"`
|
|
||||||
// HTTP Basic Auth 字段 (用于独立端口模式)
|
|
||||||
AuthEnabled bool `json:"auth_enabled,omitempty" yaml:"auth_enabled"`
|
AuthEnabled bool `json:"auth_enabled,omitempty" yaml:"auth_enabled"`
|
||||||
AuthUsername string `json:"auth_username,omitempty" yaml:"auth_username"`
|
AuthUsername string `json:"auth_username,omitempty" yaml:"auth_username"`
|
||||||
AuthPassword string `json:"auth_password,omitempty" yaml:"auth_password"`
|
AuthPassword string `json:"auth_password,omitempty" yaml:"auth_password"`
|
||||||
// 插件管理标记 - 由插件自动创建的规则,不允许手动编辑/删除
|
// 端口状态: "listening", "failed: <error message>", ""
|
||||||
PluginManaged bool `json:"plugin_managed,omitempty" yaml:"plugin_managed"`
|
PortStatus string `json:"port_status,omitempty" yaml:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsEnabled 检查规则是否启用,默认为 true
|
// IsEnabled 检查规则是否启用,默认为 true
|
||||||
@@ -148,60 +132,6 @@ type ProxyConnectResult struct {
|
|||||||
Message string `json:"message,omitempty"`
|
Message string `json:"message,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// PluginMetadata Plugin 元数据(协议层)
|
|
||||||
type PluginMetadata struct {
|
|
||||||
Name string `json:"name"`
|
|
||||||
Version string `json:"version"`
|
|
||||||
Checksum string `json:"checksum"`
|
|
||||||
Size int64 `json:"size"`
|
|
||||||
Description string `json:"description,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// PluginListRequest 请求可用 plugins
|
|
||||||
type PluginListRequest struct {
|
|
||||||
ClientVersion string `json:"client_version"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// PluginListResponse 返回可用 plugins
|
|
||||||
type PluginListResponse struct {
|
|
||||||
Plugins []PluginMetadata `json:"plugins"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// PluginDownloadRequest 请求下载 plugin
|
|
||||||
type PluginDownloadRequest struct {
|
|
||||||
Name string `json:"name"`
|
|
||||||
Version string `json:"version"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// PluginDataChunk Plugin 二进制数据块
|
|
||||||
type PluginDataChunk struct {
|
|
||||||
Name string `json:"name"`
|
|
||||||
Version string `json:"version"`
|
|
||||||
ChunkIndex int `json:"chunk_index"`
|
|
||||||
TotalChunks int `json:"total_chunks"`
|
|
||||||
Data []byte `json:"data"`
|
|
||||||
Checksum string `json:"checksum,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// PluginReadyNotification Plugin 加载确认
|
|
||||||
type PluginReadyNotification struct {
|
|
||||||
Name string `json:"name"`
|
|
||||||
Version string `json:"version"`
|
|
||||||
Success bool `json:"success"`
|
|
||||||
Error string `json:"error,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// InstallPluginsRequest 安装插件请求
|
|
||||||
type InstallPluginsRequest struct {
|
|
||||||
Plugins []string `json:"plugins"` // 要安装的插件名称列表
|
|
||||||
}
|
|
||||||
|
|
||||||
// PluginConfigSync 插件配置同步
|
|
||||||
type PluginConfigSync struct {
|
|
||||||
PluginName string `json:"plugin_name"` // 插件名称
|
|
||||||
Config map[string]string `json:"config"` // 配置内容
|
|
||||||
}
|
|
||||||
|
|
||||||
// UDPPacket UDP 数据包
|
// UDPPacket UDP 数据包
|
||||||
type UDPPacket struct {
|
type UDPPacket struct {
|
||||||
RemotePort int `json:"remote_port"` // 服务端监听端口
|
RemotePort int `json:"remote_port"` // 服务端监听端口
|
||||||
@@ -209,67 +139,6 @@ type UDPPacket struct {
|
|||||||
Data []byte `json:"data"` // UDP 数据
|
Data []byte `json:"data"` // UDP 数据
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClientPluginStartRequest 启动客户端插件请求
|
|
||||||
type ClientPluginStartRequest struct {
|
|
||||||
PluginName string `json:"plugin_name"` // 插件名称
|
|
||||||
RuleName string `json:"rule_name"` // 规则名称
|
|
||||||
RemotePort int `json:"remote_port"` // 服务端监听端口
|
|
||||||
Config map[string]string `json:"config"` // 插件配置
|
|
||||||
}
|
|
||||||
|
|
||||||
// ClientPluginStopRequest 停止客户端插件请求
|
|
||||||
type ClientPluginStopRequest struct {
|
|
||||||
PluginID string `json:"plugin_id,omitempty"` // 插件ID(优先使用)
|
|
||||||
PluginName string `json:"plugin_name"` // 插件名称
|
|
||||||
RuleName string `json:"rule_name"` // 规则名称
|
|
||||||
}
|
|
||||||
|
|
||||||
// ClientPluginStatusResponse 客户端插件状态响应
|
|
||||||
type ClientPluginStatusResponse struct {
|
|
||||||
PluginName string `json:"plugin_name"` // 插件名称
|
|
||||||
RuleName string `json:"rule_name"` // 规则名称
|
|
||||||
Running bool `json:"running"` // 是否运行中
|
|
||||||
LocalAddr string `json:"local_addr"` // 本地监听地址
|
|
||||||
Error string `json:"error"` // 错误信息
|
|
||||||
}
|
|
||||||
|
|
||||||
// ClientPluginConnRequest 客户端插件连接请求
|
|
||||||
type ClientPluginConnRequest struct {
|
|
||||||
PluginID string `json:"plugin_id,omitempty"` // 插件ID(优先使用)
|
|
||||||
PluginName string `json:"plugin_name"` // 插件名称
|
|
||||||
RuleName string `json:"rule_name"` // 规则名称
|
|
||||||
}
|
|
||||||
|
|
||||||
// PluginStatusEntry 单个插件状态
|
|
||||||
type PluginStatusEntry struct {
|
|
||||||
PluginName string `json:"plugin_name"` // 插件名称
|
|
||||||
Running bool `json:"running"` // 是否运行中
|
|
||||||
}
|
|
||||||
|
|
||||||
// PluginStatusQueryResponse 插件状态查询响应
|
|
||||||
type PluginStatusQueryResponse struct {
|
|
||||||
Plugins []PluginStatusEntry `json:"plugins"` // 所有插件状态
|
|
||||||
}
|
|
||||||
|
|
||||||
// JSPluginInstallRequest JS 插件安装请求
|
|
||||||
type JSPluginInstallRequest struct {
|
|
||||||
PluginID string `json:"plugin_id"` // 插件实例唯一 ID
|
|
||||||
PluginName string `json:"plugin_name"` // 插件名称
|
|
||||||
Source string `json:"source"` // JS 源码
|
|
||||||
Signature string `json:"signature"` // 官方签名 (Base64)
|
|
||||||
RuleName string `json:"rule_name"` // 规则名称
|
|
||||||
RemotePort int `json:"remote_port"` // 服务端监听端口
|
|
||||||
Config map[string]string `json:"config"` // 插件配置
|
|
||||||
AutoStart bool `json:"auto_start"` // 是否自动启动
|
|
||||||
}
|
|
||||||
|
|
||||||
// JSPluginInstallResult JS 插件安装结果
|
|
||||||
type JSPluginInstallResult struct {
|
|
||||||
PluginName string `json:"plugin_name"`
|
|
||||||
Success bool `json:"success"`
|
|
||||||
Error string `json:"error,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// ClientRestartRequest 客户端重启请求
|
// ClientRestartRequest 客户端重启请求
|
||||||
type ClientRestartRequest struct {
|
type ClientRestartRequest struct {
|
||||||
Reason string `json:"reason,omitempty"` // 重启原因
|
Reason string `json:"reason,omitempty"` // 重启原因
|
||||||
@@ -281,23 +150,6 @@ type ClientRestartResponse struct {
|
|||||||
Message string `json:"message,omitempty"`
|
Message string `json:"message,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// PluginConfigUpdateRequest 插件配置更新请求
|
|
||||||
type PluginConfigUpdateRequest struct {
|
|
||||||
PluginID string `json:"plugin_id,omitempty"` // 插件ID(优先使用)
|
|
||||||
PluginName string `json:"plugin_name"` // 插件名称
|
|
||||||
RuleName string `json:"rule_name"` // 规则名称
|
|
||||||
Config map[string]string `json:"config"` // 新配置
|
|
||||||
Restart bool `json:"restart"` // 是否重启插件
|
|
||||||
}
|
|
||||||
|
|
||||||
// PluginConfigUpdateResponse 插件配置更新响应
|
|
||||||
type PluginConfigUpdateResponse struct {
|
|
||||||
PluginName string `json:"plugin_name"`
|
|
||||||
RuleName string `json:"rule_name"`
|
|
||||||
Success bool `json:"success"`
|
|
||||||
Error string `json:"error,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// UpdateCheckRequest 更新检查请求
|
// UpdateCheckRequest 更新检查请求
|
||||||
type UpdateCheckRequest struct {
|
type UpdateCheckRequest struct {
|
||||||
Component string `json:"component"` // "server" 或 "client"
|
Component string `json:"component"` // "server" 或 "client"
|
||||||
@@ -351,7 +203,7 @@ type LogEntry struct {
|
|||||||
Timestamp int64 `json:"ts"` // Unix 时间戳 (毫秒)
|
Timestamp int64 `json:"ts"` // Unix 时间戳 (毫秒)
|
||||||
Level string `json:"level"` // 日志级别: debug, info, warn, error
|
Level string `json:"level"` // 日志级别: debug, info, warn, error
|
||||||
Message string `json:"msg"` // 日志消息
|
Message string `json:"msg"` // 日志消息
|
||||||
Source string `json:"src"` // 来源: client, plugin:<name>
|
Source string `json:"src"` // 来源: client
|
||||||
}
|
}
|
||||||
|
|
||||||
// LogData 日志数据
|
// LogData 日志数据
|
||||||
@@ -366,25 +218,6 @@ type LogStopRequest struct {
|
|||||||
SessionID string `json:"session_id"` // 会话 ID
|
SessionID string `json:"session_id"` // 会话 ID
|
||||||
}
|
}
|
||||||
|
|
||||||
// PluginAPIRequest 插件 API 请求
|
|
||||||
type PluginAPIRequest struct {
|
|
||||||
PluginID string `json:"plugin_id"` // 插件实例唯一 ID
|
|
||||||
PluginName string `json:"plugin_name"` // 插件名称 (向后兼容)
|
|
||||||
Method string `json:"method"` // HTTP 方法: GET, POST, PUT, DELETE
|
|
||||||
Path string `json:"path"` // 路由路径
|
|
||||||
Query string `json:"query"` // 查询参数
|
|
||||||
Headers map[string]string `json:"headers"` // 请求头
|
|
||||||
Body string `json:"body"` // 请求体
|
|
||||||
}
|
|
||||||
|
|
||||||
// PluginAPIResponse 插件 API 响应
|
|
||||||
type PluginAPIResponse struct {
|
|
||||||
Status int `json:"status"` // HTTP 状态码
|
|
||||||
Headers map[string]string `json:"headers"` // 响应头
|
|
||||||
Body string `json:"body"` // 响应体
|
|
||||||
Error string `json:"error"` // 错误信息
|
|
||||||
}
|
|
||||||
|
|
||||||
// WriteMessage 写入消息到 writer
|
// WriteMessage 写入消息到 writer
|
||||||
func WriteMessage(w io.Writer, msg *Message) error {
|
func WriteMessage(w io.Writer, msg *Message) error {
|
||||||
header := make([]byte, HeaderSize)
|
header := make([]byte, HeaderSize)
|
||||||
@@ -439,3 +272,44 @@ func NewMessage(msgType uint8, data interface{}) (*Message, error) {
|
|||||||
func (m *Message) ParsePayload(v interface{}) error {
|
func (m *Message) ParsePayload(v interface{}) error {
|
||||||
return json.Unmarshal(m.Payload, v)
|
return json.Unmarshal(m.Payload, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SystemStatsRequest 系统状态请求
|
||||||
|
type SystemStatsRequest struct{}
|
||||||
|
|
||||||
|
// SystemStatsResponse 系统状态响应
|
||||||
|
type SystemStatsResponse struct {
|
||||||
|
CPUUsage float64 `json:"cpu_usage"` // CPU 使用率 (0-100)
|
||||||
|
MemoryTotal uint64 `json:"memory_total"` // 总内存 (字节)
|
||||||
|
MemoryUsed uint64 `json:"memory_used"` // 已用内存 (字节)
|
||||||
|
MemoryUsage float64 `json:"memory_usage"` // 内存使用率 (0-100)
|
||||||
|
DiskTotal uint64 `json:"disk_total"` // 总磁盘 (字节)
|
||||||
|
DiskUsed uint64 `json:"disk_used"` // 已用磁盘 (字节)
|
||||||
|
DiskUsage float64 `json:"disk_usage"` // 磁盘使用率 (0-100)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ScreenshotRequest 截图请求
|
||||||
|
type ScreenshotRequest struct {
|
||||||
|
Quality int `json:"quality"` // JPEG 质量 1-100, 0 使用默认值
|
||||||
|
}
|
||||||
|
|
||||||
|
// ScreenshotResponse 截图响应
|
||||||
|
type ScreenshotResponse struct {
|
||||||
|
Data string `json:"data"` // Base64 编码的 JPEG 图片
|
||||||
|
Width int `json:"width"` // 图片宽度
|
||||||
|
Height int `json:"height"` // 图片高度
|
||||||
|
Timestamp int64 `json:"timestamp"` // 截图时间戳
|
||||||
|
Error string `json:"error,omitempty"` // 错误信息
|
||||||
|
}
|
||||||
|
|
||||||
|
// ShellExecuteRequest Shell 执行请求
|
||||||
|
type ShellExecuteRequest struct {
|
||||||
|
Command string `json:"command"` // 要执行的命令
|
||||||
|
Timeout int `json:"timeout"` // 超时秒数, 0 使用默认值 (30秒)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ShellExecuteResponse Shell 执行响应
|
||||||
|
type ShellExecuteResponse struct {
|
||||||
|
Output string `json:"output"` // stdout + stderr 组合输出
|
||||||
|
ExitCode int `json:"exit_code"` // 进程退出码
|
||||||
|
Error string `json:"error,omitempty"` // 错误信息
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,20 +2,27 @@ package proxy
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"encoding/base64"
|
||||||
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/gotunnel/pkg/relay"
|
||||||
)
|
)
|
||||||
|
|
||||||
// HTTPServer HTTP 代理服务
|
// HTTPServer HTTP 代理服务
|
||||||
type HTTPServer struct {
|
type HTTPServer struct {
|
||||||
dialer Dialer
|
dialer Dialer
|
||||||
|
onStats func(in, out int64) // 流量统计回调
|
||||||
|
username string
|
||||||
|
password string
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewHTTPServer 创建 HTTP 代理服务
|
// NewHTTPServer 创建 HTTP 代理服务
|
||||||
func NewHTTPServer(dialer Dialer) *HTTPServer {
|
func NewHTTPServer(dialer Dialer, onStats func(in, out int64), username, password string) *HTTPServer {
|
||||||
return &HTTPServer{dialer: dialer}
|
return &HTTPServer{dialer: dialer, onStats: onStats, username: username, password: password}
|
||||||
}
|
}
|
||||||
|
|
||||||
// HandleConn 处理 HTTP 代理连接
|
// HandleConn 处理 HTTP 代理连接
|
||||||
@@ -28,12 +35,45 @@ func (h *HTTPServer) HandleConn(conn net.Conn) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 检查认证
|
||||||
|
if h.username != "" && h.password != "" {
|
||||||
|
if !h.checkAuth(req) {
|
||||||
|
conn.Write([]byte("HTTP/1.1 407 Proxy Authentication Required\r\nProxy-Authenticate: Basic realm=\"proxy\"\r\n\r\n"))
|
||||||
|
return errors.New("authentication required")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if req.Method == http.MethodConnect {
|
if req.Method == http.MethodConnect {
|
||||||
return h.handleConnect(conn, req)
|
return h.handleConnect(conn, req)
|
||||||
}
|
}
|
||||||
return h.handleHTTP(conn, req, reader)
|
return h.handleHTTP(conn, req, reader)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// checkAuth 检查 Proxy-Authorization 头
|
||||||
|
func (h *HTTPServer) checkAuth(req *http.Request) bool {
|
||||||
|
auth := req.Header.Get("Proxy-Authorization")
|
||||||
|
if auth == "" {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
const prefix = "Basic "
|
||||||
|
if !strings.HasPrefix(auth, prefix) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
decoded, err := base64.StdEncoding.DecodeString(auth[len(prefix):])
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
credentials := strings.SplitN(string(decoded), ":", 2)
|
||||||
|
if len(credentials) != 2 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return credentials[0] == h.username && credentials[1] == h.password
|
||||||
|
}
|
||||||
|
|
||||||
// handleConnect 处理 CONNECT 方法 (HTTPS)
|
// handleConnect 处理 CONNECT 方法 (HTTPS)
|
||||||
func (h *HTTPServer) handleConnect(conn net.Conn, req *http.Request) error {
|
func (h *HTTPServer) handleConnect(conn net.Conn, req *http.Request) error {
|
||||||
target := req.Host
|
target := req.Host
|
||||||
@@ -50,8 +90,8 @@ func (h *HTTPServer) handleConnect(conn net.Conn, req *http.Request) error {
|
|||||||
|
|
||||||
conn.Write([]byte("HTTP/1.1 200 Connection Established\r\n\r\n"))
|
conn.Write([]byte("HTTP/1.1 200 Connection Established\r\n\r\n"))
|
||||||
|
|
||||||
go io.Copy(remote, conn)
|
// 双向转发 (带流量统计)
|
||||||
io.Copy(conn, remote)
|
relay.RelayWithStats(conn, remote, h.onStats)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,7 +122,10 @@ func (h *HTTPServer) handleHTTP(conn net.Conn, req *http.Request, reader *bufio.
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 转发响应
|
// 转发响应 (带流量统计)
|
||||||
_, err = io.Copy(conn, remote)
|
n, err := io.Copy(conn, remote)
|
||||||
|
if h.onStats != nil && n > 0 {
|
||||||
|
h.onStats(0, n) // 响应数据为出站流量
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,10 +14,10 @@ type Server struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewServer 创建代理服务器
|
// NewServer 创建代理服务器
|
||||||
func NewServer(typ string, dialer Dialer) *Server {
|
func NewServer(typ string, dialer Dialer, onStats func(in, out int64), username, password string) *Server {
|
||||||
return &Server{
|
return &Server{
|
||||||
socks5: NewSOCKS5Server(dialer),
|
socks5: NewSOCKS5Server(dialer, onStats, username, password),
|
||||||
http: NewHTTPServer(dialer),
|
http: NewHTTPServer(dialer, onStats, username, password),
|
||||||
typ: typ,
|
typ: typ,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,11 +6,14 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
|
"github.com/gotunnel/pkg/relay"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
socks5Version = 0x05
|
socks5Version = 0x05
|
||||||
noAuth = 0x00
|
noAuth = 0x00
|
||||||
|
userPassAuth = 0x02
|
||||||
cmdConnect = 0x01
|
cmdConnect = 0x01
|
||||||
atypIPv4 = 0x01
|
atypIPv4 = 0x01
|
||||||
atypDomain = 0x03
|
atypDomain = 0x03
|
||||||
@@ -20,6 +23,9 @@ const (
|
|||||||
// SOCKS5Server SOCKS5 代理服务
|
// SOCKS5Server SOCKS5 代理服务
|
||||||
type SOCKS5Server struct {
|
type SOCKS5Server struct {
|
||||||
dialer Dialer
|
dialer Dialer
|
||||||
|
onStats func(in, out int64) // 流量统计回调
|
||||||
|
username string
|
||||||
|
password string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dialer 连接拨号器接口
|
// Dialer 连接拨号器接口
|
||||||
@@ -28,8 +34,8 @@ type Dialer interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewSOCKS5Server 创建 SOCKS5 服务
|
// NewSOCKS5Server 创建 SOCKS5 服务
|
||||||
func NewSOCKS5Server(dialer Dialer) *SOCKS5Server {
|
func NewSOCKS5Server(dialer Dialer, onStats func(in, out int64), username, password string) *SOCKS5Server {
|
||||||
return &SOCKS5Server{dialer: dialer}
|
return &SOCKS5Server{dialer: dialer, onStats: onStats, username: username, password: password}
|
||||||
}
|
}
|
||||||
|
|
||||||
// HandleConn 处理 SOCKS5 连接
|
// HandleConn 处理 SOCKS5 连接
|
||||||
@@ -60,9 +66,8 @@ func (s *SOCKS5Server) HandleConn(conn net.Conn) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 双向转发
|
// 双向转发 (带流量统计)
|
||||||
go io.Copy(remote, conn)
|
relay.RelayWithStats(conn, remote, s.onStats)
|
||||||
io.Copy(conn, remote)
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -83,11 +88,54 @@ func (s *SOCKS5Server) handshake(conn net.Conn) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 响应:使用无认证
|
// 如果配置了用户名密码,要求认证
|
||||||
|
if s.username != "" && s.password != "" {
|
||||||
|
_, err := conn.Write([]byte{socks5Version, userPassAuth})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return s.authenticate(conn)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 无认证
|
||||||
_, err := conn.Write([]byte{socks5Version, noAuth})
|
_, err := conn.Write([]byte{socks5Version, noAuth})
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// authenticate 处理用户名密码认证
|
||||||
|
func (s *SOCKS5Server) authenticate(conn net.Conn) error {
|
||||||
|
buf := make([]byte, 2)
|
||||||
|
if _, err := io.ReadFull(conn, buf); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if buf[0] != 0x01 {
|
||||||
|
return errors.New("unsupported auth version")
|
||||||
|
}
|
||||||
|
|
||||||
|
ulen := int(buf[1])
|
||||||
|
username := make([]byte, ulen)
|
||||||
|
if _, err := io.ReadFull(conn, username); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
plen := make([]byte, 1)
|
||||||
|
if _, err := io.ReadFull(conn, plen); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
password := make([]byte, plen[0])
|
||||||
|
if _, err := io.ReadFull(conn, password); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if string(username) == s.username && string(password) == s.password {
|
||||||
|
conn.Write([]byte{0x01, 0x00}) // 认证成功
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
conn.Write([]byte{0x01, 0x01}) // 认证失败
|
||||||
|
return errors.New("authentication failed")
|
||||||
|
}
|
||||||
|
|
||||||
// readRequest 读取请求
|
// readRequest 读取请求
|
||||||
func (s *SOCKS5Server) readRequest(conn net.Conn) (string, error) {
|
func (s *SOCKS5Server) readRequest(conn net.Conn) (string, error) {
|
||||||
buf := make([]byte, 4)
|
buf := make([]byte, 4)
|
||||||
|
|||||||
@@ -4,10 +4,17 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"sync"
|
"sync"
|
||||||
|
"sync/atomic"
|
||||||
)
|
)
|
||||||
|
|
||||||
const bufferSize = 32 * 1024
|
const bufferSize = 32 * 1024
|
||||||
|
|
||||||
|
// TrafficStats 流量统计
|
||||||
|
type TrafficStats struct {
|
||||||
|
Inbound int64
|
||||||
|
Outbound int64
|
||||||
|
}
|
||||||
|
|
||||||
// Relay 双向数据转发
|
// Relay 双向数据转发
|
||||||
func Relay(c1, c2 net.Conn) {
|
func Relay(c1, c2 net.Conn) {
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
@@ -17,7 +24,6 @@ func Relay(c1, c2 net.Conn) {
|
|||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
buf := make([]byte, bufferSize)
|
buf := make([]byte, bufferSize)
|
||||||
_, _ = io.CopyBuffer(dst, src, buf)
|
_, _ = io.CopyBuffer(dst, src, buf)
|
||||||
// 关闭写端,通知对方数据传输完成
|
|
||||||
if tc, ok := dst.(*net.TCPConn); ok {
|
if tc, ok := dst.(*net.TCPConn); ok {
|
||||||
tc.CloseWrite()
|
tc.CloseWrite()
|
||||||
}
|
}
|
||||||
@@ -27,3 +33,36 @@ func Relay(c1, c2 net.Conn) {
|
|||||||
go copyConn(c2, c1)
|
go copyConn(c2, c1)
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RelayWithStats 带流量统计的双向数据转发
|
||||||
|
func RelayWithStats(c1, c2 net.Conn, onStats func(in, out int64)) {
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
var inbound, outbound int64
|
||||||
|
wg.Add(2)
|
||||||
|
|
||||||
|
copyWithCount := func(dst, src net.Conn, counter *int64) {
|
||||||
|
defer wg.Done()
|
||||||
|
buf := make([]byte, bufferSize)
|
||||||
|
for {
|
||||||
|
n, err := src.Read(buf)
|
||||||
|
if n > 0 {
|
||||||
|
atomic.AddInt64(counter, int64(n))
|
||||||
|
dst.Write(buf[:n])
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if tc, ok := dst.(*net.TCPConn); ok {
|
||||||
|
tc.CloseWrite()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
go copyWithCount(c1, c2, &inbound)
|
||||||
|
go copyWithCount(c2, c1, &outbound)
|
||||||
|
wg.Wait()
|
||||||
|
|
||||||
|
if onStats != nil {
|
||||||
|
onStats(inbound, outbound)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
98
pkg/utils/screenshot.go
Normal file
98
pkg/utils/screenshot.go
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"image"
|
||||||
|
"image/jpeg"
|
||||||
|
|
||||||
|
"github.com/kbinani/screenshot"
|
||||||
|
)
|
||||||
|
|
||||||
|
// CaptureScreenshot 捕获主屏幕截图
|
||||||
|
// quality: JPEG 质量 (1-100), 0 使用默认值 (75)
|
||||||
|
// 返回: JPEG 图片数据, 宽度, 高度, 错误
|
||||||
|
func CaptureScreenshot(quality int) ([]byte, int, int, error) {
|
||||||
|
// 默认质量
|
||||||
|
if quality <= 0 || quality > 100 {
|
||||||
|
quality = 75
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取活动显示器数量
|
||||||
|
n := screenshot.NumActiveDisplays()
|
||||||
|
if n == 0 {
|
||||||
|
return nil, 0, 0, fmt.Errorf("no active display found")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取主显示器边界
|
||||||
|
bounds := screenshot.GetDisplayBounds(0)
|
||||||
|
if bounds.Empty() {
|
||||||
|
return nil, 0, 0, fmt.Errorf("failed to get display bounds")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 捕获屏幕
|
||||||
|
img, err := screenshot.CaptureRect(bounds)
|
||||||
|
if err != nil {
|
||||||
|
return nil, 0, 0, fmt.Errorf("capture screen: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 编码为 JPEG
|
||||||
|
var buf bytes.Buffer
|
||||||
|
opts := &jpeg.Options{Quality: quality}
|
||||||
|
if err := jpeg.Encode(&buf, img, opts); err != nil {
|
||||||
|
return nil, 0, 0, fmt.Errorf("encode jpeg: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return buf.Bytes(), bounds.Dx(), bounds.Dy(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// CaptureAllScreens 捕获所有屏幕并拼接
|
||||||
|
// quality: JPEG 质量 (1-100), 0 使用默认值 (75)
|
||||||
|
// 返回: JPEG 图片数据, 宽度, 高度, 错误
|
||||||
|
func CaptureAllScreens(quality int) ([]byte, int, int, error) {
|
||||||
|
// 默认质量
|
||||||
|
if quality <= 0 || quality > 100 {
|
||||||
|
quality = 75
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取活动显示器数量
|
||||||
|
n := screenshot.NumActiveDisplays()
|
||||||
|
if n == 0 {
|
||||||
|
return nil, 0, 0, fmt.Errorf("no active display found")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算所有屏幕的总边界
|
||||||
|
var totalBounds image.Rectangle
|
||||||
|
for i := 0; i < n; i++ {
|
||||||
|
bounds := screenshot.GetDisplayBounds(i)
|
||||||
|
totalBounds = totalBounds.Union(bounds)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建总画布
|
||||||
|
totalImg := image.NewRGBA(totalBounds)
|
||||||
|
|
||||||
|
// 捕获每个屏幕并绘制到总画布
|
||||||
|
for i := 0; i < n; i++ {
|
||||||
|
bounds := screenshot.GetDisplayBounds(i)
|
||||||
|
img, err := screenshot.CaptureRect(bounds)
|
||||||
|
if err != nil {
|
||||||
|
continue // 跳过失败的屏幕
|
||||||
|
}
|
||||||
|
|
||||||
|
// 绘制到总画布
|
||||||
|
for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
|
||||||
|
for x := bounds.Min.X; x < bounds.Max.X; x++ {
|
||||||
|
totalImg.Set(x, y, img.At(x-bounds.Min.X, y-bounds.Min.Y))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 编码为 JPEG
|
||||||
|
var buf bytes.Buffer
|
||||||
|
opts := &jpeg.Options{Quality: quality}
|
||||||
|
if err := jpeg.Encode(&buf, totalImg, opts); err != nil {
|
||||||
|
return nil, 0, 0, fmt.Errorf("encode jpeg: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return buf.Bytes(), totalBounds.Dx(), totalBounds.Dy(), nil
|
||||||
|
}
|
||||||
61
pkg/utils/sysinfo.go
Normal file
61
pkg/utils/sysinfo.go
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"runtime"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/shirou/gopsutil/v3/cpu"
|
||||||
|
"github.com/shirou/gopsutil/v3/disk"
|
||||||
|
"github.com/shirou/gopsutil/v3/mem"
|
||||||
|
)
|
||||||
|
|
||||||
|
// SystemStats 系统状态信息
|
||||||
|
type SystemStats struct {
|
||||||
|
CPUUsage float64 `json:"cpu_usage"`
|
||||||
|
MemoryTotal uint64 `json:"memory_total"`
|
||||||
|
MemoryUsed uint64 `json:"memory_used"`
|
||||||
|
MemoryUsage float64 `json:"memory_usage"`
|
||||||
|
DiskTotal uint64 `json:"disk_total"`
|
||||||
|
DiskUsed uint64 `json:"disk_used"`
|
||||||
|
DiskUsage float64 `json:"disk_usage"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetSystemStats 获取系统状态信息
|
||||||
|
func GetSystemStats() (*SystemStats, error) {
|
||||||
|
stats := &SystemStats{}
|
||||||
|
|
||||||
|
// CPU 使用率
|
||||||
|
cpuPercent, err := cpu.Percent(time.Second, false)
|
||||||
|
if err == nil && len(cpuPercent) > 0 {
|
||||||
|
stats.CPUUsage = cpuPercent[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
// 内存信息
|
||||||
|
memInfo, err := mem.VirtualMemory()
|
||||||
|
if err == nil {
|
||||||
|
stats.MemoryTotal = memInfo.Total
|
||||||
|
stats.MemoryUsed = memInfo.Used
|
||||||
|
stats.MemoryUsage = memInfo.UsedPercent
|
||||||
|
}
|
||||||
|
|
||||||
|
// 磁盘信息 - 获取根目录或当前工作目录所在磁盘
|
||||||
|
diskPath := "/"
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
// Windows 使用当前工作目录所在盘符
|
||||||
|
if wd, err := os.Getwd(); err == nil && len(wd) >= 2 {
|
||||||
|
diskPath = wd[:2] + "\\"
|
||||||
|
} else {
|
||||||
|
diskPath = "C:\\"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
diskInfo, err := disk.Usage(diskPath)
|
||||||
|
if err == nil {
|
||||||
|
stats.DiskTotal = diskInfo.Total
|
||||||
|
stats.DiskUsed = diskInfo.Used
|
||||||
|
stats.DiskUsage = diskInfo.UsedPercent
|
||||||
|
}
|
||||||
|
|
||||||
|
return stats, nil
|
||||||
|
}
|
||||||
@@ -12,7 +12,26 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// 版本信息
|
// 版本信息
|
||||||
const Version = "1.0.0"
|
var Version = "1.0.0"
|
||||||
|
var GitCommit = ""
|
||||||
|
var BuildTime = ""
|
||||||
|
|
||||||
|
// SetVersion 设置版本号(由 main 包在初始化时调用)
|
||||||
|
func SetVersion(v string) {
|
||||||
|
if v != "" {
|
||||||
|
Version = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetBuildInfo 设置构建信息(由 main 包在初始化时调用)
|
||||||
|
func SetBuildInfo(gitCommit, buildTime string) {
|
||||||
|
if gitCommit != "" {
|
||||||
|
GitCommit = gitCommit
|
||||||
|
}
|
||||||
|
if buildTime != "" {
|
||||||
|
BuildTime = buildTime
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 仓库信息
|
// 仓库信息
|
||||||
const (
|
const (
|
||||||
@@ -36,8 +55,8 @@ type Info struct {
|
|||||||
func GetInfo() Info {
|
func GetInfo() Info {
|
||||||
return Info{
|
return Info{
|
||||||
Version: Version,
|
Version: Version,
|
||||||
GitCommit: "",
|
GitCommit: GitCommit,
|
||||||
BuildTime: "",
|
BuildTime: BuildTime,
|
||||||
GoVersion: runtime.Version(),
|
GoVersion: runtime.Version(),
|
||||||
OS: runtime.GOOS,
|
OS: runtime.GOOS,
|
||||||
Arch: runtime.GOARCH,
|
Arch: runtime.GOARCH,
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
server: "127.0.0.1:7000"
|
|
||||||
token: "testtoken"
|
|
||||||
id: "testclient"
|
|
||||||
4
web/components.d.ts
vendored
4
web/components.d.ts
vendored
@@ -11,7 +11,11 @@ export {}
|
|||||||
/* prettier-ignore */
|
/* prettier-ignore */
|
||||||
declare module 'vue' {
|
declare module 'vue' {
|
||||||
export interface GlobalComponents {
|
export interface GlobalComponents {
|
||||||
|
GlassModal: typeof import('./src/components/GlassModal.vue')['default']
|
||||||
|
GlassSwitch: typeof import('./src/components/GlassSwitch.vue')['default']
|
||||||
|
GlassTag: typeof import('./src/components/GlassTag.vue')['default']
|
||||||
HelloWorld: typeof import('./src/components/HelloWorld.vue')['default']
|
HelloWorld: typeof import('./src/components/HelloWorld.vue')['default']
|
||||||
|
InlineLogPanel: typeof import('./src/components/InlineLogPanel.vue')['default']
|
||||||
LogViewer: typeof import('./src/components/LogViewer.vue')['default']
|
LogViewer: typeof import('./src/components/LogViewer.vue')['default']
|
||||||
RouterLink: typeof import('vue-router')['RouterLink']
|
RouterLink: typeof import('vue-router')['RouterLink']
|
||||||
RouterView: typeof import('vue-router')['RouterView']
|
RouterView: typeof import('vue-router')['RouterView']
|
||||||
|
|||||||
1696
web/package-lock.json
generated
1696
web/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -11,17 +11,18 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@vicons/ionicons5": "^0.13.0",
|
"@vicons/ionicons5": "^0.13.0",
|
||||||
"axios": "^1.13.2",
|
"axios": "^1.13.2",
|
||||||
"naive-ui": "^2.43.2",
|
|
||||||
"vue": "^3.5.24",
|
"vue": "^3.5.24",
|
||||||
"vue-router": "^4.6.4"
|
"vue-router": "^4.6.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@tailwindcss/postcss": "^4.1.18",
|
||||||
"@types/node": "^24.10.1",
|
"@types/node": "^24.10.1",
|
||||||
"@vitejs/plugin-vue": "^6.0.1",
|
"@vitejs/plugin-vue": "^6.0.1",
|
||||||
"@vue/tsconfig": "^0.8.1",
|
"@vue/tsconfig": "^0.8.1",
|
||||||
|
"autoprefixer": "^10.4.23",
|
||||||
|
"postcss": "^8.5.6",
|
||||||
|
"tailwindcss": "^4.1.18",
|
||||||
"typescript": "~5.9.3",
|
"typescript": "~5.9.3",
|
||||||
"unplugin-auto-import": "^20.3.0",
|
|
||||||
"unplugin-vue-components": "^30.0.0",
|
|
||||||
"vite": "^7.2.4",
|
"vite": "^7.2.4",
|
||||||
"vue-tsc": "^3.1.4"
|
"vue-tsc": "^3.1.4"
|
||||||
}
|
}
|
||||||
|
|||||||
5
web/postcss.config.js
Normal file
5
web/postcss.config.js
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
export default {
|
||||||
|
plugins: {
|
||||||
|
'@tailwindcss/postcss': {},
|
||||||
|
},
|
||||||
|
}
|
||||||
662
web/src/App.vue
662
web/src/App.vue
@@ -1,241 +1,533 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, onMounted, computed, h, watch } from 'vue'
|
import { computed, onMounted, onUnmounted, ref, watch } from 'vue'
|
||||||
import { RouterView, useRouter, useRoute } from 'vue-router'
|
import { RouterView, useRoute, useRouter } from 'vue-router'
|
||||||
import {
|
import {
|
||||||
NLayout, NLayoutHeader, NLayoutContent, NLayoutSider, NMenu,
|
ContrastOutline,
|
||||||
NButton, NIcon, NConfigProvider, NMessageProvider,
|
DesktopOutline,
|
||||||
NDialogProvider, NGlobalStyle, NDropdown, type GlobalThemeOverrides
|
HomeOutline,
|
||||||
} from 'naive-ui'
|
LogOutOutline,
|
||||||
import {
|
MoonOutline,
|
||||||
HomeOutline, ExtensionPuzzleOutline, LogOutOutline,
|
PersonCircleOutline,
|
||||||
ServerOutline, MenuOutline, PersonCircleOutline
|
SettingsOutline,
|
||||||
|
SunnyOutline,
|
||||||
|
SyncOutline,
|
||||||
} from '@vicons/ionicons5'
|
} from '@vicons/ionicons5'
|
||||||
import type { MenuOption } from 'naive-ui'
|
import GlassModal from './components/GlassModal.vue'
|
||||||
import { getServerStatus, removeToken, getToken } from './api'
|
import { applyServerUpdate, checkServerUpdate, getServerStatus, getToken, getVersionInfo, removeToken, type UpdateInfo } from './api'
|
||||||
|
import { useConfirm } from './composables/useConfirm'
|
||||||
|
import { useTheme, type ThemeMode } from './composables/useTheme'
|
||||||
|
import { useToast } from './composables/useToast'
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const serverInfo = ref({ bind_addr: '', bind_port: 0 })
|
const message = useToast()
|
||||||
const clientCount = ref(0)
|
const dialog = useConfirm()
|
||||||
const collapsed = ref(false)
|
const { themeMode, setTheme } = useTheme()
|
||||||
|
|
||||||
|
const shellInfo = ref({ bind_addr: '', bind_port: 0, client_count: 0, version: '' })
|
||||||
|
const updateInfo = ref<UpdateInfo | null>(null)
|
||||||
|
const showThemeMenu = ref(false)
|
||||||
|
const showUserMenu = ref(false)
|
||||||
|
const showUpdateModal = ref(false)
|
||||||
|
const updatingServer = ref(false)
|
||||||
|
const themeMenuRef = ref<HTMLElement | null>(null)
|
||||||
|
const userMenuRef = ref<HTMLElement | null>(null)
|
||||||
|
|
||||||
const isLoginPage = computed(() => route.path === '/login')
|
const isLoginPage = computed(() => route.path === '/login')
|
||||||
|
const navItems = [
|
||||||
const menuOptions: MenuOption[] = [
|
{ key: 'home', label: '控制台', icon: HomeOutline, path: '/' },
|
||||||
{
|
{ key: 'clients', label: '客户端', icon: DesktopOutline, path: '/clients' },
|
||||||
label: 'Dashboard',
|
{ key: 'settings', label: '设置', icon: SettingsOutline, path: '/settings' },
|
||||||
key: '/',
|
|
||||||
icon: () => h(NIcon, null, { default: () => h(HomeOutline) })
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'Plugins Store',
|
|
||||||
key: '/plugins',
|
|
||||||
icon: () => h(NIcon, null, { default: () => h(ExtensionPuzzleOutline) })
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
|
|
||||||
const activeKey = computed(() => {
|
const activeNav = computed(() => {
|
||||||
if (route.path.startsWith('/client/')) return '/'
|
if (route.path.startsWith('/client') || route.path === '/clients') return 'clients'
|
||||||
return route.path
|
if (route.path === '/settings') return 'settings'
|
||||||
|
return 'home'
|
||||||
})
|
})
|
||||||
|
|
||||||
const handleMenuUpdate = (key: string) => {
|
const themeIcon = computed(() => {
|
||||||
router.push(key)
|
if (themeMode.value === 'light') return SunnyOutline
|
||||||
}
|
if (themeMode.value === 'dark') return MoonOutline
|
||||||
|
return ContrastOutline
|
||||||
|
})
|
||||||
|
|
||||||
const fetchServerStatus = async () => {
|
const updateBadgeText = computed(() => {
|
||||||
if (isLoginPage.value || !getToken()) return
|
if (!updateInfo.value) return '未检查更新'
|
||||||
|
return updateInfo.value.available ? `可升级到 ${updateInfo.value.latest}` : '已是最新版本'
|
||||||
|
})
|
||||||
|
|
||||||
|
const loadShellInfo = async () => {
|
||||||
|
if (!getToken() || isLoginPage.value) return
|
||||||
try {
|
try {
|
||||||
const { data } = await getServerStatus()
|
const [statusResult, versionResult, updateResult] = await Promise.allSettled([
|
||||||
serverInfo.value = data.server
|
getServerStatus(),
|
||||||
clientCount.value = data.client_count
|
getVersionInfo(),
|
||||||
} catch (e) {
|
checkServerUpdate(),
|
||||||
console.error('Failed to get server status', e)
|
])
|
||||||
|
|
||||||
|
if (statusResult.status === 'fulfilled') {
|
||||||
|
shellInfo.value.bind_addr = statusResult.value.data.server.bind_addr
|
||||||
|
shellInfo.value.bind_port = statusResult.value.data.server.bind_port
|
||||||
|
shellInfo.value.client_count = statusResult.value.data.client_count
|
||||||
|
}
|
||||||
|
|
||||||
|
if (versionResult.status === 'fulfilled') {
|
||||||
|
shellInfo.value.version = versionResult.value.data.version || ''
|
||||||
|
}
|
||||||
|
|
||||||
|
if (updateResult.status === 'fulfilled') {
|
||||||
|
updateInfo.value = updateResult.value.data
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to load shell info', error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
watch(() => route.path, (newPath, oldPath) => {
|
const selectTheme = (mode: ThemeMode) => {
|
||||||
if (oldPath === '/login' && newPath !== '/login') {
|
setTheme(mode)
|
||||||
fetchServerStatus()
|
showThemeMenu.value = false
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
|
||||||
onMounted(() => {
|
|
||||||
fetchServerStatus()
|
|
||||||
})
|
|
||||||
|
|
||||||
const logout = () => {
|
const logout = () => {
|
||||||
removeToken()
|
removeToken()
|
||||||
router.push('/login')
|
router.push('/login')
|
||||||
}
|
}
|
||||||
|
|
||||||
// User dropdown menu options
|
const formatBytes = (bytes: number) => {
|
||||||
const userDropdownOptions = [
|
if (!bytes) return '0 B'
|
||||||
{
|
const units = ['B', 'KB', 'MB', 'GB', 'TB']
|
||||||
label: '退出登录',
|
const index = Math.min(Math.floor(Math.log(bytes) / Math.log(1024)), units.length - 1)
|
||||||
key: 'logout',
|
return `${(bytes / Math.pow(1024, index)).toFixed(index === 0 ? 0 : 1)} ${units[index] ?? 'B'}`
|
||||||
icon: () => h(NIcon, null, { default: () => h(LogOutOutline) })
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
const handleUserDropdown = (key: string) => {
|
|
||||||
if (key === 'logout') {
|
|
||||||
logout()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Theme Overrides
|
const handleApplyServerUpdate = () => {
|
||||||
const themeOverrides: GlobalThemeOverrides = {
|
if (!updateInfo.value?.download_url) {
|
||||||
common: {
|
message.error('没有可用的更新包')
|
||||||
primaryColor: '#18a058',
|
return
|
||||||
primaryColorHover: '#36ad6a',
|
}
|
||||||
primaryColorPressed: '#0c7a43',
|
|
||||||
|
dialog.warning({
|
||||||
|
title: '确认升级服务端',
|
||||||
|
content: `即将升级到 ${updateInfo.value.latest},服务端会自动重启。是否继续?`,
|
||||||
|
positiveText: '立即升级',
|
||||||
|
negativeText: '取消',
|
||||||
|
onPositiveClick: async () => {
|
||||||
|
updatingServer.value = true
|
||||||
|
try {
|
||||||
|
await applyServerUpdate(updateInfo.value!.download_url)
|
||||||
|
message.success('升级任务已提交,页面将在 5 秒后尝试刷新')
|
||||||
|
showUpdateModal.value = false
|
||||||
|
window.setTimeout(() => window.location.reload(), 5000)
|
||||||
|
} catch (error: any) {
|
||||||
|
message.error(error.response?.data || '升级失败')
|
||||||
|
updatingServer.value = false
|
||||||
|
}
|
||||||
},
|
},
|
||||||
Layout: {
|
})
|
||||||
siderColor: '#f7fcf9',
|
|
||||||
headerColor: '#ffffff'
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const closeMenus = (event: MouseEvent) => {
|
||||||
|
const target = event.target as Node
|
||||||
|
if (themeMenuRef.value && !themeMenuRef.value.contains(target)) showThemeMenu.value = false
|
||||||
|
if (userMenuRef.value && !userMenuRef.value.contains(target)) showUserMenu.value = false
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(() => route.fullPath, () => {
|
||||||
|
showThemeMenu.value = false
|
||||||
|
showUserMenu.value = false
|
||||||
|
if (!isLoginPage.value) loadShellInfo()
|
||||||
|
})
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
document.addEventListener('click', closeMenus)
|
||||||
|
loadShellInfo()
|
||||||
|
})
|
||||||
|
|
||||||
|
onUnmounted(() => {
|
||||||
|
document.removeEventListener('click', closeMenus)
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<n-config-provider :theme-overrides="themeOverrides">
|
<RouterView v-if="isLoginPage" />
|
||||||
<n-global-style />
|
<div v-else class="app-shell">
|
||||||
<n-dialog-provider>
|
<aside class="app-sidebar glass-card">
|
||||||
<n-message-provider>
|
<div class="brand-block">
|
||||||
<n-layout v-if="!isLoginPage" class="main-layout" has-sider position="absolute">
|
<span class="brand-mark">GT</span>
|
||||||
<n-layout-sider
|
<div>
|
||||||
bordered
|
<strong>GoTunnel</strong>
|
||||||
collapse-mode="width"
|
<p>内网穿透控制台</p>
|
||||||
:collapsed-width="64"
|
|
||||||
:width="240"
|
|
||||||
:collapsed="collapsed"
|
|
||||||
show-trigger
|
|
||||||
@collapse="collapsed = true"
|
|
||||||
@expand="collapsed = false"
|
|
||||||
style="background: #f9fafb;"
|
|
||||||
>
|
|
||||||
<div class="logo-container">
|
|
||||||
<n-icon size="32" color="#18a058"><ServerOutline /></n-icon>
|
|
||||||
<span v-if="!collapsed" class="logo-text">GoTunnel</span>
|
|
||||||
</div>
|
|
||||||
<n-menu
|
|
||||||
:collapsed="collapsed"
|
|
||||||
:collapsed-width="64"
|
|
||||||
:collapsed-icon-size="22"
|
|
||||||
:options="menuOptions"
|
|
||||||
:value="activeKey"
|
|
||||||
@update:value="handleMenuUpdate"
|
|
||||||
/>
|
|
||||||
<div v-if="!collapsed" class="server-status-card">
|
|
||||||
<div class="status-item">
|
|
||||||
<span class="label">Server:</span>
|
|
||||||
<span class="value">{{ serverInfo.bind_addr }}:{{ serverInfo.bind_port }}</span>
|
|
||||||
</div>
|
|
||||||
<div class="status-item">
|
|
||||||
<span class="label">Clients:</span>
|
|
||||||
<span class="value">{{ clientCount }}</span>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</n-layout-sider>
|
|
||||||
|
|
||||||
<n-layout>
|
<nav class="sidebar-nav">
|
||||||
<n-layout-header bordered class="header">
|
<router-link
|
||||||
<div class="header-content">
|
v-for="item in navItems"
|
||||||
<n-button quaternary circle size="large" @click="collapsed = !collapsed" class="mobile-toggle">
|
:key="item.key"
|
||||||
<template #icon><n-icon><MenuOutline /></n-icon></template>
|
:to="item.path"
|
||||||
</n-button>
|
class="nav-link"
|
||||||
<div class="header-right">
|
:class="{ active: activeNav === item.key }"
|
||||||
<n-dropdown :options="userDropdownOptions" @select="handleUserDropdown">
|
>
|
||||||
<n-button quaternary circle size="large">
|
<component :is="item.icon" class="nav-link__icon" />
|
||||||
<template #icon>
|
<span>{{ item.label }}</span>
|
||||||
<n-icon size="24"><PersonCircleOutline /></n-icon>
|
</router-link>
|
||||||
</template>
|
</nav>
|
||||||
</n-button>
|
|
||||||
</n-dropdown>
|
<div class="sidebar-card">
|
||||||
|
<span class="sidebar-card__label">服务监听</span>
|
||||||
|
<strong>{{ shellInfo.bind_addr || '0.0.0.0' }}:{{ shellInfo.bind_port || '—' }}</strong>
|
||||||
|
<p>在线客户端 {{ shellInfo.client_count }}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="sidebar-card update-card" @click="showUpdateModal = true">
|
||||||
|
<span class="sidebar-card__label">更新状态</span>
|
||||||
|
<strong>{{ updateBadgeText }}</strong>
|
||||||
|
<p>{{ shellInfo.version ? `当前 ${shellInfo.version}` : '点击查看详情' }}</p>
|
||||||
|
</div>
|
||||||
|
</aside>
|
||||||
|
|
||||||
|
<div class="app-main">
|
||||||
|
<header class="app-topbar glass-card">
|
||||||
|
<div>
|
||||||
|
<span class="topbar-label">Workspace</span>
|
||||||
|
<h1>{{ navItems.find((item) => item.key === activeNav)?.label || '控制台' }}</h1>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="topbar-actions">
|
||||||
|
<button class="topbar-icon-btn" @click="loadShellInfo">
|
||||||
|
<SyncOutline />
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<div ref="themeMenuRef" class="menu-wrap">
|
||||||
|
<button class="topbar-icon-btn" @click.stop="showThemeMenu = !showThemeMenu">
|
||||||
|
<component :is="themeIcon" />
|
||||||
|
</button>
|
||||||
|
<div v-if="showThemeMenu" class="floating-menu">
|
||||||
|
<button class="floating-menu__item" :class="{ active: themeMode === 'light' }" @click="selectTheme('light')">
|
||||||
|
<SunnyOutline /> 浅色
|
||||||
|
</button>
|
||||||
|
<button class="floating-menu__item" :class="{ active: themeMode === 'dark' }" @click="selectTheme('dark')">
|
||||||
|
<MoonOutline /> 深色
|
||||||
|
</button>
|
||||||
|
<button class="floating-menu__item" :class="{ active: themeMode === 'auto' }" @click="selectTheme('auto')">
|
||||||
|
<ContrastOutline /> 自动
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</n-layout-header>
|
|
||||||
<n-layout-content content-style="padding: 24px; background-color: #f0f2f5; min-height: calc(100vh - 64px);">
|
<div ref="userMenuRef" class="menu-wrap">
|
||||||
|
<button class="profile-button" @click.stop="showUserMenu = !showUserMenu">
|
||||||
|
<PersonCircleOutline />
|
||||||
|
<span>管理员</span>
|
||||||
|
</button>
|
||||||
|
<div v-if="showUserMenu" class="floating-menu floating-menu--right">
|
||||||
|
<button class="floating-menu__item" @click="logout">
|
||||||
|
<LogOutOutline /> 退出登录
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<main class="app-content">
|
||||||
<RouterView />
|
<RouterView />
|
||||||
</n-layout-content>
|
</main>
|
||||||
</n-layout>
|
</div>
|
||||||
</n-layout>
|
|
||||||
<RouterView v-else />
|
<GlassModal :show="showUpdateModal" title="服务端更新" width="560px" @close="showUpdateModal = false">
|
||||||
</n-message-provider>
|
<div v-if="updateInfo" class="update-grid">
|
||||||
</n-dialog-provider>
|
<div><span>当前版本</span><strong>{{ updateInfo.current }}</strong></div>
|
||||||
</n-config-provider>
|
<div><span>最新版本</span><strong>{{ updateInfo.latest }}</strong></div>
|
||||||
|
<div><span>文件名</span><strong>{{ updateInfo.asset_name || '未提供' }}</strong></div>
|
||||||
|
<div><span>文件大小</span><strong>{{ formatBytes(updateInfo.asset_size) }}</strong></div>
|
||||||
|
</div>
|
||||||
|
<div v-if="updateInfo?.release_note" class="release-note">{{ updateInfo.release_note }}</div>
|
||||||
|
<template #footer>
|
||||||
|
<button class="glass-btn" @click="showUpdateModal = false">关闭</button>
|
||||||
|
<button v-if="updateInfo?.available" class="glass-btn primary" :disabled="updatingServer" @click="handleApplyServerUpdate">
|
||||||
|
{{ updatingServer ? '升级中...' : '立即升级' }}
|
||||||
|
</button>
|
||||||
|
</template>
|
||||||
|
</GlassModal>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.main-layout {
|
.app-shell {
|
||||||
height: 100vh;
|
min-height: 100vh;
|
||||||
}
|
display: grid;
|
||||||
|
grid-template-columns: 260px minmax(0, 1fr);
|
||||||
.logo-container {
|
gap: 20px;
|
||||||
height: 64px;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
gap: 12px;
|
|
||||||
border-bottom: 1px solid #efeff5;
|
|
||||||
overflow: hidden;
|
|
||||||
}
|
|
||||||
|
|
||||||
.logo-text {
|
|
||||||
font-size: 20px;
|
|
||||||
font-weight: 700;
|
|
||||||
color: #18a058;
|
|
||||||
white-space: nowrap;
|
|
||||||
}
|
|
||||||
|
|
||||||
.header {
|
|
||||||
height: 64px;
|
|
||||||
background: white;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
padding: 0 24px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.header-content {
|
|
||||||
width: 100%;
|
|
||||||
display: flex;
|
|
||||||
justify-content: space-between;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.server-status-card {
|
|
||||||
position: absolute;
|
|
||||||
bottom: 0;
|
|
||||||
width: 100%;
|
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
background: #f0fdf4;
|
|
||||||
border-top: 1px solid #d1fae5;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.status-item {
|
.app-sidebar,
|
||||||
|
.app-topbar {
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.app-sidebar {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
flex-direction: column;
|
||||||
margin-bottom: 8px;
|
gap: 18px;
|
||||||
|
position: sticky;
|
||||||
|
top: 20px;
|
||||||
|
height: calc(100vh - 40px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand-block {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand-mark {
|
||||||
|
display: grid;
|
||||||
|
place-items: center;
|
||||||
|
width: 44px;
|
||||||
|
height: 44px;
|
||||||
|
border-radius: 14px;
|
||||||
|
background: var(--gradient-accent);
|
||||||
|
color: white;
|
||||||
|
font-weight: 700;
|
||||||
|
box-shadow: 0 8px 20px var(--color-accent-glow);
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand-block strong {
|
||||||
|
color: var(--color-text-primary);
|
||||||
|
font-size: 18px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand-block p,
|
||||||
|
.sidebar-card p,
|
||||||
|
.topbar-label {
|
||||||
|
color: var(--color-text-secondary);
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar-nav {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-link {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 12px;
|
||||||
|
padding: 12px 14px;
|
||||||
|
border-radius: 14px;
|
||||||
|
text-decoration: none;
|
||||||
|
color: var(--color-text-secondary);
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-link:hover,
|
||||||
|
.nav-link.active {
|
||||||
|
color: var(--color-text-primary);
|
||||||
|
background: var(--glass-bg-light);
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-link.active {
|
||||||
|
box-shadow: inset 0 0 0 1px rgba(59, 130, 246, 0.18);
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-link__icon {
|
||||||
|
width: 18px;
|
||||||
|
height: 18px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar-card {
|
||||||
|
padding: 18px;
|
||||||
|
border-radius: 18px;
|
||||||
|
background: var(--glass-bg-light);
|
||||||
|
border: 1px solid var(--color-border-light);
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar-card__label {
|
||||||
|
display: block;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
color: var(--color-text-muted);
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.status-item .label {
|
.sidebar-card strong {
|
||||||
color: #64748b;
|
display: block;
|
||||||
|
color: var(--color-text-primary);
|
||||||
|
font-size: 16px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.status-item .value {
|
.update-card {
|
||||||
font-weight: 600;
|
margin-top: auto;
|
||||||
color: #0f172a;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
.mobile-toggle {
|
.app-main {
|
||||||
display: none;
|
min-width: 0;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.app-topbar {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.app-topbar h1 {
|
||||||
|
margin: 6px 0 0;
|
||||||
|
font-size: 24px;
|
||||||
|
color: var(--color-text-primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.topbar-actions {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.topbar-icon-btn,
|
||||||
|
.profile-button {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
height: 42px;
|
||||||
|
padding: 0 14px;
|
||||||
|
border-radius: 12px;
|
||||||
|
border: 1px solid var(--color-border);
|
||||||
|
background: var(--glass-bg-light);
|
||||||
|
color: var(--color-text-primary);
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.topbar-icon-btn svg,
|
||||||
|
.profile-button svg,
|
||||||
|
.floating-menu__item svg {
|
||||||
|
width: 18px;
|
||||||
|
height: 18px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.menu-wrap {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.floating-menu {
|
||||||
|
position: absolute;
|
||||||
|
top: calc(100% + 10px);
|
||||||
|
left: 0;
|
||||||
|
min-width: 168px;
|
||||||
|
padding: 8px;
|
||||||
|
border-radius: 16px;
|
||||||
|
background: var(--glass-bg);
|
||||||
|
border: 1px solid var(--color-border);
|
||||||
|
box-shadow: var(--shadow-lg);
|
||||||
|
z-index: 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
.floating-menu--right {
|
||||||
|
right: 0;
|
||||||
|
left: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.floating-menu__item {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 10px;
|
||||||
|
width: 100%;
|
||||||
|
padding: 10px 12px;
|
||||||
|
border: none;
|
||||||
|
border-radius: 12px;
|
||||||
|
background: transparent;
|
||||||
|
color: var(--color-text-primary);
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.floating-menu__item.active,
|
||||||
|
.floating-menu__item:hover {
|
||||||
|
background: var(--glass-bg-light);
|
||||||
|
}
|
||||||
|
|
||||||
|
.app-content {
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.update-grid {
|
||||||
|
display: grid;
|
||||||
|
gap: 12px;
|
||||||
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||||
|
}
|
||||||
|
|
||||||
|
.update-grid div {
|
||||||
|
padding: 14px;
|
||||||
|
border-radius: 14px;
|
||||||
|
background: var(--glass-bg-light);
|
||||||
|
border: 1px solid var(--color-border-light);
|
||||||
|
}
|
||||||
|
|
||||||
|
.update-grid span {
|
||||||
|
display: block;
|
||||||
|
margin-bottom: 8px;
|
||||||
|
color: var(--color-text-secondary);
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.update-grid strong {
|
||||||
|
color: var(--color-text-primary);
|
||||||
|
word-break: break-word;
|
||||||
|
}
|
||||||
|
|
||||||
|
.release-note {
|
||||||
|
margin-top: 16px;
|
||||||
|
padding: 14px;
|
||||||
|
border-radius: 14px;
|
||||||
|
background: var(--glass-bg-light);
|
||||||
|
border: 1px solid var(--color-border-light);
|
||||||
|
color: var(--color-text-secondary);
|
||||||
|
white-space: pre-wrap;
|
||||||
|
line-height: 1.7;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 1080px) {
|
||||||
|
.app-shell {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}
|
||||||
|
|
||||||
|
.app-sidebar {
|
||||||
|
position: static;
|
||||||
|
height: auto;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (max-width: 768px) {
|
@media (max-width: 768px) {
|
||||||
.mobile-toggle {
|
.app-shell {
|
||||||
display: inline-flex;
|
padding: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.app-sidebar,
|
||||||
|
.app-topbar {
|
||||||
|
padding: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.app-topbar {
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: flex-start;
|
||||||
|
}
|
||||||
|
|
||||||
|
.topbar-actions {
|
||||||
|
width: 100%;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.profile-button {
|
||||||
|
flex: 1;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.update-grid {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { get, post, put, del, getToken } from '../config/axios'
|
import { get, post, put, del, getToken } from '../config/axios'
|
||||||
import type { ClientConfig, ClientStatus, ClientDetail, ServerStatus, PluginInfo, StorePluginInfo, PluginConfigResponse, JSPlugin, RuleSchemasMap, LogEntry, LogStreamOptions, ConfigField } from '../types'
|
import type { ClientConfig, ClientStatus, ClientDetail, ServerStatus, LogEntry, LogStreamOptions, InstallCommandResponse } from '../types'
|
||||||
|
|
||||||
// 重新导出 token 管理方法
|
// 重新导出 token 管理方法
|
||||||
export { getToken, setToken, removeToken } from '../config/axios'
|
export { getToken, setToken, removeToken } from '../config/axios'
|
||||||
@@ -24,91 +24,6 @@ export const reloadConfig = () => post('/config/reload')
|
|||||||
export const pushConfigToClient = (id: string) => post(`/client/${id}/push`)
|
export const pushConfigToClient = (id: string) => post(`/client/${id}/push`)
|
||||||
export const disconnectClient = (id: string) => post(`/client/${id}/disconnect`)
|
export const disconnectClient = (id: string) => post(`/client/${id}/disconnect`)
|
||||||
export const restartClient = (id: string) => post(`/client/${id}/restart`)
|
export const restartClient = (id: string) => post(`/client/${id}/restart`)
|
||||||
export const installPluginsToClient = (id: string, plugins: string[]) =>
|
|
||||||
post(`/client/${id}/install-plugins`, { plugins })
|
|
||||||
|
|
||||||
// 规则配置模式
|
|
||||||
export const getRuleSchemas = () => get<RuleSchemasMap>('/rule-schemas')
|
|
||||||
|
|
||||||
// 客户端插件控制(使用 pluginID)
|
|
||||||
export const startClientPlugin = (clientId: string, pluginId: string, ruleName: string) =>
|
|
||||||
post(`/client/${clientId}/plugin/${pluginId}/start`, { rule_name: ruleName })
|
|
||||||
export const stopClientPlugin = (clientId: string, pluginId: string, ruleName: string) =>
|
|
||||||
post(`/client/${clientId}/plugin/${pluginId}/stop`, { rule_name: ruleName })
|
|
||||||
export const restartClientPlugin = (clientId: string, pluginId: string, ruleName: string) =>
|
|
||||||
post(`/client/${clientId}/plugin/${pluginId}/restart`, { rule_name: ruleName })
|
|
||||||
export const deleteClientPlugin = (clientId: string, pluginId: string) =>
|
|
||||||
post(`/client/${clientId}/plugin/${pluginId}/delete`)
|
|
||||||
export const updateClientPluginConfigWithRestart = (clientId: string, pluginId: string, ruleName: string, config: Record<string, string>, restart: boolean) =>
|
|
||||||
post(`/client/${clientId}/plugin/${pluginId}/config`, { rule_name: ruleName, config, restart })
|
|
||||||
|
|
||||||
// 插件管理
|
|
||||||
export const getPlugins = () => get<PluginInfo[]>('/plugins')
|
|
||||||
export const enablePlugin = (name: string) => post(`/plugin/${name}/enable`)
|
|
||||||
export const disablePlugin = (name: string) => post(`/plugin/${name}/disable`)
|
|
||||||
|
|
||||||
// 扩展商店
|
|
||||||
export const getStorePlugins = () => get<{ plugins: StorePluginInfo[] }>('/store/plugins')
|
|
||||||
export const installStorePlugin = (
|
|
||||||
pluginName: string,
|
|
||||||
downloadUrl: string,
|
|
||||||
signatureUrl: string,
|
|
||||||
clientId: string,
|
|
||||||
remotePort?: number,
|
|
||||||
version?: string,
|
|
||||||
configSchema?: ConfigField[],
|
|
||||||
authEnabled?: boolean,
|
|
||||||
authUsername?: string,
|
|
||||||
authPassword?: string
|
|
||||||
) =>
|
|
||||||
post('/store/install', {
|
|
||||||
plugin_name: pluginName,
|
|
||||||
version: version || '',
|
|
||||||
download_url: downloadUrl,
|
|
||||||
signature_url: signatureUrl,
|
|
||||||
client_id: clientId,
|
|
||||||
remote_port: remotePort || 0,
|
|
||||||
config_schema: configSchema || [],
|
|
||||||
auth_enabled: authEnabled || false,
|
|
||||||
auth_username: authUsername || '',
|
|
||||||
auth_password: authPassword || ''
|
|
||||||
})
|
|
||||||
|
|
||||||
// 客户端插件配置
|
|
||||||
export const getClientPluginConfig = (clientId: string, pluginName: string) =>
|
|
||||||
get<PluginConfigResponse>(`/client-plugin/${clientId}/${pluginName}/config`)
|
|
||||||
export const updateClientPluginConfig = (clientId: string, pluginName: string, config: Record<string, string>) =>
|
|
||||||
put(`/client-plugin/${clientId}/${pluginName}/config`, { config })
|
|
||||||
|
|
||||||
// JS 插件管理
|
|
||||||
export const getJSPlugins = () => get<JSPlugin[]>('/js-plugins')
|
|
||||||
export const createJSPlugin = (plugin: JSPlugin) => post('/js-plugins', plugin)
|
|
||||||
export const getJSPlugin = (name: string) => get<JSPlugin>(`/js-plugin/${name}`)
|
|
||||||
export const updateJSPlugin = (name: string, plugin: JSPlugin) => put(`/js-plugin/${name}`, plugin)
|
|
||||||
export const deleteJSPlugin = (name: string) => del(`/js-plugin/${name}`)
|
|
||||||
export const pushJSPluginToClient = (pluginName: string, clientId: string, remotePort?: number) =>
|
|
||||||
post(`/js-plugin/${pluginName}/push/${clientId}`, { remote_port: remotePort || 0 })
|
|
||||||
export const updateJSPluginConfig = (name: string, config: Record<string, string>) =>
|
|
||||||
put(`/js-plugin/${name}/config`, { config })
|
|
||||||
export const setJSPluginEnabled = (name: string, enabled: boolean) =>
|
|
||||||
post(`/js-plugin/${name}/${enabled ? 'enable' : 'disable'}`)
|
|
||||||
|
|
||||||
// 插件 API 代理(通过 pluginID 调用插件自定义 API)
|
|
||||||
export const callPluginAPI = <T = any>(clientId: string, pluginId: string, method: string, route: string, body?: any) => {
|
|
||||||
const path = `/client/${clientId}/plugin-api/${pluginId}${route.startsWith('/') ? route : '/' + route}`
|
|
||||||
switch (method.toUpperCase()) {
|
|
||||||
case 'GET':
|
|
||||||
return get<T>(path)
|
|
||||||
case 'POST':
|
|
||||||
return post<T>(path, body)
|
|
||||||
case 'PUT':
|
|
||||||
return put<T>(path, body)
|
|
||||||
case 'DELETE':
|
|
||||||
return del<T>(path)
|
|
||||||
default:
|
|
||||||
return get<T>(path)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 更新管理
|
// 更新管理
|
||||||
export interface UpdateInfo {
|
export interface UpdateInfo {
|
||||||
@@ -180,3 +95,86 @@ export const createLogStream = (
|
|||||||
|
|
||||||
return eventSource
|
return eventSource
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 流量统计
|
||||||
|
export interface TrafficStats {
|
||||||
|
traffic_24h: { inbound: number; outbound: number }
|
||||||
|
traffic_total: { inbound: number; outbound: number }
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface TrafficRecord {
|
||||||
|
timestamp: number
|
||||||
|
inbound: number
|
||||||
|
outbound: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getTrafficStats = () => get<TrafficStats>('/traffic/stats')
|
||||||
|
export const getTrafficHourly = () => get<{ records: TrafficRecord[] }>('/traffic/hourly')
|
||||||
|
|
||||||
|
// 客户端系统状态
|
||||||
|
export interface SystemStats {
|
||||||
|
cpu_usage: number
|
||||||
|
memory_total: number
|
||||||
|
memory_used: number
|
||||||
|
memory_usage: number
|
||||||
|
disk_total: number
|
||||||
|
disk_used: number
|
||||||
|
disk_usage: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getClientSystemStats = (clientId: string) => get<SystemStats>(`/client/${clientId}/system-stats`)
|
||||||
|
|
||||||
|
// 客户端截图
|
||||||
|
export interface ScreenshotData {
|
||||||
|
data: string // Base64 JPEG
|
||||||
|
width: number
|
||||||
|
height: number
|
||||||
|
timestamp: number
|
||||||
|
error?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getClientScreenshot = (clientId: string, quality?: number) =>
|
||||||
|
get<ScreenshotData>(`/client/${clientId}/screenshot${quality ? '?quality=' + quality : ''}`)
|
||||||
|
|
||||||
|
// Shell 执行
|
||||||
|
export interface ShellResult {
|
||||||
|
output: string
|
||||||
|
exit_code: number
|
||||||
|
error?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export const executeClientShell = (clientId: string, command: string, timeout?: number) =>
|
||||||
|
post<ShellResult>(`/client/${clientId}/shell`, { command, timeout: timeout || 30 })
|
||||||
|
|
||||||
|
// 服务器配置
|
||||||
|
export interface ServerConfigInfo {
|
||||||
|
bind_addr: string
|
||||||
|
bind_port: number
|
||||||
|
token: string
|
||||||
|
heartbeat_sec: number
|
||||||
|
heartbeat_timeout: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface WebConfigInfo {
|
||||||
|
enabled: boolean
|
||||||
|
bind_port: number
|
||||||
|
username: string
|
||||||
|
password: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ServerConfigResponse {
|
||||||
|
server: ServerConfigInfo
|
||||||
|
web: WebConfigInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface UpdateServerConfigRequest {
|
||||||
|
server?: Partial<ServerConfigInfo>
|
||||||
|
web?: Partial<WebConfigInfo>
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getServerConfig = () => get<ServerConfigResponse>('/config')
|
||||||
|
export const updateServerConfig = (config: UpdateServerConfigRequest) => put('/config', config)
|
||||||
|
|
||||||
|
// 安装命令生成
|
||||||
|
export const generateInstallCommand = () =>
|
||||||
|
post<InstallCommandResponse>('/install/generate')
|
||||||
|
|||||||
128
web/src/components/GlassModal.vue
Normal file
128
web/src/components/GlassModal.vue
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { CloseOutline } from '@vicons/ionicons5'
|
||||||
|
|
||||||
|
defineProps<{
|
||||||
|
show: boolean
|
||||||
|
title: string
|
||||||
|
width?: string
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
(e: 'close'): void
|
||||||
|
}>()
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Teleport to="body">
|
||||||
|
<div v-if="show" class="modal-overlay" @click.self="emit('close')">
|
||||||
|
<div class="modal-container" :style="{ maxWidth: width || '500px' }">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h3>{{ title }}</h3>
|
||||||
|
<button class="close-btn" @click="emit('close')">
|
||||||
|
<CloseOutline />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<slot />
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<slot name="footer" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Teleport>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.modal-overlay {
|
||||||
|
position: fixed;
|
||||||
|
inset: 0;
|
||||||
|
background: rgba(0, 0, 0, 0.6);
|
||||||
|
backdrop-filter: blur(4px);
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
z-index: 1000;
|
||||||
|
padding: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal-container {
|
||||||
|
width: 100%;
|
||||||
|
background: var(--glass-bg);
|
||||||
|
backdrop-filter: var(--glass-blur);
|
||||||
|
-webkit-backdrop-filter: var(--glass-blur);
|
||||||
|
border-radius: 16px;
|
||||||
|
border: 1px solid var(--color-border);
|
||||||
|
overflow: hidden;
|
||||||
|
box-shadow: var(--shadow-lg), var(--shadow-glow);
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 顶部高光 */
|
||||||
|
.modal-container::before {
|
||||||
|
content: '';
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 15%;
|
||||||
|
right: 15%;
|
||||||
|
height: 1px;
|
||||||
|
background: linear-gradient(90deg,
|
||||||
|
transparent 0%,
|
||||||
|
rgba(255, 255, 255, 0.15) 50%,
|
||||||
|
transparent 100%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal-header {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
padding: 16px 20px;
|
||||||
|
border-bottom: 1px solid var(--color-border-light);
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal-header h3 {
|
||||||
|
margin: 0;
|
||||||
|
font-size: 16px;
|
||||||
|
font-weight: 600;
|
||||||
|
color: var(--color-text-primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.close-btn {
|
||||||
|
background: var(--glass-bg-light);
|
||||||
|
border: none;
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 6px;
|
||||||
|
color: var(--color-text-secondary);
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.close-btn:hover {
|
||||||
|
background: rgba(239, 68, 68, 0.15);
|
||||||
|
color: var(--color-error);
|
||||||
|
}
|
||||||
|
|
||||||
|
.close-btn svg {
|
||||||
|
width: 18px;
|
||||||
|
height: 18px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal-body {
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal-footer {
|
||||||
|
padding: 16px 20px;
|
||||||
|
border-top: 1px solid var(--color-border-light);
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-end;
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal-footer:empty {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
85
web/src/components/GlassSwitch.vue
Normal file
85
web/src/components/GlassSwitch.vue
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
const props = defineProps<{
|
||||||
|
modelValue?: boolean
|
||||||
|
size?: 'small' | 'medium'
|
||||||
|
disabled?: boolean
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
(e: 'update:modelValue', value: boolean): void
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const toggle = () => {
|
||||||
|
if (!props.disabled) {
|
||||||
|
emit('update:modelValue', !props.modelValue)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<button
|
||||||
|
class="glass-switch"
|
||||||
|
:class="[size || 'small', { active: modelValue, disabled }]"
|
||||||
|
@click="toggle"
|
||||||
|
:disabled="disabled"
|
||||||
|
>
|
||||||
|
<span class="switch-thumb"></span>
|
||||||
|
</button>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.glass-switch {
|
||||||
|
position: relative;
|
||||||
|
width: 36px;
|
||||||
|
height: 20px;
|
||||||
|
background: rgba(255, 255, 255, 0.15);
|
||||||
|
border: none;
|
||||||
|
border-radius: 10px;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.2s;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.glass-switch.small {
|
||||||
|
width: 32px;
|
||||||
|
height: 18px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.glass-switch:hover:not(.disabled) {
|
||||||
|
background: rgba(255, 255, 255, 0.25);
|
||||||
|
}
|
||||||
|
|
||||||
|
.glass-switch.active {
|
||||||
|
background: linear-gradient(135deg, #60a5fa 0%, #a78bfa 100%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.glass-switch.disabled {
|
||||||
|
opacity: 0.5;
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
.switch-thumb {
|
||||||
|
position: absolute;
|
||||||
|
top: 2px;
|
||||||
|
left: 2px;
|
||||||
|
width: 14px;
|
||||||
|
height: 14px;
|
||||||
|
background: white;
|
||||||
|
border-radius: 50%;
|
||||||
|
transition: transform 0.2s;
|
||||||
|
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.glass-switch.small .switch-thumb {
|
||||||
|
width: 12px;
|
||||||
|
height: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.glass-switch.active .switch-thumb {
|
||||||
|
transform: translateX(16px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.glass-switch.small.active .switch-thumb {
|
||||||
|
transform: translateX(14px);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
60
web/src/components/GlassTag.vue
Normal file
60
web/src/components/GlassTag.vue
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
defineProps<{
|
||||||
|
type?: 'default' | 'success' | 'warning' | 'error' | 'info'
|
||||||
|
size?: 'small' | 'medium'
|
||||||
|
round?: boolean
|
||||||
|
}>()
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<span class="glass-tag" :class="[type || 'default', size || 'small', { round }]">
|
||||||
|
<slot />
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.glass-tag {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
padding: 2px 8px;
|
||||||
|
border-radius: 4px;
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 500;
|
||||||
|
background: rgba(255, 255, 255, 0.1);
|
||||||
|
color: rgba(255, 255, 255, 0.8);
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.15);
|
||||||
|
}
|
||||||
|
|
||||||
|
.glass-tag.round {
|
||||||
|
border-radius: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.glass-tag.medium {
|
||||||
|
padding: 4px 12px;
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.glass-tag.success {
|
||||||
|
background: rgba(52, 211, 153, 0.15);
|
||||||
|
border-color: rgba(52, 211, 153, 0.3);
|
||||||
|
color: #34d399;
|
||||||
|
}
|
||||||
|
|
||||||
|
.glass-tag.warning {
|
||||||
|
background: rgba(251, 191, 36, 0.15);
|
||||||
|
border-color: rgba(251, 191, 36, 0.3);
|
||||||
|
color: #fbbf24;
|
||||||
|
}
|
||||||
|
|
||||||
|
.glass-tag.error {
|
||||||
|
background: rgba(239, 68, 68, 0.15);
|
||||||
|
border-color: rgba(239, 68, 68, 0.3);
|
||||||
|
color: #f87171;
|
||||||
|
}
|
||||||
|
|
||||||
|
.glass-tag.info {
|
||||||
|
background: rgba(96, 165, 250, 0.15);
|
||||||
|
border-color: rgba(96, 165, 250, 0.3);
|
||||||
|
color: #60a5fa;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
300
web/src/components/InlineLogPanel.vue
Normal file
300
web/src/components/InlineLogPanel.vue
Normal file
@@ -0,0 +1,300 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { ref, onMounted, onUnmounted, nextTick } from 'vue'
|
||||||
|
import { PlayOutline, StopOutline, TrashOutline } from '@vicons/ionicons5'
|
||||||
|
import { createLogStream } from '../api'
|
||||||
|
import type { LogEntry } from '../types'
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
clientId: string
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const logs = ref<LogEntry[]>([])
|
||||||
|
const isStreaming = ref(false)
|
||||||
|
const autoScroll = ref(true)
|
||||||
|
const loading = ref(false)
|
||||||
|
|
||||||
|
let eventSource: EventSource | null = null
|
||||||
|
const logContainer = ref<HTMLElement | null>(null)
|
||||||
|
|
||||||
|
const startStream = () => {
|
||||||
|
if (eventSource) {
|
||||||
|
eventSource.close()
|
||||||
|
}
|
||||||
|
|
||||||
|
loading.value = true
|
||||||
|
isStreaming.value = true
|
||||||
|
|
||||||
|
eventSource = createLogStream(
|
||||||
|
props.clientId,
|
||||||
|
{ lines: 100, follow: true, level: '' },
|
||||||
|
(entry) => {
|
||||||
|
logs.value.push(entry)
|
||||||
|
if (logs.value.length > 500) {
|
||||||
|
logs.value = logs.value.slice(-300)
|
||||||
|
}
|
||||||
|
if (autoScroll.value) {
|
||||||
|
nextTick(() => scrollToBottom())
|
||||||
|
}
|
||||||
|
loading.value = false
|
||||||
|
},
|
||||||
|
() => {
|
||||||
|
isStreaming.value = false
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const stopStream = () => {
|
||||||
|
if (eventSource) {
|
||||||
|
eventSource.close()
|
||||||
|
eventSource = null
|
||||||
|
}
|
||||||
|
isStreaming.value = false
|
||||||
|
}
|
||||||
|
|
||||||
|
const clearLogs = () => {
|
||||||
|
logs.value = []
|
||||||
|
}
|
||||||
|
|
||||||
|
const scrollToBottom = () => {
|
||||||
|
if (logContainer.value) {
|
||||||
|
logContainer.value.scrollTop = logContainer.value.scrollHeight
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const getLevelColor = (level: string): string => {
|
||||||
|
switch (level) {
|
||||||
|
case 'error': return '#fca5a5'
|
||||||
|
case 'warn': return '#fcd34d'
|
||||||
|
case 'info': return '#60a5fa'
|
||||||
|
case 'debug': return '#9ca3af'
|
||||||
|
default: return 'rgba(255,255,255,0.7)'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const formatTime = (ts: number): string => {
|
||||||
|
return new Date(ts).toLocaleTimeString('en-US', { hour12: false })
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
startStream()
|
||||||
|
})
|
||||||
|
|
||||||
|
onUnmounted(() => {
|
||||||
|
stopStream()
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="inline-log-panel">
|
||||||
|
<div class="log-toolbar">
|
||||||
|
<div class="toolbar-left">
|
||||||
|
<span class="log-title">实时日志</span>
|
||||||
|
<span v-if="isStreaming" class="streaming-badge">
|
||||||
|
<span class="streaming-dot"></span>
|
||||||
|
实时
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div class="toolbar-right">
|
||||||
|
<button v-if="!isStreaming" class="tool-btn" @click="startStream" title="开始">
|
||||||
|
<PlayOutline class="tool-icon" />
|
||||||
|
</button>
|
||||||
|
<button v-else class="tool-btn" @click="stopStream" title="停止">
|
||||||
|
<StopOutline class="tool-icon" />
|
||||||
|
</button>
|
||||||
|
<button class="tool-btn" @click="clearLogs" title="清空">
|
||||||
|
<TrashOutline class="tool-icon" />
|
||||||
|
</button>
|
||||||
|
<label class="auto-scroll-toggle">
|
||||||
|
<input type="checkbox" v-model="autoScroll" />
|
||||||
|
<span>自动滚动</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div ref="logContainer" class="log-content">
|
||||||
|
<div v-if="loading && logs.length === 0" class="log-loading">
|
||||||
|
连接中...
|
||||||
|
</div>
|
||||||
|
<div v-else-if="logs.length === 0" class="log-empty">
|
||||||
|
暂无日志
|
||||||
|
</div>
|
||||||
|
<div v-else class="log-lines">
|
||||||
|
<div v-for="(log, index) in logs" :key="index" class="log-line">
|
||||||
|
<span class="log-time">{{ formatTime(log.ts) }}</span>
|
||||||
|
<span class="log-level" :style="{ color: getLevelColor(log.level) }">
|
||||||
|
[{{ log.level.toUpperCase() }}]
|
||||||
|
</span>
|
||||||
|
<span class="log-src">[{{ log.src }}]</span>
|
||||||
|
<span class="log-msg">{{ log.msg }}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.inline-log-panel {
|
||||||
|
background: var(--glass-bg);
|
||||||
|
border-radius: 12px;
|
||||||
|
border: 1px solid var(--color-border);
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-toolbar {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
padding: 12px 16px;
|
||||||
|
border-bottom: 1px solid var(--color-border);
|
||||||
|
background: var(--glass-bg-light);
|
||||||
|
}
|
||||||
|
|
||||||
|
.toolbar-left {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-title {
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 600;
|
||||||
|
color: var(--color-text-primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.streaming-badge {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
|
font-size: 11px;
|
||||||
|
color: var(--color-success);
|
||||||
|
background: rgba(16, 185, 129, 0.15);
|
||||||
|
padding: 2px 8px;
|
||||||
|
border-radius: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.streaming-dot {
|
||||||
|
width: 6px;
|
||||||
|
height: 6px;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: var(--color-success);
|
||||||
|
animation: pulse 1.5s ease-in-out infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes pulse {
|
||||||
|
0%, 100% { opacity: 1; }
|
||||||
|
50% { opacity: 0.4; }
|
||||||
|
}
|
||||||
|
|
||||||
|
.toolbar-right {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tool-btn {
|
||||||
|
background: var(--color-border);
|
||||||
|
border: none;
|
||||||
|
border-radius: 6px;
|
||||||
|
padding: 6px;
|
||||||
|
color: var(--color-text-secondary);
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.2s;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tool-btn:hover {
|
||||||
|
background: var(--color-bg-elevated);
|
||||||
|
color: var(--color-text-primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.tool-icon {
|
||||||
|
width: 16px;
|
||||||
|
height: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.auto-scroll-toggle {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
|
font-size: 12px;
|
||||||
|
color: var(--color-text-secondary);
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.auto-scroll-toggle input {
|
||||||
|
width: 14px;
|
||||||
|
height: 14px;
|
||||||
|
accent-color: var(--color-accent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-content {
|
||||||
|
height: 200px;
|
||||||
|
overflow-y: auto;
|
||||||
|
font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
|
||||||
|
font-size: 12px;
|
||||||
|
line-height: 1.6;
|
||||||
|
background: var(--color-bg-elevated);
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-loading,
|
||||||
|
.log-empty {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
height: 100%;
|
||||||
|
color: var(--color-text-muted);
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-lines {
|
||||||
|
padding: 8px 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-line {
|
||||||
|
display: flex;
|
||||||
|
gap: 8px;
|
||||||
|
padding: 2px 0;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-time {
|
||||||
|
color: var(--color-text-muted);
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-level {
|
||||||
|
flex-shrink: 0;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-src {
|
||||||
|
color: var(--color-text-muted);
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-msg {
|
||||||
|
color: var(--color-text-secondary);
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Scrollbar */
|
||||||
|
.log-content::-webkit-scrollbar {
|
||||||
|
width: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-content::-webkit-scrollbar-track {
|
||||||
|
background: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-content::-webkit-scrollbar-thumb {
|
||||||
|
background: var(--color-border);
|
||||||
|
border-radius: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-content::-webkit-scrollbar-thumb:hover {
|
||||||
|
background: var(--color-text-muted);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, computed, onMounted, onUnmounted, watch, nextTick } from 'vue'
|
import { ref, computed, onMounted, onUnmounted, watch, nextTick } from 'vue'
|
||||||
import { NCard, NSpace, NButton, NSelect, NSwitch, NInput, NIcon, NEmpty, NSpin } from 'naive-ui'
|
import {
|
||||||
import { PlayOutline, StopOutline, TrashOutline, DownloadOutline } from '@vicons/ionicons5'
|
PlayOutline, StopOutline, TrashOutline, DownloadOutline, CloseOutline
|
||||||
|
} from '@vicons/ionicons5'
|
||||||
import { createLogStream } from '../api'
|
import { createLogStream } from '../api'
|
||||||
import type { LogEntry } from '../types'
|
import type { LogEntry } from '../types'
|
||||||
|
|
||||||
@@ -24,14 +25,6 @@ const loading = ref(false)
|
|||||||
let eventSource: EventSource | null = null
|
let eventSource: EventSource | null = null
|
||||||
const logContainer = ref<HTMLElement | null>(null)
|
const logContainer = ref<HTMLElement | null>(null)
|
||||||
|
|
||||||
const levelOptions = [
|
|
||||||
{ label: '所有级别', value: '' },
|
|
||||||
{ label: 'Info', value: 'info' },
|
|
||||||
{ label: 'Warning', value: 'warn' },
|
|
||||||
{ label: 'Error', value: 'error' },
|
|
||||||
{ label: 'Debug', value: 'debug' }
|
|
||||||
]
|
|
||||||
|
|
||||||
const startStream = () => {
|
const startStream = () => {
|
||||||
if (eventSource) {
|
if (eventSource) {
|
||||||
eventSource.close()
|
eventSource.close()
|
||||||
@@ -133,100 +126,354 @@ onUnmounted(() => {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<n-card title="客户端日志" :closable="true" @close="emit('close')">
|
<div v-if="visible" class="log-overlay" @click.self="emit('close')">
|
||||||
<template #header-extra>
|
<div class="log-modal">
|
||||||
<n-space :size="8">
|
<!-- Header -->
|
||||||
<n-select
|
<div class="log-header">
|
||||||
v-model:value="levelFilter"
|
<h3>客户端日志</h3>
|
||||||
:options="levelOptions"
|
<div class="log-controls">
|
||||||
size="small"
|
<select v-model="levelFilter" class="log-select" @change="() => { stopStream(); logs = []; startStream(); }">
|
||||||
style="width: 110px;"
|
<option value="">所有级别</option>
|
||||||
@update:value="() => { stopStream(); logs = []; startStream(); }"
|
<option value="info">Info</option>
|
||||||
/>
|
<option value="warn">Warning</option>
|
||||||
<n-input
|
<option value="error">Error</option>
|
||||||
v-model:value="searchText"
|
<option value="debug">Debug</option>
|
||||||
placeholder="搜索..."
|
</select>
|
||||||
size="small"
|
<input v-model="searchText" type="text" class="log-input" placeholder="搜索..." />
|
||||||
style="width: 120px;"
|
<label class="log-toggle">
|
||||||
clearable
|
<input type="checkbox" v-model="autoScroll" />
|
||||||
/>
|
<span>自动滚动</span>
|
||||||
<n-switch v-model:value="autoScroll" size="small">
|
</label>
|
||||||
<template #checked>自动滚动</template>
|
<button class="icon-btn" @click="clearLogs" title="清空">
|
||||||
<template #unchecked>手动</template>
|
<TrashOutline />
|
||||||
</n-switch>
|
</button>
|
||||||
<n-button size="small" quaternary @click="clearLogs">
|
<button class="icon-btn" @click="downloadLogs" title="下载">
|
||||||
<template #icon><n-icon><TrashOutline /></n-icon></template>
|
<DownloadOutline />
|
||||||
</n-button>
|
</button>
|
||||||
<n-button size="small" quaternary @click="downloadLogs">
|
<button class="action-btn" :class="isStreaming ? 'danger' : 'success'" @click="isStreaming ? stopStream() : startStream()">
|
||||||
<template #icon><n-icon><DownloadOutline /></n-icon></template>
|
<StopOutline v-if="isStreaming" />
|
||||||
</n-button>
|
<PlayOutline v-else />
|
||||||
<n-button
|
<span>{{ isStreaming ? '停止' : '开始' }}</span>
|
||||||
size="small"
|
</button>
|
||||||
:type="isStreaming ? 'error' : 'success'"
|
</div>
|
||||||
@click="isStreaming ? stopStream() : startStream()"
|
<button class="close-btn" @click="emit('close')">
|
||||||
>
|
<CloseOutline />
|
||||||
<template #icon>
|
</button>
|
||||||
<n-icon><StopOutline v-if="isStreaming" /><PlayOutline v-else /></n-icon>
|
</div>
|
||||||
</template>
|
|
||||||
{{ isStreaming ? '停止' : '开始' }}
|
|
||||||
</n-button>
|
|
||||||
</n-space>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<n-spin :show="loading && logs.length === 0">
|
<!-- Content -->
|
||||||
<div
|
<div class="log-body">
|
||||||
ref="logContainer"
|
<div v-if="loading && logs.length === 0" class="log-loading">加载中...</div>
|
||||||
class="log-container"
|
<div ref="logContainer" class="log-container">
|
||||||
>
|
<div v-if="filteredLogs.length === 0" class="log-empty">暂无日志</div>
|
||||||
<n-empty v-if="filteredLogs.length === 0" description="暂无日志" />
|
<div v-for="(log, i) in filteredLogs" :key="i" class="log-line">
|
||||||
<div
|
|
||||||
v-for="(log, i) in filteredLogs"
|
|
||||||
:key="i"
|
|
||||||
class="log-line"
|
|
||||||
>
|
|
||||||
<span class="log-time">{{ formatTime(log.ts) }}</span>
|
<span class="log-time">{{ formatTime(log.ts) }}</span>
|
||||||
<span class="log-level" :style="{ color: getLevelColor(log.level) }">[{{ log.level.toUpperCase() }}]</span>
|
<span class="log-level" :style="{ color: getLevelColor(log.level) }">[{{ log.level.toUpperCase() }}]</span>
|
||||||
<span class="log-src">[{{ log.src }}]</span>
|
<span class="log-src">[{{ log.src }}]</span>
|
||||||
<span class="log-msg">{{ log.msg }}</span>
|
<span class="log-msg">{{ log.msg }}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</n-spin>
|
</div>
|
||||||
</n-card>
|
</div>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.log-container {
|
/* Overlay */
|
||||||
height: 400px;
|
.log-overlay {
|
||||||
overflow-y: auto;
|
position: fixed;
|
||||||
background: #1e1e1e;
|
inset: 0;
|
||||||
padding: 8px;
|
background: rgba(0, 0, 0, 0.6);
|
||||||
font-family: 'Consolas', 'Monaco', monospace;
|
backdrop-filter: blur(4px);
|
||||||
font-size: 12px;
|
display: flex;
|
||||||
border-radius: 4px;
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
z-index: 1000;
|
||||||
|
padding: 24px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Modal */
|
||||||
|
.log-modal {
|
||||||
|
width: 100%;
|
||||||
|
max-width: 900px;
|
||||||
|
max-height: 80vh;
|
||||||
|
background: rgba(30, 27, 75, 0.95);
|
||||||
|
backdrop-filter: blur(20px);
|
||||||
|
-webkit-backdrop-filter: blur(20px);
|
||||||
|
border-radius: 16px;
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.12);
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Header */
|
||||||
|
.log-header {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 16px;
|
||||||
|
padding: 16px 20px;
|
||||||
|
border-bottom: 1px solid rgba(255, 255, 255, 0.08);
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-header h3 {
|
||||||
|
margin: 0;
|
||||||
|
font-size: 16px;
|
||||||
|
font-weight: 600;
|
||||||
|
color: white;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-controls {
|
||||||
|
flex: 1;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 12px;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Select */
|
||||||
|
.log-select {
|
||||||
|
background: rgba(255, 255, 255, 0.1);
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.15);
|
||||||
|
border-radius: 6px;
|
||||||
|
padding: 6px 12px;
|
||||||
|
color: white;
|
||||||
|
font-size: 13px;
|
||||||
|
cursor: pointer;
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-select option {
|
||||||
|
background: #1e1b4b;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Input */
|
||||||
|
.log-input {
|
||||||
|
background: rgba(255, 255, 255, 0.1);
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.15);
|
||||||
|
border-radius: 6px;
|
||||||
|
padding: 6px 12px;
|
||||||
|
color: white;
|
||||||
|
font-size: 13px;
|
||||||
|
width: 150px;
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-input::placeholder {
|
||||||
|
color: rgba(255, 255, 255, 0.4);
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-input:focus {
|
||||||
|
border-color: rgba(167, 139, 250, 0.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Toggle */
|
||||||
|
.log-toggle {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
|
color: rgba(255, 255, 255, 0.7);
|
||||||
|
font-size: 13px;
|
||||||
|
cursor: pointer;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-toggle input[type="checkbox"] {
|
||||||
|
width: 16px;
|
||||||
|
height: 16px;
|
||||||
|
accent-color: #a78bfa;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Icon Button */
|
||||||
|
.icon-btn {
|
||||||
|
background: rgba(255, 255, 255, 0.1);
|
||||||
|
border: none;
|
||||||
|
border-radius: 6px;
|
||||||
|
padding: 6px;
|
||||||
|
color: rgba(255, 255, 255, 0.7);
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.2s;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-btn:hover {
|
||||||
|
background: rgba(255, 255, 255, 0.2);
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-btn svg {
|
||||||
|
width: 18px;
|
||||||
|
height: 18px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Action Button */
|
||||||
|
.action-btn {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
|
background: rgba(255, 255, 255, 0.1);
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.15);
|
||||||
|
border-radius: 6px;
|
||||||
|
padding: 6px 12px;
|
||||||
|
color: white;
|
||||||
|
font-size: 13px;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.action-btn:hover {
|
||||||
|
background: rgba(255, 255, 255, 0.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.action-btn svg {
|
||||||
|
width: 16px;
|
||||||
|
height: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.action-btn.success {
|
||||||
|
background: rgba(52, 211, 153, 0.2);
|
||||||
|
border-color: rgba(52, 211, 153, 0.3);
|
||||||
|
color: #34d399;
|
||||||
|
}
|
||||||
|
|
||||||
|
.action-btn.danger {
|
||||||
|
background: rgba(239, 68, 68, 0.2);
|
||||||
|
border-color: rgba(239, 68, 68, 0.3);
|
||||||
|
color: #fca5a5;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Close Button */
|
||||||
|
.close-btn {
|
||||||
|
background: rgba(255, 255, 255, 0.1);
|
||||||
|
border: none;
|
||||||
|
border-radius: 6px;
|
||||||
|
padding: 6px;
|
||||||
|
color: rgba(255, 255, 255, 0.6);
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.2s;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
margin-left: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.close-btn:hover {
|
||||||
|
background: rgba(239, 68, 68, 0.2);
|
||||||
|
color: #fca5a5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.close-btn svg {
|
||||||
|
width: 20px;
|
||||||
|
height: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Body */
|
||||||
|
.log-body {
|
||||||
|
flex: 1;
|
||||||
|
padding: 16px;
|
||||||
|
overflow: hidden;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-loading {
|
||||||
|
text-align: center;
|
||||||
|
padding: 32px;
|
||||||
|
color: rgba(255, 255, 255, 0.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Container */
|
||||||
|
.log-container {
|
||||||
|
flex: 1;
|
||||||
|
height: 400px;
|
||||||
|
overflow-y: auto;
|
||||||
|
background: rgba(0, 0, 0, 0.3);
|
||||||
|
padding: 12px;
|
||||||
|
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
||||||
|
font-size: 12px;
|
||||||
|
border-radius: 8px;
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.05);
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-empty {
|
||||||
|
text-align: center;
|
||||||
|
padding: 48px;
|
||||||
|
color: rgba(255, 255, 255, 0.4);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Log Line */
|
||||||
.log-line {
|
.log-line {
|
||||||
line-height: 1.6;
|
line-height: 1.8;
|
||||||
white-space: pre-wrap;
|
white-space: pre-wrap;
|
||||||
word-break: break-all;
|
word-break: break-all;
|
||||||
color: #d4d4d4;
|
color: rgba(255, 255, 255, 0.8);
|
||||||
|
padding: 2px 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.log-time {
|
.log-time {
|
||||||
color: #808080;
|
color: rgba(255, 255, 255, 0.4);
|
||||||
margin-right: 8px;
|
margin-right: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.log-level {
|
.log-level {
|
||||||
margin-right: 8px;
|
margin-right: 8px;
|
||||||
|
font-weight: 500;
|
||||||
}
|
}
|
||||||
|
|
||||||
.log-src {
|
.log-src {
|
||||||
color: #a0a0a0;
|
color: rgba(167, 139, 250, 0.8);
|
||||||
margin-right: 8px;
|
margin-right: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.log-msg {
|
.log-msg {
|
||||||
color: #d4d4d4;
|
color: rgba(255, 255, 255, 0.85);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Scrollbar */
|
||||||
|
.log-container::-webkit-scrollbar {
|
||||||
|
width: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-container::-webkit-scrollbar-track {
|
||||||
|
background: rgba(255, 255, 255, 0.05);
|
||||||
|
border-radius: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-container::-webkit-scrollbar-thumb {
|
||||||
|
background: rgba(255, 255, 255, 0.2);
|
||||||
|
border-radius: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-container::-webkit-scrollbar-thumb:hover {
|
||||||
|
background: rgba(255, 255, 255, 0.3);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Responsive */
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
.log-overlay {
|
||||||
|
padding: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-modal {
|
||||||
|
max-height: 90vh;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-header {
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-controls {
|
||||||
|
order: 1;
|
||||||
|
width: 100%;
|
||||||
|
margin-top: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-input {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
62
web/src/components/MetricCard.vue
Normal file
62
web/src/components/MetricCard.vue
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
const props = defineProps<{
|
||||||
|
label: string
|
||||||
|
value: string | number
|
||||||
|
hint?: string
|
||||||
|
tone?: 'default' | 'success' | 'warning' | 'info'
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const toneClass = props.tone || 'default'
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<article class="metric-card" :class="`metric-card--${toneClass}`">
|
||||||
|
<span class="metric-card__label">{{ label }}</span>
|
||||||
|
<strong class="metric-card__value">{{ value }}</strong>
|
||||||
|
<span v-if="hint" class="metric-card__hint">{{ hint }}</span>
|
||||||
|
</article>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.metric-card {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 10px;
|
||||||
|
padding: 18px;
|
||||||
|
min-height: 128px;
|
||||||
|
border-radius: 20px;
|
||||||
|
background: var(--glass-bg-card);
|
||||||
|
border: 1px solid var(--color-border);
|
||||||
|
box-shadow: var(--shadow-card);
|
||||||
|
}
|
||||||
|
|
||||||
|
.metric-card__label {
|
||||||
|
font-size: 13px;
|
||||||
|
color: var(--color-text-secondary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.metric-card__value {
|
||||||
|
font-size: clamp(26px, 4vw, 34px);
|
||||||
|
line-height: 1;
|
||||||
|
color: var(--color-text-primary);
|
||||||
|
letter-spacing: -0.04em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.metric-card__hint {
|
||||||
|
margin-top: auto;
|
||||||
|
font-size: 13px;
|
||||||
|
color: var(--color-text-muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
.metric-card--success {
|
||||||
|
border-color: rgba(16, 185, 129, 0.24);
|
||||||
|
}
|
||||||
|
|
||||||
|
.metric-card--warning {
|
||||||
|
border-color: rgba(245, 158, 11, 0.24);
|
||||||
|
}
|
||||||
|
|
||||||
|
.metric-card--info {
|
||||||
|
border-color: rgba(6, 182, 212, 0.24);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
154
web/src/components/PageShell.vue
Normal file
154
web/src/components/PageShell.vue
Normal file
@@ -0,0 +1,154 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
defineProps<{
|
||||||
|
title: string
|
||||||
|
subtitle?: string
|
||||||
|
eyebrow?: string
|
||||||
|
}>()
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<section class="page-shell">
|
||||||
|
<div class="page-shell__glow page-shell__glow--primary"></div>
|
||||||
|
<div class="page-shell__glow page-shell__glow--secondary"></div>
|
||||||
|
|
||||||
|
<header class="page-shell__header">
|
||||||
|
<div class="page-shell__heading">
|
||||||
|
<span v-if="eyebrow" class="page-shell__eyebrow">{{ eyebrow }}</span>
|
||||||
|
<h1>{{ title }}</h1>
|
||||||
|
<p v-if="subtitle">{{ subtitle }}</p>
|
||||||
|
</div>
|
||||||
|
<div v-if="$slots.actions" class="page-shell__actions">
|
||||||
|
<slot name="actions" />
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div v-if="$slots.metrics" class="page-shell__metrics">
|
||||||
|
<slot name="metrics" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="page-shell__content">
|
||||||
|
<slot />
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.page-shell {
|
||||||
|
position: relative;
|
||||||
|
padding: 32px;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-shell__glow {
|
||||||
|
position: absolute;
|
||||||
|
border-radius: 999px;
|
||||||
|
filter: blur(80px);
|
||||||
|
opacity: 0.18;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-shell__glow--primary {
|
||||||
|
width: 320px;
|
||||||
|
height: 320px;
|
||||||
|
top: -120px;
|
||||||
|
right: -80px;
|
||||||
|
background: var(--color-accent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-shell__glow--secondary {
|
||||||
|
width: 280px;
|
||||||
|
height: 280px;
|
||||||
|
bottom: -120px;
|
||||||
|
left: -40px;
|
||||||
|
background: #8b5cf6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-shell__header,
|
||||||
|
.page-shell__metrics,
|
||||||
|
.page-shell__content {
|
||||||
|
position: relative;
|
||||||
|
z-index: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-shell__header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 20px;
|
||||||
|
align-items: flex-start;
|
||||||
|
margin-bottom: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-shell__heading {
|
||||||
|
max-width: 720px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-shell__eyebrow {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
|
padding: 6px 10px;
|
||||||
|
margin-bottom: 12px;
|
||||||
|
border-radius: 999px;
|
||||||
|
background: rgba(59, 130, 246, 0.12);
|
||||||
|
border: 1px solid rgba(59, 130, 246, 0.18);
|
||||||
|
color: var(--color-accent);
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 600;
|
||||||
|
letter-spacing: 0.04em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-shell__heading h1 {
|
||||||
|
margin: 0;
|
||||||
|
font-size: clamp(28px, 4vw, 40px);
|
||||||
|
font-weight: 700;
|
||||||
|
letter-spacing: -0.03em;
|
||||||
|
color: var(--color-text-primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-shell__heading p {
|
||||||
|
margin: 10px 0 0;
|
||||||
|
max-width: 640px;
|
||||||
|
color: var(--color-text-secondary);
|
||||||
|
font-size: 15px;
|
||||||
|
line-height: 1.7;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-shell__actions {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
justify-content: flex-end;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-shell__metrics {
|
||||||
|
display: grid;
|
||||||
|
gap: 16px;
|
||||||
|
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
|
||||||
|
margin-bottom: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-shell__content {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
.page-shell {
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-shell__header {
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-shell__actions {
|
||||||
|
width: 100%;
|
||||||
|
justify-content: stretch;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-shell__actions :deep(*) {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
79
web/src/components/SectionCard.vue
Normal file
79
web/src/components/SectionCard.vue
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
defineProps<{
|
||||||
|
title: string
|
||||||
|
description?: string
|
||||||
|
}>()
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<section class="section-card glass-card">
|
||||||
|
<header class="section-card__header">
|
||||||
|
<div>
|
||||||
|
<h2>{{ title }}</h2>
|
||||||
|
<p v-if="description">{{ description }}</p>
|
||||||
|
</div>
|
||||||
|
<div v-if="$slots.header" class="section-card__extra">
|
||||||
|
<slot name="header" />
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div class="section-card__body">
|
||||||
|
<slot />
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.section-card {
|
||||||
|
padding: 22px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.section-card__header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: flex-start;
|
||||||
|
gap: 16px;
|
||||||
|
margin-bottom: 18px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.section-card__header h2 {
|
||||||
|
margin: 0;
|
||||||
|
font-size: 18px;
|
||||||
|
font-weight: 700;
|
||||||
|
color: var(--color-text-primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.section-card__header p {
|
||||||
|
margin: 8px 0 0;
|
||||||
|
font-size: 13px;
|
||||||
|
line-height: 1.6;
|
||||||
|
color: var(--color-text-secondary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.section-card__extra {
|
||||||
|
display: flex;
|
||||||
|
gap: 8px;
|
||||||
|
align-items: center;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.section-card__body {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
.section-card {
|
||||||
|
padding: 18px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.section-card__header {
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.section-card__extra {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
129
web/src/composables/useConfirm.ts
Normal file
129
web/src/composables/useConfirm.ts
Normal file
@@ -0,0 +1,129 @@
|
|||||||
|
import { ref, createApp, h } from 'vue'
|
||||||
|
|
||||||
|
interface DialogOptions {
|
||||||
|
title: string
|
||||||
|
content: string
|
||||||
|
positiveText?: string
|
||||||
|
negativeText?: string
|
||||||
|
onPositiveClick?: () => void | Promise<void>
|
||||||
|
onNegativeClick?: () => void
|
||||||
|
}
|
||||||
|
|
||||||
|
const dialogVisible = ref(false)
|
||||||
|
const dialogOptions = ref<DialogOptions | null>(null)
|
||||||
|
|
||||||
|
const DialogComponent = {
|
||||||
|
setup() {
|
||||||
|
const handlePositive = async () => {
|
||||||
|
if (dialogOptions.value?.onPositiveClick) {
|
||||||
|
await dialogOptions.value.onPositiveClick()
|
||||||
|
}
|
||||||
|
dialogVisible.value = false
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleNegative = () => {
|
||||||
|
dialogOptions.value?.onNegativeClick?.()
|
||||||
|
dialogVisible.value = false
|
||||||
|
}
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
if (!dialogVisible.value || !dialogOptions.value) return null
|
||||||
|
|
||||||
|
return h('div', { class: 'dialog-overlay', onClick: handleNegative },
|
||||||
|
h('div', { class: 'dialog-container', onClick: (e: Event) => e.stopPropagation() }, [
|
||||||
|
h('h3', { class: 'dialog-title' }, dialogOptions.value.title),
|
||||||
|
h('p', { class: 'dialog-content' }, dialogOptions.value.content),
|
||||||
|
h('div', { class: 'dialog-footer' }, [
|
||||||
|
h('button', { class: 'dialog-btn', onClick: handleNegative },
|
||||||
|
dialogOptions.value.negativeText || '取消'),
|
||||||
|
h('button', { class: 'dialog-btn primary', onClick: handlePositive },
|
||||||
|
dialogOptions.value.positiveText || '确定')
|
||||||
|
])
|
||||||
|
])
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let containerMounted = false
|
||||||
|
|
||||||
|
function ensureContainer() {
|
||||||
|
if (containerMounted) return
|
||||||
|
|
||||||
|
const container = document.createElement('div')
|
||||||
|
container.id = 'dialog-root'
|
||||||
|
document.body.appendChild(container)
|
||||||
|
|
||||||
|
const app = createApp(DialogComponent)
|
||||||
|
app.mount(container)
|
||||||
|
containerMounted = true
|
||||||
|
|
||||||
|
// Add styles
|
||||||
|
const style = document.createElement('style')
|
||||||
|
style.textContent = `
|
||||||
|
.dialog-overlay {
|
||||||
|
position: fixed;
|
||||||
|
inset: 0;
|
||||||
|
background: rgba(0, 0, 0, 0.6);
|
||||||
|
backdrop-filter: blur(4px);
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
z-index: 9998;
|
||||||
|
}
|
||||||
|
.dialog-container {
|
||||||
|
background: rgba(30, 27, 75, 0.95);
|
||||||
|
backdrop-filter: blur(20px);
|
||||||
|
border-radius: 16px;
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.12);
|
||||||
|
padding: 24px;
|
||||||
|
max-width: 400px;
|
||||||
|
width: 90%;
|
||||||
|
}
|
||||||
|
.dialog-title {
|
||||||
|
margin: 0 0 12px 0;
|
||||||
|
font-size: 18px;
|
||||||
|
font-weight: 600;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
.dialog-content {
|
||||||
|
margin: 0 0 20px 0;
|
||||||
|
color: rgba(255, 255, 255, 0.7);
|
||||||
|
font-size: 14px;
|
||||||
|
line-height: 1.6;
|
||||||
|
}
|
||||||
|
.dialog-footer {
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-end;
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
.dialog-btn {
|
||||||
|
background: rgba(255, 255, 255, 0.1);
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.15);
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 8px 16px;
|
||||||
|
color: white;
|
||||||
|
font-size: 14px;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.2s;
|
||||||
|
}
|
||||||
|
.dialog-btn:hover {
|
||||||
|
background: rgba(255, 255, 255, 0.2);
|
||||||
|
}
|
||||||
|
.dialog-btn.primary {
|
||||||
|
background: linear-gradient(135deg, #60a5fa 0%, #a78bfa 100%);
|
||||||
|
border: none;
|
||||||
|
}
|
||||||
|
`
|
||||||
|
document.head.appendChild(style)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useConfirm() {
|
||||||
|
return {
|
||||||
|
warning: (options: DialogOptions) => {
|
||||||
|
ensureContainer()
|
||||||
|
dialogOptions.value = options
|
||||||
|
dialogVisible.value = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
47
web/src/composables/useTheme.ts
Normal file
47
web/src/composables/useTheme.ts
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
import { ref, watch, onMounted } from 'vue'
|
||||||
|
|
||||||
|
export type ThemeMode = 'light' | 'dark' | 'auto'
|
||||||
|
|
||||||
|
const STORAGE_KEY = 'gotunnel-theme'
|
||||||
|
|
||||||
|
const themeMode = ref<ThemeMode>('auto')
|
||||||
|
|
||||||
|
function getSystemTheme(): 'light' | 'dark' {
|
||||||
|
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'
|
||||||
|
}
|
||||||
|
|
||||||
|
function applyTheme(mode: ThemeMode) {
|
||||||
|
const theme = mode === 'auto' ? getSystemTheme() : mode
|
||||||
|
document.documentElement.setAttribute('data-theme', theme)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useTheme() {
|
||||||
|
onMounted(() => {
|
||||||
|
const saved = localStorage.getItem(STORAGE_KEY) as ThemeMode | null
|
||||||
|
if (saved && ['light', 'dark', 'auto'].includes(saved)) {
|
||||||
|
themeMode.value = saved
|
||||||
|
}
|
||||||
|
applyTheme(themeMode.value)
|
||||||
|
|
||||||
|
// 监听系统主题变化
|
||||||
|
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => {
|
||||||
|
if (themeMode.value === 'auto') {
|
||||||
|
applyTheme('auto')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
watch(themeMode, (mode) => {
|
||||||
|
localStorage.setItem(STORAGE_KEY, mode)
|
||||||
|
applyTheme(mode)
|
||||||
|
})
|
||||||
|
|
||||||
|
const setTheme = (mode: ThemeMode) => {
|
||||||
|
themeMode.value = mode
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
themeMode,
|
||||||
|
setTheme
|
||||||
|
}
|
||||||
|
}
|
||||||
101
web/src/composables/useToast.ts
Normal file
101
web/src/composables/useToast.ts
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
import { ref, createApp, h } from 'vue'
|
||||||
|
|
||||||
|
interface ToastOptions {
|
||||||
|
message: string
|
||||||
|
type: 'success' | 'error' | 'warning' | 'info'
|
||||||
|
duration?: number
|
||||||
|
}
|
||||||
|
|
||||||
|
const toasts = ref<Array<ToastOptions & { id: number }>>([])
|
||||||
|
let toastId = 0
|
||||||
|
|
||||||
|
const ToastContainer = {
|
||||||
|
setup() {
|
||||||
|
return () => h('div', { class: 'toast-container' },
|
||||||
|
toasts.value.map(toast =>
|
||||||
|
h('div', {
|
||||||
|
key: toast.id,
|
||||||
|
class: ['toast-item', toast.type]
|
||||||
|
}, toast.message)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let containerMounted = false
|
||||||
|
|
||||||
|
function ensureContainer() {
|
||||||
|
if (containerMounted) return
|
||||||
|
|
||||||
|
const container = document.createElement('div')
|
||||||
|
container.id = 'toast-root'
|
||||||
|
document.body.appendChild(container)
|
||||||
|
|
||||||
|
const app = createApp(ToastContainer)
|
||||||
|
app.mount(container)
|
||||||
|
containerMounted = true
|
||||||
|
|
||||||
|
// Add styles
|
||||||
|
const style = document.createElement('style')
|
||||||
|
style.textContent = `
|
||||||
|
.toast-container {
|
||||||
|
position: fixed;
|
||||||
|
top: 20px;
|
||||||
|
right: 20px;
|
||||||
|
z-index: 9999;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
.toast-item {
|
||||||
|
padding: 12px 20px;
|
||||||
|
border-radius: 8px;
|
||||||
|
font-size: 14px;
|
||||||
|
color: white;
|
||||||
|
backdrop-filter: blur(20px);
|
||||||
|
animation: toast-in 0.3s ease;
|
||||||
|
max-width: 350px;
|
||||||
|
}
|
||||||
|
.toast-item.success {
|
||||||
|
background: rgba(52, 211, 153, 0.9);
|
||||||
|
}
|
||||||
|
.toast-item.error {
|
||||||
|
background: rgba(239, 68, 68, 0.9);
|
||||||
|
}
|
||||||
|
.toast-item.warning {
|
||||||
|
background: rgba(251, 191, 36, 0.9);
|
||||||
|
color: #1e1b4b;
|
||||||
|
}
|
||||||
|
.toast-item.info {
|
||||||
|
background: rgba(96, 165, 250, 0.9);
|
||||||
|
}
|
||||||
|
@keyframes toast-in {
|
||||||
|
from { opacity: 0; transform: translateX(20px); }
|
||||||
|
to { opacity: 1; transform: translateX(0); }
|
||||||
|
}
|
||||||
|
`
|
||||||
|
document.head.appendChild(style)
|
||||||
|
}
|
||||||
|
|
||||||
|
function showToast(options: ToastOptions) {
|
||||||
|
ensureContainer()
|
||||||
|
|
||||||
|
const id = ++toastId
|
||||||
|
toasts.value.push({ ...options, id })
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
const index = toasts.value.findIndex(t => t.id === id)
|
||||||
|
if (index > -1) {
|
||||||
|
toasts.value.splice(index, 1)
|
||||||
|
}
|
||||||
|
}, options.duration || 3000)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useToast() {
|
||||||
|
return {
|
||||||
|
success: (message: string) => showToast({ message, type: 'success' }),
|
||||||
|
error: (message: string) => showToast({ message, type: 'error' }),
|
||||||
|
warning: (message: string) => showToast({ message, type: 'warning' }),
|
||||||
|
info: (message: string) => showToast({ message, type: 'info' })
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,10 +1,8 @@
|
|||||||
import { createApp } from 'vue'
|
import { createApp } from 'vue'
|
||||||
import naive from 'naive-ui'
|
|
||||||
import './style.css'
|
import './style.css'
|
||||||
import App from './App.vue'
|
import App from './App.vue'
|
||||||
import router from './router'
|
import router from './router'
|
||||||
|
|
||||||
const app = createApp(App)
|
const app = createApp(App)
|
||||||
app.use(router)
|
app.use(router)
|
||||||
app.use(naive)
|
|
||||||
app.mount('#app')
|
app.mount('#app')
|
||||||
|
|||||||
@@ -15,20 +15,20 @@ const router = createRouter({
|
|||||||
name: 'home',
|
name: 'home',
|
||||||
component: () => import('../views/HomeView.vue'),
|
component: () => import('../views/HomeView.vue'),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: '/clients',
|
||||||
|
name: 'clients',
|
||||||
|
component: () => import('../views/ClientsView.vue'),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: '/client/:id',
|
path: '/client/:id',
|
||||||
name: 'client',
|
name: 'client',
|
||||||
component: () => import('../views/ClientView.vue'),
|
component: () => import('../views/ClientView.vue'),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/plugins',
|
path: '/settings',
|
||||||
name: 'plugins',
|
name: 'settings',
|
||||||
component: () => import('../views/PluginsView.vue'),
|
component: () => import('../views/SettingsView.vue'),
|
||||||
},
|
|
||||||
{
|
|
||||||
path: '/update',
|
|
||||||
name: 'update',
|
|
||||||
component: () => import('../views/UpdateView.vue'),
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,3 +1,123 @@
|
|||||||
|
@import "tailwindcss";
|
||||||
|
|
||||||
|
/* ========================================
|
||||||
|
GoTunnel 毛玻璃设计系统
|
||||||
|
Glassmorphism Design System
|
||||||
|
======================================== */
|
||||||
|
|
||||||
|
/* 深色主题(默认) - 深邃渐变背景 */
|
||||||
|
:root,
|
||||||
|
[data-theme="dark"] {
|
||||||
|
/* 背景色 - 深色渐变基底 */
|
||||||
|
--color-bg-primary: #0a0e17;
|
||||||
|
--color-bg-secondary: #0d1220;
|
||||||
|
--color-bg-tertiary: #111827;
|
||||||
|
--color-bg-elevated: #1a2332;
|
||||||
|
|
||||||
|
/* 玻璃态背景 - 半透明 */
|
||||||
|
--glass-bg: rgba(17, 24, 39, 0.6);
|
||||||
|
--glass-bg-hover: rgba(26, 35, 50, 0.7);
|
||||||
|
--glass-bg-light: rgba(255, 255, 255, 0.03);
|
||||||
|
--glass-bg-card: rgba(17, 24, 39, 0.5);
|
||||||
|
|
||||||
|
/* 边框 - 高光描边 */
|
||||||
|
--color-border: rgba(255, 255, 255, 0.08);
|
||||||
|
--color-border-light: rgba(255, 255, 255, 0.05);
|
||||||
|
--color-border-glow: rgba(99, 179, 237, 0.3);
|
||||||
|
--glass-border: 1px solid rgba(255, 255, 255, 0.1);
|
||||||
|
--glass-border-hover: 1px solid rgba(255, 255, 255, 0.15);
|
||||||
|
|
||||||
|
/* 文字颜色 */
|
||||||
|
--color-text-primary: #f0f4f8;
|
||||||
|
--color-text-secondary: rgba(240, 244, 248, 0.7);
|
||||||
|
--color-text-muted: rgba(240, 244, 248, 0.45);
|
||||||
|
|
||||||
|
/* 强调色 - 霓虹高光 */
|
||||||
|
--color-accent: #3b82f6;
|
||||||
|
--color-accent-hover: #60a5fa;
|
||||||
|
--color-accent-glow: rgba(59, 130, 246, 0.4);
|
||||||
|
--color-success: #10b981;
|
||||||
|
--color-success-glow: rgba(16, 185, 129, 0.4);
|
||||||
|
--color-warning: #f59e0b;
|
||||||
|
--color-warning-glow: rgba(245, 158, 11, 0.4);
|
||||||
|
--color-error: #ef4444;
|
||||||
|
--color-error-glow: rgba(239, 68, 68, 0.4);
|
||||||
|
--color-info: #06b6d4;
|
||||||
|
--color-info-glow: rgba(6, 182, 212, 0.4);
|
||||||
|
|
||||||
|
/* 渐变背景 */
|
||||||
|
--gradient-bg: linear-gradient(135deg, #0a0e17 0%, #1a1f35 50%, #0d1220 100%);
|
||||||
|
--gradient-accent: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
|
||||||
|
--gradient-card: linear-gradient(135deg, rgba(255,255,255,0.05) 0%, rgba(255,255,255,0.02) 100%);
|
||||||
|
|
||||||
|
/* 模糊效果 */
|
||||||
|
--glass-blur: blur(20px);
|
||||||
|
--glass-blur-light: blur(12px);
|
||||||
|
|
||||||
|
/* 阴影 - 悬浮感 */
|
||||||
|
--shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
|
||||||
|
--shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
|
||||||
|
--shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
|
||||||
|
--shadow-glow: 0 0 20px rgba(59, 130, 246, 0.15);
|
||||||
|
--shadow-card: 0 8px 32px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.05);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 浅色主题 - 柔和渐变背景 */
|
||||||
|
[data-theme="light"] {
|
||||||
|
/* 背景色 - 浅色渐变基底 */
|
||||||
|
--color-bg-primary: #f0f4f8;
|
||||||
|
--color-bg-secondary: #e8eef4;
|
||||||
|
--color-bg-tertiary: #ffffff;
|
||||||
|
--color-bg-elevated: #ffffff;
|
||||||
|
|
||||||
|
/* 玻璃态背景 - 半透明白 */
|
||||||
|
--glass-bg: rgba(255, 255, 255, 0.7);
|
||||||
|
--glass-bg-hover: rgba(255, 255, 255, 0.85);
|
||||||
|
--glass-bg-light: rgba(255, 255, 255, 0.5);
|
||||||
|
--glass-bg-card: rgba(255, 255, 255, 0.6);
|
||||||
|
|
||||||
|
/* 边框 - 柔和描边 */
|
||||||
|
--color-border: rgba(0, 0, 0, 0.08);
|
||||||
|
--color-border-light: rgba(0, 0, 0, 0.05);
|
||||||
|
--color-border-glow: rgba(59, 130, 246, 0.3);
|
||||||
|
--glass-border: 1px solid rgba(255, 255, 255, 0.8);
|
||||||
|
--glass-border-hover: 1px solid rgba(255, 255, 255, 0.95);
|
||||||
|
|
||||||
|
/* 文字颜色 */
|
||||||
|
--color-text-primary: #1a202c;
|
||||||
|
--color-text-secondary: rgba(26, 32, 44, 0.7);
|
||||||
|
--color-text-muted: rgba(26, 32, 44, 0.5);
|
||||||
|
|
||||||
|
/* 强调色 */
|
||||||
|
--color-accent: #3b82f6;
|
||||||
|
--color-accent-hover: #2563eb;
|
||||||
|
--color-accent-glow: rgba(59, 130, 246, 0.3);
|
||||||
|
--color-success: #10b981;
|
||||||
|
--color-success-glow: rgba(16, 185, 129, 0.3);
|
||||||
|
--color-warning: #f59e0b;
|
||||||
|
--color-warning-glow: rgba(245, 158, 11, 0.3);
|
||||||
|
--color-error: #ef4444;
|
||||||
|
--color-error-glow: rgba(239, 68, 68, 0.3);
|
||||||
|
--color-info: #06b6d4;
|
||||||
|
--color-info-glow: rgba(6, 182, 212, 0.3);
|
||||||
|
|
||||||
|
/* 渐变背景 */
|
||||||
|
--gradient-bg: linear-gradient(135deg, #e8eef4 0%, #f0f4f8 50%, #e0e8f0 100%);
|
||||||
|
--gradient-accent: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
|
||||||
|
--gradient-card: linear-gradient(135deg, rgba(255,255,255,0.9) 0%, rgba(255,255,255,0.7) 100%);
|
||||||
|
|
||||||
|
/* 模糊效果 */
|
||||||
|
--glass-blur: blur(20px);
|
||||||
|
--glass-blur-light: blur(12px);
|
||||||
|
|
||||||
|
/* 阴影 */
|
||||||
|
--shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.08);
|
||||||
|
--shadow-md: 0 4px 16px rgba(0, 0, 0, 0.1);
|
||||||
|
--shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.12);
|
||||||
|
--shadow-glow: 0 0 20px rgba(59, 130, 246, 0.1);
|
||||||
|
--shadow-card: 0 8px 32px rgba(0, 0, 0, 0.1), inset 0 1px 0 rgba(255, 255, 255, 0.8);
|
||||||
|
}
|
||||||
|
|
||||||
* {
|
* {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
@@ -8,8 +128,205 @@ body {
|
|||||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
|
||||||
-webkit-font-smoothing: antialiased;
|
-webkit-font-smoothing: antialiased;
|
||||||
-moz-osx-font-smoothing: grayscale;
|
-moz-osx-font-smoothing: grayscale;
|
||||||
|
background: var(--gradient-bg);
|
||||||
|
color: var(--color-text-primary);
|
||||||
|
min-height: 100vh;
|
||||||
}
|
}
|
||||||
|
|
||||||
#app {
|
#app {
|
||||||
min-height: 100vh;
|
min-height: 100vh;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ========================================
|
||||||
|
玻璃态卡片组件
|
||||||
|
======================================== */
|
||||||
|
|
||||||
|
.glass-card {
|
||||||
|
background: var(--glass-bg);
|
||||||
|
backdrop-filter: var(--glass-blur);
|
||||||
|
-webkit-backdrop-filter: var(--glass-blur);
|
||||||
|
border-radius: 16px;
|
||||||
|
border: 1px solid var(--color-border);
|
||||||
|
box-shadow: var(--shadow-card);
|
||||||
|
position: relative;
|
||||||
|
overflow: hidden;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 卡片顶部高光 */
|
||||||
|
.glass-card::before {
|
||||||
|
content: '';
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
height: 1px;
|
||||||
|
background: linear-gradient(90deg,
|
||||||
|
transparent 0%,
|
||||||
|
rgba(255, 255, 255, 0.1) 50%,
|
||||||
|
transparent 100%);
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.glass-card-hover:hover {
|
||||||
|
background: var(--glass-bg-hover);
|
||||||
|
border-color: rgba(255, 255, 255, 0.12);
|
||||||
|
box-shadow: var(--shadow-lg), var(--shadow-glow);
|
||||||
|
transform: translateY(-2px);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ========================================
|
||||||
|
玻璃态按钮
|
||||||
|
======================================== */
|
||||||
|
|
||||||
|
.glass-btn {
|
||||||
|
background: var(--glass-bg);
|
||||||
|
backdrop-filter: var(--glass-blur-light);
|
||||||
|
-webkit-backdrop-filter: var(--glass-blur-light);
|
||||||
|
border: 1px solid var(--color-border);
|
||||||
|
border-radius: 10px;
|
||||||
|
padding: 10px 18px;
|
||||||
|
color: var(--color-text-primary);
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: 500;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
position: relative;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.glass-btn:hover {
|
||||||
|
background: var(--glass-bg-hover);
|
||||||
|
border-color: rgba(255, 255, 255, 0.15);
|
||||||
|
box-shadow: var(--shadow-sm);
|
||||||
|
}
|
||||||
|
|
||||||
|
.glass-btn:active {
|
||||||
|
transform: scale(0.98);
|
||||||
|
}
|
||||||
|
|
||||||
|
.glass-btn.primary {
|
||||||
|
background: var(--gradient-accent);
|
||||||
|
border: none;
|
||||||
|
color: white;
|
||||||
|
box-shadow: 0 4px 15px var(--color-accent-glow);
|
||||||
|
}
|
||||||
|
|
||||||
|
.glass-btn.primary:hover {
|
||||||
|
box-shadow: 0 6px 20px var(--color-accent-glow);
|
||||||
|
filter: brightness(1.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.glass-btn.small {
|
||||||
|
padding: 6px 12px;
|
||||||
|
font-size: 12px;
|
||||||
|
border-radius: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ========================================
|
||||||
|
玻璃态输入框
|
||||||
|
======================================== */
|
||||||
|
|
||||||
|
.glass-input {
|
||||||
|
background: var(--glass-bg-light);
|
||||||
|
backdrop-filter: var(--glass-blur-light);
|
||||||
|
-webkit-backdrop-filter: var(--glass-blur-light);
|
||||||
|
border: 1px solid var(--color-border);
|
||||||
|
border-radius: 10px;
|
||||||
|
padding: 12px 16px;
|
||||||
|
color: var(--color-text-primary);
|
||||||
|
font-size: 15px;
|
||||||
|
width: 100%;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.glass-input:focus {
|
||||||
|
border-color: var(--color-accent);
|
||||||
|
box-shadow: 0 0 0 3px var(--color-accent-glow);
|
||||||
|
}
|
||||||
|
|
||||||
|
.glass-input::placeholder {
|
||||||
|
color: var(--color-text-muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ========================================
|
||||||
|
动画背景粒子
|
||||||
|
======================================== */
|
||||||
|
|
||||||
|
.particles {
|
||||||
|
position: absolute;
|
||||||
|
inset: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
pointer-events: none;
|
||||||
|
z-index: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.particle {
|
||||||
|
position: absolute;
|
||||||
|
border-radius: 50%;
|
||||||
|
opacity: 0.15;
|
||||||
|
filter: blur(60px);
|
||||||
|
animation: float 20s ease-in-out infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
.particle-1 {
|
||||||
|
width: 400px;
|
||||||
|
height: 400px;
|
||||||
|
background: var(--color-accent);
|
||||||
|
top: -100px;
|
||||||
|
right: -100px;
|
||||||
|
animation-delay: 0s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.particle-2 {
|
||||||
|
width: 300px;
|
||||||
|
height: 300px;
|
||||||
|
background: #8b5cf6;
|
||||||
|
bottom: -50px;
|
||||||
|
left: -50px;
|
||||||
|
animation-delay: -5s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.particle-3 {
|
||||||
|
width: 250px;
|
||||||
|
height: 250px;
|
||||||
|
background: var(--color-info);
|
||||||
|
top: 50%;
|
||||||
|
left: 50%;
|
||||||
|
animation-delay: -10s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.particle-4 {
|
||||||
|
width: 200px;
|
||||||
|
height: 200px;
|
||||||
|
background: var(--color-success);
|
||||||
|
bottom: 20%;
|
||||||
|
right: 20%;
|
||||||
|
animation-delay: -15s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.particle-5 {
|
||||||
|
width: 350px;
|
||||||
|
height: 350px;
|
||||||
|
background: #ec4899;
|
||||||
|
top: 30%;
|
||||||
|
left: 10%;
|
||||||
|
animation-delay: -7s;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes float {
|
||||||
|
0%, 100% {
|
||||||
|
transform: translate(0, 0) scale(1);
|
||||||
|
}
|
||||||
|
25% {
|
||||||
|
transform: translate(30px, -30px) scale(1.05);
|
||||||
|
}
|
||||||
|
50% {
|
||||||
|
transform: translate(-20px, 20px) scale(0.95);
|
||||||
|
}
|
||||||
|
75% {
|
||||||
|
transform: translate(-30px, -20px) scale(1.02);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,43 +6,6 @@ export interface ProxyRule {
|
|||||||
remote_port: number
|
remote_port: number
|
||||||
type?: string
|
type?: string
|
||||||
enabled?: boolean
|
enabled?: boolean
|
||||||
plugin_config?: Record<string, string>
|
|
||||||
plugin_managed?: boolean // 插件管理标记 - 由插件自动创建的规则
|
|
||||||
}
|
|
||||||
|
|
||||||
// 客户端已安装的插件
|
|
||||||
export interface ClientPlugin {
|
|
||||||
id: string // 插件实例唯一 ID
|
|
||||||
name: string
|
|
||||||
version: string
|
|
||||||
enabled: boolean
|
|
||||||
running: boolean
|
|
||||||
config?: Record<string, string>
|
|
||||||
remote_port?: number // 远程监听端口
|
|
||||||
}
|
|
||||||
|
|
||||||
// 插件配置字段
|
|
||||||
export interface ConfigField {
|
|
||||||
key: string
|
|
||||||
label: string
|
|
||||||
type: 'string' | 'number' | 'bool' | 'select' | 'password'
|
|
||||||
default?: string
|
|
||||||
required?: boolean
|
|
||||||
options?: string[]
|
|
||||||
description?: string
|
|
||||||
}
|
|
||||||
|
|
||||||
// 规则表单模式
|
|
||||||
export interface RuleSchema {
|
|
||||||
needs_local_addr: boolean
|
|
||||||
extra_fields?: ConfigField[]
|
|
||||||
}
|
|
||||||
|
|
||||||
// 插件配置响应
|
|
||||||
export interface PluginConfigResponse {
|
|
||||||
plugin_name: string
|
|
||||||
schema: ConfigField[]
|
|
||||||
config: Record<string, string>
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 客户端配置
|
// 客户端配置
|
||||||
@@ -50,7 +13,6 @@ export interface ClientConfig {
|
|||||||
id: string
|
id: string
|
||||||
nickname?: string
|
nickname?: string
|
||||||
rules: ProxyRule[]
|
rules: ProxyRule[]
|
||||||
plugins?: ClientPlugin[]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 客户端状态
|
// 客户端状态
|
||||||
@@ -61,6 +23,8 @@ export interface ClientStatus {
|
|||||||
last_ping?: string
|
last_ping?: string
|
||||||
remote_addr?: string
|
remote_addr?: string
|
||||||
rule_count: number
|
rule_count: number
|
||||||
|
os?: string
|
||||||
|
arch?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
// 客户端详情
|
// 客户端详情
|
||||||
@@ -68,10 +32,12 @@ export interface ClientDetail {
|
|||||||
id: string
|
id: string
|
||||||
nickname?: string
|
nickname?: string
|
||||||
rules: ProxyRule[]
|
rules: ProxyRule[]
|
||||||
plugins?: ClientPlugin[]
|
|
||||||
online: boolean
|
online: boolean
|
||||||
last_ping?: string
|
last_ping?: string
|
||||||
remote_addr?: string
|
remote_addr?: string
|
||||||
|
os?: string
|
||||||
|
arch?: string
|
||||||
|
version?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
// 服务器状态
|
// 服务器状态
|
||||||
@@ -83,64 +49,12 @@ export interface ServerStatus {
|
|||||||
client_count: number
|
client_count: number
|
||||||
}
|
}
|
||||||
|
|
||||||
// 插件类型
|
|
||||||
export const PluginType = {
|
|
||||||
Proxy: 'proxy',
|
|
||||||
App: 'app',
|
|
||||||
Service: 'service',
|
|
||||||
Tool: 'tool'
|
|
||||||
} as const
|
|
||||||
|
|
||||||
export type PluginTypeValue = typeof PluginType[keyof typeof PluginType]
|
|
||||||
|
|
||||||
// 插件信息
|
|
||||||
export interface PluginInfo {
|
|
||||||
name: string
|
|
||||||
version: string
|
|
||||||
type: string
|
|
||||||
description: string
|
|
||||||
source: string
|
|
||||||
icon?: string
|
|
||||||
enabled: boolean
|
|
||||||
rule_schema?: RuleSchema
|
|
||||||
}
|
|
||||||
|
|
||||||
// 扩展商店插件信息
|
|
||||||
export interface StorePluginInfo {
|
|
||||||
name: string
|
|
||||||
version: string
|
|
||||||
type: string
|
|
||||||
description: string
|
|
||||||
author: string
|
|
||||||
icon?: string
|
|
||||||
download_url?: string
|
|
||||||
signature_url?: string
|
|
||||||
config_schema?: ConfigField[]
|
|
||||||
}
|
|
||||||
|
|
||||||
// JS 插件信息
|
|
||||||
export interface JSPlugin {
|
|
||||||
name: string
|
|
||||||
source: string
|
|
||||||
signature?: string
|
|
||||||
description: string
|
|
||||||
author: string
|
|
||||||
version?: string
|
|
||||||
auto_push: string[]
|
|
||||||
config: Record<string, string>
|
|
||||||
auto_start: boolean
|
|
||||||
enabled: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
// 规则配置模式集合
|
|
||||||
export type RuleSchemasMap = Record<string, RuleSchema>
|
|
||||||
|
|
||||||
// 日志条目
|
// 日志条目
|
||||||
export interface LogEntry {
|
export interface LogEntry {
|
||||||
ts: number // Unix 时间戳 (毫秒)
|
ts: number // Unix 时间戳 (毫秒)
|
||||||
level: string // 日志级别: debug, info, warn, error
|
level: string // 日志级别: debug, info, warn, error
|
||||||
msg: string // 日志消息
|
msg: string // 日志消息
|
||||||
src: string // 来源: client, plugin:<name>
|
src: string // 来源: client
|
||||||
}
|
}
|
||||||
|
|
||||||
// 日志流选项
|
// 日志流选项
|
||||||
@@ -149,3 +63,15 @@ export interface LogStreamOptions {
|
|||||||
follow?: boolean // 是否持续推送
|
follow?: boolean // 是否持续推送
|
||||||
level?: string // 日志级别过滤
|
level?: string // 日志级别过滤
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 安装命令响应
|
||||||
|
export interface InstallCommandResponse {
|
||||||
|
token: string
|
||||||
|
commands: {
|
||||||
|
linux: string
|
||||||
|
macos: string
|
||||||
|
windows: string
|
||||||
|
}
|
||||||
|
expires_at: number
|
||||||
|
server_addr: string
|
||||||
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
295
web/src/views/ClientsView.vue
Normal file
295
web/src/views/ClientsView.vue
Normal file
@@ -0,0 +1,295 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { computed, onMounted, ref } from 'vue'
|
||||||
|
import { useRouter } from 'vue-router'
|
||||||
|
import GlassModal from '../components/GlassModal.vue'
|
||||||
|
import MetricCard from '../components/MetricCard.vue'
|
||||||
|
import PageShell from '../components/PageShell.vue'
|
||||||
|
import SectionCard from '../components/SectionCard.vue'
|
||||||
|
import { generateInstallCommand, getClients } from '../api'
|
||||||
|
import { useToast } from '../composables/useToast'
|
||||||
|
import type { ClientStatus, InstallCommandResponse } from '../types'
|
||||||
|
|
||||||
|
const router = useRouter()
|
||||||
|
const message = useToast()
|
||||||
|
const clients = ref<ClientStatus[]>([])
|
||||||
|
const loading = ref(true)
|
||||||
|
const showInstallModal = ref(false)
|
||||||
|
const installData = ref<InstallCommandResponse | null>(null)
|
||||||
|
const generatingInstall = ref(false)
|
||||||
|
const search = ref('')
|
||||||
|
|
||||||
|
const loadClients = async () => {
|
||||||
|
loading.value = true
|
||||||
|
try {
|
||||||
|
const { data } = await getClients()
|
||||||
|
clients.value = data || []
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to load clients', error)
|
||||||
|
message.error('客户端列表加载失败')
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const openInstallModal = async () => {
|
||||||
|
generatingInstall.value = true
|
||||||
|
try {
|
||||||
|
const { data } = await generateInstallCommand()
|
||||||
|
installData.value = data
|
||||||
|
showInstallModal.value = true
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to generate install command', error)
|
||||||
|
message.error('安装命令生成失败')
|
||||||
|
} finally {
|
||||||
|
generatingInstall.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const copyCommand = async (command: string) => {
|
||||||
|
try {
|
||||||
|
await navigator.clipboard.writeText(command)
|
||||||
|
message.success('命令已复制')
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to copy command', error)
|
||||||
|
message.error('复制失败,请手动复制')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const filteredClients = computed(() => {
|
||||||
|
const keyword = search.value.trim().toLowerCase()
|
||||||
|
if (!keyword) return clients.value
|
||||||
|
return clients.value.filter((client) => {
|
||||||
|
return [client.id, client.nickname, client.remote_addr, client.os, client.arch]
|
||||||
|
.filter(Boolean)
|
||||||
|
.some((value) => String(value).toLowerCase().includes(keyword))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
const onlineClients = computed(() => clients.value.filter((client) => client.online).length)
|
||||||
|
const offlineClients = computed(() => Math.max(clients.value.length - onlineClients.value, 0))
|
||||||
|
|
||||||
|
onMounted(loadClients)
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<PageShell title="客户端" eyebrow="Clients" subtitle="统一管理已注册节点、连接状态与快速安装命令,减少操作跳转。">
|
||||||
|
<template #actions>
|
||||||
|
<button class="glass-btn" :disabled="generatingInstall" @click="openInstallModal">
|
||||||
|
{{ generatingInstall ? '生成中...' : '安装命令' }}
|
||||||
|
</button>
|
||||||
|
<button class="glass-btn primary" @click="loadClients">{{ loading ? '刷新中...' : '刷新列表' }}</button>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template #metrics>
|
||||||
|
<MetricCard label="客户端总数" :value="clients.length" hint="已接入的全部节点" />
|
||||||
|
<MetricCard label="在线节点" :value="onlineClients" hint="可立即推送配置" tone="success" />
|
||||||
|
<MetricCard label="离线节点" :value="offlineClients" hint="等待心跳恢复" tone="warning" />
|
||||||
|
<MetricCard label="当前筛选结果" :value="filteredClients.length" hint="支持 ID / 昵称 / 地址搜索" tone="info" />
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<SectionCard title="节点列表" description="使用统一卡片样式展示连接信息,便于快速判断状态与进入详情页。">
|
||||||
|
<template #header>
|
||||||
|
<input v-model="search" class="glass-input search-input" type="search" placeholder="搜索 ID / 昵称 / 地址" />
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<div v-if="loading" class="empty-state">正在加载客户端列表...</div>
|
||||||
|
<div v-else-if="filteredClients.length === 0" class="empty-state">未找到匹配的客户端。</div>
|
||||||
|
<div v-else class="client-grid">
|
||||||
|
<article v-for="client in filteredClients" :key="client.id" class="client-card" @click="router.push(`/client/${client.id}`)">
|
||||||
|
<div class="client-card__header">
|
||||||
|
<div>
|
||||||
|
<div class="client-card__title">
|
||||||
|
<span class="status-dot" :class="{ online: client.online }"></span>
|
||||||
|
<strong>{{ client.nickname || client.id }}</strong>
|
||||||
|
</div>
|
||||||
|
<p>{{ client.nickname ? client.id : client.remote_addr || '等待首次连接' }}</p>
|
||||||
|
</div>
|
||||||
|
<span class="state-pill" :class="client.online ? 'online' : 'offline'">{{ client.online ? '在线' : '离线' }}</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<dl class="client-card__meta">
|
||||||
|
<div>
|
||||||
|
<dt>地址</dt>
|
||||||
|
<dd>{{ client.remote_addr || '未上报' }}</dd>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<dt>规则数</dt>
|
||||||
|
<dd>{{ client.rule_count || 0 }}</dd>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<dt>平台</dt>
|
||||||
|
<dd>{{ [client.os, client.arch].filter(Boolean).join(' / ') || '未知' }}</dd>
|
||||||
|
</div>
|
||||||
|
</dl>
|
||||||
|
</article>
|
||||||
|
</div>
|
||||||
|
</SectionCard>
|
||||||
|
|
||||||
|
<GlassModal :show="showInstallModal" title="安装命令" width="760px" @close="showInstallModal = false">
|
||||||
|
<div v-if="installData" class="install-grid">
|
||||||
|
<article v-for="item in [
|
||||||
|
{ label: 'Linux', value: installData.commands.linux },
|
||||||
|
{ label: 'macOS', value: installData.commands.macos },
|
||||||
|
{ label: 'Windows', value: installData.commands.windows },
|
||||||
|
]" :key="item.label" class="install-card">
|
||||||
|
<header>
|
||||||
|
<strong>{{ item.label }}</strong>
|
||||||
|
<button class="glass-btn small" @click="copyCommand(item.value)">复制</button>
|
||||||
|
</header>
|
||||||
|
<code>{{ item.value }}</code>
|
||||||
|
</article>
|
||||||
|
</div>
|
||||||
|
<template #footer>
|
||||||
|
<span class="install-footnote">命令内含一次性 token,使用后请重新生成。</span>
|
||||||
|
</template>
|
||||||
|
</GlassModal>
|
||||||
|
</PageShell>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.search-input {
|
||||||
|
min-width: min(320px, 100%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.client-grid {
|
||||||
|
display: grid;
|
||||||
|
gap: 16px;
|
||||||
|
grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
|
||||||
|
}
|
||||||
|
|
||||||
|
.client-card {
|
||||||
|
padding: 18px;
|
||||||
|
border-radius: 18px;
|
||||||
|
background: var(--glass-bg-light);
|
||||||
|
border: 1px solid var(--color-border-light);
|
||||||
|
cursor: pointer;
|
||||||
|
transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.client-card:hover {
|
||||||
|
transform: translateY(-2px);
|
||||||
|
border-color: rgba(59, 130, 246, 0.24);
|
||||||
|
box-shadow: var(--shadow-md);
|
||||||
|
}
|
||||||
|
|
||||||
|
.client-card__header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 12px;
|
||||||
|
margin-bottom: 18px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.client-card__title {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 10px;
|
||||||
|
margin-bottom: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.client-card__header p {
|
||||||
|
color: var(--color-text-secondary);
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-dot {
|
||||||
|
width: 10px;
|
||||||
|
height: 10px;
|
||||||
|
border-radius: 999px;
|
||||||
|
background: var(--color-error);
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-dot.online {
|
||||||
|
background: var(--color-success);
|
||||||
|
}
|
||||||
|
|
||||||
|
.state-pill {
|
||||||
|
height: fit-content;
|
||||||
|
padding: 4px 10px;
|
||||||
|
border-radius: 999px;
|
||||||
|
font-size: 12px;
|
||||||
|
border: 1px solid transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
.state-pill.online {
|
||||||
|
color: var(--color-success);
|
||||||
|
background: rgba(16, 185, 129, 0.12);
|
||||||
|
border-color: rgba(16, 185, 129, 0.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.state-pill.offline {
|
||||||
|
color: var(--color-text-secondary);
|
||||||
|
background: rgba(148, 163, 184, 0.12);
|
||||||
|
border-color: rgba(148, 163, 184, 0.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.client-card__meta {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.client-card__meta dt {
|
||||||
|
margin-bottom: 6px;
|
||||||
|
color: var(--color-text-muted);
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.client-card__meta dd {
|
||||||
|
color: var(--color-text-primary);
|
||||||
|
font-size: 13px;
|
||||||
|
word-break: break-word;
|
||||||
|
}
|
||||||
|
|
||||||
|
.install-grid {
|
||||||
|
display: grid;
|
||||||
|
gap: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.install-card {
|
||||||
|
padding: 16px;
|
||||||
|
border-radius: 16px;
|
||||||
|
background: var(--glass-bg-light);
|
||||||
|
border: 1px solid var(--color-border-light);
|
||||||
|
}
|
||||||
|
|
||||||
|
.install-card header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
gap: 12px;
|
||||||
|
margin-bottom: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.install-card code {
|
||||||
|
display: block;
|
||||||
|
color: var(--color-text-primary);
|
||||||
|
white-space: pre-wrap;
|
||||||
|
word-break: break-all;
|
||||||
|
font-size: 12px;
|
||||||
|
line-height: 1.7;
|
||||||
|
}
|
||||||
|
|
||||||
|
.install-footnote {
|
||||||
|
color: var(--color-text-secondary);
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.empty-state {
|
||||||
|
padding: 48px 20px;
|
||||||
|
text-align: center;
|
||||||
|
color: var(--color-text-secondary);
|
||||||
|
background: var(--glass-bg-light);
|
||||||
|
border: 1px dashed var(--color-border);
|
||||||
|
border-radius: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
.client-card__header {
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.client-card__meta {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -1,97 +1,324 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, onMounted, computed } from 'vue'
|
import { computed, onMounted, ref } from 'vue'
|
||||||
import { useRouter } from 'vue-router'
|
import { getClients, getTrafficHourly, getTrafficStats, type TrafficRecord } from '../api'
|
||||||
import { NCard, NButton, NSpace, NTag, NStatistic, NGrid, NGi, NEmpty, NIcon } from 'naive-ui'
|
|
||||||
import { ExtensionPuzzleOutline, CloudDownloadOutline } from '@vicons/ionicons5'
|
|
||||||
import { getClients } from '../api'
|
|
||||||
import type { ClientStatus } from '../types'
|
import type { ClientStatus } from '../types'
|
||||||
|
import MetricCard from '../components/MetricCard.vue'
|
||||||
|
import PageShell from '../components/PageShell.vue'
|
||||||
|
import SectionCard from '../components/SectionCard.vue'
|
||||||
|
|
||||||
const router = useRouter()
|
|
||||||
const clients = ref<ClientStatus[]>([])
|
const clients = ref<ClientStatus[]>([])
|
||||||
|
const traffic24h = ref({ inbound: 0, outbound: 0 })
|
||||||
|
const trafficTotal = ref({ inbound: 0, outbound: 0 })
|
||||||
|
const trafficHistory = ref<TrafficRecord[]>([])
|
||||||
|
const loading = ref(true)
|
||||||
|
|
||||||
const loadClients = async () => {
|
const formatBytes = (bytes: number): { value: string; unit: string } => {
|
||||||
try {
|
if (bytes === 0) return { value: '0', unit: 'B' }
|
||||||
const { data } = await getClients()
|
const units = ['B', 'KB', 'MB', 'GB', 'TB']
|
||||||
clients.value = data || []
|
const index = Math.min(Math.floor(Math.log(bytes) / Math.log(1024)), units.length - 1)
|
||||||
} catch (e) {
|
return {
|
||||||
console.error('Failed to load clients', e)
|
value: (bytes / Math.pow(1024, index)).toFixed(index === 0 ? 0 : 1),
|
||||||
|
unit: units[index] ?? 'B',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const loadDashboard = async () => {
|
||||||
|
loading.value = true
|
||||||
|
try {
|
||||||
|
const [{ data: clientData }, { data: statsData }, { data: hourlyData }] = await Promise.all([
|
||||||
|
getClients(),
|
||||||
|
getTrafficStats(),
|
||||||
|
getTrafficHourly(),
|
||||||
|
])
|
||||||
|
|
||||||
const onlineClients = computed(() => {
|
clients.value = clientData || []
|
||||||
return clients.value.filter(client => client.online).length
|
traffic24h.value = statsData.traffic_24h
|
||||||
})
|
trafficTotal.value = statsData.traffic_total
|
||||||
|
|
||||||
const totalRules = computed(() => {
|
const records = hourlyData.records || []
|
||||||
return clients.value.reduce((sum, client) => sum + client.rule_count, 0)
|
if (records.length) {
|
||||||
})
|
trafficHistory.value = records.slice(-12)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
onMounted(loadClients)
|
const now = new Date()
|
||||||
|
trafficHistory.value = Array.from({ length: 12 }, (_, index) => {
|
||||||
const viewClient = (id: string) => {
|
const slot = new Date(now.getTime() - (11 - index) * 3600 * 1000)
|
||||||
router.push(`/client/${id}`)
|
return {
|
||||||
|
timestamp: Math.floor(slot.getTime() / 1000),
|
||||||
|
inbound: 0,
|
||||||
|
outbound: 0,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to load dashboard', error)
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const onlineClients = computed(() => clients.value.filter((client) => client.online).length)
|
||||||
|
const offlineClients = computed(() => Math.max(clients.value.length - onlineClients.value, 0))
|
||||||
|
const totalRules = computed(() => clients.value.reduce((sum, client) => sum + (client.rule_count || 0), 0))
|
||||||
|
const topClients = computed(() => [...clients.value].sort((a, b) => Number(b.online) - Number(a.online)).slice(0, 6))
|
||||||
|
const chartMax = computed(() => Math.max(...trafficHistory.value.flatMap((item) => [item.inbound, item.outbound]), 1))
|
||||||
|
const formatted24hInbound = computed(() => formatBytes(traffic24h.value.inbound))
|
||||||
|
const formatted24hOutbound = computed(() => formatBytes(traffic24h.value.outbound))
|
||||||
|
const formattedTotalInbound = computed(() => formatBytes(trafficTotal.value.inbound))
|
||||||
|
const formattedTotalOutbound = computed(() => formatBytes(trafficTotal.value.outbound))
|
||||||
|
const formatHour = (timestamp: number) => new Date(timestamp * 1000).toLocaleTimeString('zh-CN', { hour: '2-digit', minute: '2-digit' })
|
||||||
|
|
||||||
|
onMounted(loadDashboard)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="home">
|
<PageShell title="控制台" eyebrow="Overview" subtitle="统一查看连接状态、流量趋势与客户端健康情况,减少页面层级并突出关键数据。">
|
||||||
<n-space justify="space-between" align="center" style="margin-bottom: 24px;">
|
<template #actions>
|
||||||
|
<button class="glass-btn" @click="loadDashboard">{{ loading ? '刷新中...' : '刷新数据' }}</button>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template #metrics>
|
||||||
|
<MetricCard label="在线客户端" :value="onlineClients" :hint="`离线 ${offlineClients} 台`" tone="success" />
|
||||||
|
<MetricCard label="代理规则" :value="totalRules" hint="全部客户端规则总数" />
|
||||||
|
<MetricCard
|
||||||
|
label="24H 出站"
|
||||||
|
:value="formatted24hOutbound.value"
|
||||||
|
:hint="formatted24hOutbound.unit"
|
||||||
|
tone="info"
|
||||||
|
/>
|
||||||
|
<MetricCard
|
||||||
|
label="总入站"
|
||||||
|
:value="formattedTotalInbound.value"
|
||||||
|
:hint="formattedTotalInbound.unit"
|
||||||
|
tone="warning"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<div class="dashboard-grid">
|
||||||
|
<SectionCard title="流量趋势" description="近 12 小时入站 / 出站流量概览。">
|
||||||
|
<div class="traffic-summary">
|
||||||
|
<div class="traffic-pill">
|
||||||
|
<span>24H 入站</span>
|
||||||
|
<strong>{{ formatted24hInbound.value }} {{ formatted24hInbound.unit }}</strong>
|
||||||
|
</div>
|
||||||
|
<div class="traffic-pill">
|
||||||
|
<span>24H 出站</span>
|
||||||
|
<strong>{{ formatted24hOutbound.value }} {{ formatted24hOutbound.unit }}</strong>
|
||||||
|
</div>
|
||||||
|
<div class="traffic-pill">
|
||||||
|
<span>总出站</span>
|
||||||
|
<strong>{{ formattedTotalOutbound.value }} {{ formattedTotalOutbound.unit }}</strong>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="traffic-chart">
|
||||||
|
<div v-for="item in trafficHistory" :key="item.timestamp" class="traffic-chart__item">
|
||||||
|
<div class="traffic-chart__bars">
|
||||||
|
<span class="bar bar--inbound" :style="{ height: `${(item.inbound / chartMax) * 100}%` }"></span>
|
||||||
|
<span class="bar bar--outbound" :style="{ height: `${(item.outbound / chartMax) * 100}%` }"></span>
|
||||||
|
</div>
|
||||||
|
<span class="traffic-chart__label">{{ formatHour(item.timestamp) }}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</SectionCard>
|
||||||
|
|
||||||
|
<SectionCard title="客户端概况" description="优先展示在线客户端,并保留连接来源与规则数量。">
|
||||||
|
<div v-if="topClients.length" class="client-list">
|
||||||
|
<article v-for="client in topClients" :key="client.id" class="client-row">
|
||||||
<div>
|
<div>
|
||||||
<h2 style="margin: 0 0 8px 0;">客户端管理</h2>
|
<div class="client-row__title">
|
||||||
<p style="margin: 0; color: #666;">查看已连接的隧道客户端</p>
|
<span class="client-dot" :class="{ online: client.online }"></span>
|
||||||
|
<strong>{{ client.nickname || client.id }}</strong>
|
||||||
</div>
|
</div>
|
||||||
<n-space>
|
<p>{{ client.remote_addr || '等待连接地址' }}</p>
|
||||||
<n-button @click="router.push('/plugins')">
|
|
||||||
<template #icon><n-icon><ExtensionPuzzleOutline /></n-icon></template>
|
|
||||||
扩展商店
|
|
||||||
</n-button>
|
|
||||||
<n-button @click="router.push('/update')">
|
|
||||||
<template #icon><n-icon><CloudDownloadOutline /></n-icon></template>
|
|
||||||
系统更新
|
|
||||||
</n-button>
|
|
||||||
</n-space>
|
|
||||||
</n-space>
|
|
||||||
|
|
||||||
<n-grid :cols="3" :x-gap="16" :y-gap="16" style="margin-bottom: 24px;">
|
|
||||||
<n-gi>
|
|
||||||
<n-card>
|
|
||||||
<n-statistic label="总客户端" :value="clients.length" />
|
|
||||||
</n-card>
|
|
||||||
</n-gi>
|
|
||||||
<n-gi>
|
|
||||||
<n-card>
|
|
||||||
<n-statistic label="在线客户端" :value="onlineClients" />
|
|
||||||
</n-card>
|
|
||||||
</n-gi>
|
|
||||||
<n-gi>
|
|
||||||
<n-card>
|
|
||||||
<n-statistic label="总规则数" :value="totalRules" />
|
|
||||||
</n-card>
|
|
||||||
</n-gi>
|
|
||||||
</n-grid>
|
|
||||||
|
|
||||||
<n-empty v-if="clients.length === 0" description="暂无客户端连接" />
|
|
||||||
|
|
||||||
<n-grid v-else :cols="3" :x-gap="16" :y-gap="16" responsive="screen" cols-s="1" cols-m="2">
|
|
||||||
<n-gi v-for="client in clients" :key="client.id">
|
|
||||||
<n-card hoverable style="cursor: pointer;" @click="viewClient(client.id)">
|
|
||||||
<n-space justify="space-between" align="center">
|
|
||||||
<div>
|
|
||||||
<h3 style="margin: 0 0 4px 0;">{{ client.nickname || client.id }}</h3>
|
|
||||||
<p v-if="client.nickname" style="margin: 0 0 4px 0; color: #999; font-size: 12px;">{{ client.id }}</p>
|
|
||||||
<p v-if="client.remote_addr && client.online" style="margin: 0 0 8px 0; color: #666; font-size: 12px;">IP: {{ client.remote_addr }}</p>
|
|
||||||
<n-space>
|
|
||||||
<n-tag :type="client.online ? 'success' : 'default'" size="small">
|
|
||||||
{{ client.online ? '在线' : '离线' }}
|
|
||||||
</n-tag>
|
|
||||||
<n-tag type="info" size="small">{{ client.rule_count }} 条规则</n-tag>
|
|
||||||
</n-space>
|
|
||||||
</div>
|
</div>
|
||||||
<n-button size="small" @click.stop="viewClient(client.id)">查看详情</n-button>
|
<div class="client-row__meta">
|
||||||
</n-space>
|
<span>{{ client.rule_count || 0 }} 条规则</span>
|
||||||
</n-card>
|
<span class="state-pill" :class="client.online ? 'online' : 'offline'">{{ client.online ? '在线' : '离线' }}</span>
|
||||||
</n-gi>
|
|
||||||
</n-grid>
|
|
||||||
</div>
|
</div>
|
||||||
|
</article>
|
||||||
|
</div>
|
||||||
|
<div v-else class="empty-state">暂无客户端数据。</div>
|
||||||
|
</SectionCard>
|
||||||
|
</div>
|
||||||
|
</PageShell>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.dashboard-grid {
|
||||||
|
display: grid;
|
||||||
|
gap: 20px;
|
||||||
|
grid-template-columns: minmax(0, 1.6fr) minmax(320px, 1fr);
|
||||||
|
}
|
||||||
|
|
||||||
|
.traffic-summary {
|
||||||
|
display: grid;
|
||||||
|
gap: 12px;
|
||||||
|
grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
|
||||||
|
}
|
||||||
|
|
||||||
|
.traffic-pill {
|
||||||
|
padding: 14px 16px;
|
||||||
|
border-radius: 16px;
|
||||||
|
background: var(--glass-bg-light);
|
||||||
|
border: 1px solid var(--color-border-light);
|
||||||
|
}
|
||||||
|
|
||||||
|
.traffic-pill span {
|
||||||
|
display: block;
|
||||||
|
color: var(--color-text-secondary);
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.traffic-pill strong {
|
||||||
|
display: block;
|
||||||
|
margin-top: 8px;
|
||||||
|
color: var(--color-text-primary);
|
||||||
|
font-size: 18px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.traffic-chart {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(12, minmax(0, 1fr));
|
||||||
|
gap: 10px;
|
||||||
|
align-items: end;
|
||||||
|
min-height: 240px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.traffic-chart__item {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.traffic-chart__bars {
|
||||||
|
display: flex;
|
||||||
|
align-items: end;
|
||||||
|
gap: 4px;
|
||||||
|
height: 200px;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bar {
|
||||||
|
flex: 1;
|
||||||
|
min-height: 4px;
|
||||||
|
border-radius: 999px 999px 6px 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bar--inbound {
|
||||||
|
background: linear-gradient(180deg, rgba(6, 182, 212, 0.95), rgba(6, 182, 212, 0.25));
|
||||||
|
}
|
||||||
|
|
||||||
|
.bar--outbound {
|
||||||
|
background: linear-gradient(180deg, rgba(59, 130, 246, 0.95), rgba(59, 130, 246, 0.25));
|
||||||
|
}
|
||||||
|
|
||||||
|
.traffic-chart__label {
|
||||||
|
font-size: 11px;
|
||||||
|
color: var(--color-text-muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
.client-list {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.client-row {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 16px;
|
||||||
|
padding: 16px;
|
||||||
|
border-radius: 16px;
|
||||||
|
background: var(--glass-bg-light);
|
||||||
|
border: 1px solid var(--color-border-light);
|
||||||
|
}
|
||||||
|
|
||||||
|
.client-row__title {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 10px;
|
||||||
|
margin-bottom: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.client-row p {
|
||||||
|
color: var(--color-text-secondary);
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.client-row__meta {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: flex-end;
|
||||||
|
gap: 10px;
|
||||||
|
color: var(--color-text-secondary);
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.client-dot {
|
||||||
|
width: 10px;
|
||||||
|
height: 10px;
|
||||||
|
border-radius: 999px;
|
||||||
|
background: var(--color-error);
|
||||||
|
box-shadow: 0 0 0 6px rgba(239, 68, 68, 0.08);
|
||||||
|
}
|
||||||
|
|
||||||
|
.client-dot.online {
|
||||||
|
background: var(--color-success);
|
||||||
|
box-shadow: 0 0 0 6px rgba(16, 185, 129, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.state-pill {
|
||||||
|
padding: 4px 10px;
|
||||||
|
border-radius: 999px;
|
||||||
|
font-size: 12px;
|
||||||
|
border: 1px solid transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
.state-pill.online {
|
||||||
|
color: var(--color-success);
|
||||||
|
background: rgba(16, 185, 129, 0.12);
|
||||||
|
border-color: rgba(16, 185, 129, 0.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.state-pill.offline {
|
||||||
|
color: var(--color-text-secondary);
|
||||||
|
background: rgba(148, 163, 184, 0.12);
|
||||||
|
border-color: rgba(148, 163, 184, 0.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.empty-state {
|
||||||
|
padding: 36px 16px;
|
||||||
|
text-align: center;
|
||||||
|
color: var(--color-text-secondary);
|
||||||
|
background: var(--glass-bg-light);
|
||||||
|
border: 1px dashed var(--color-border);
|
||||||
|
border-radius: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 1024px) {
|
||||||
|
.dashboard-grid {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
.traffic-chart {
|
||||||
|
overflow-x: auto;
|
||||||
|
padding-bottom: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.traffic-chart__bars {
|
||||||
|
width: 28px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.client-row {
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.client-row__meta {
|
||||||
|
align-items: flex-start;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref } from 'vue'
|
import { computed, ref } from 'vue'
|
||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
import { NCard, NForm, NFormItem, NInput, NButton, NAlert } from 'naive-ui'
|
|
||||||
import { login, setToken } from '../api'
|
import { login, setToken } from '../api'
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
@@ -10,6 +9,14 @@ const password = ref('')
|
|||||||
const error = ref('')
|
const error = ref('')
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
|
|
||||||
|
const features = [
|
||||||
|
'统一管理隧道、客户端与规则状态',
|
||||||
|
'自动下发配置,客户端零配置接入',
|
||||||
|
'内置更新与运行状态查看,便于运维排障',
|
||||||
|
]
|
||||||
|
|
||||||
|
const canSubmit = computed(() => Boolean(username.value && password.value) && !loading.value)
|
||||||
|
|
||||||
const handleLogin = async () => {
|
const handleLogin = async () => {
|
||||||
if (!username.value || !password.value) {
|
if (!username.value || !password.value) {
|
||||||
error.value = '请输入用户名和密码'
|
error.value = '请输入用户名和密码'
|
||||||
@@ -18,7 +25,6 @@ const handleLogin = async () => {
|
|||||||
|
|
||||||
loading.value = true
|
loading.value = true
|
||||||
error.value = ''
|
error.value = ''
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { data } = await login(username.value, password.value)
|
const { data } = await login(username.value, password.value)
|
||||||
setToken(data.token)
|
setToken(data.token)
|
||||||
@@ -33,51 +39,40 @@ const handleLogin = async () => {
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="login-page">
|
<div class="login-page">
|
||||||
<n-card class="login-card" :bordered="false">
|
<div class="login-shell glass-card">
|
||||||
<template #header>
|
<section class="login-hero">
|
||||||
<div class="login-header">
|
<span class="login-badge">GoTunnel Console</span>
|
||||||
<h1 class="logo">GoTunnel</h1>
|
<h1>更统一、更轻量的管理界面。</h1>
|
||||||
<p class="subtitle">安全的内网穿透工具</p>
|
<p>聚焦连接状态、更新能力与节点管理,让日常操作更直观、页面更简洁。</p>
|
||||||
|
<ul>
|
||||||
|
<li v-for="item in features" :key="item">{{ item }}</li>
|
||||||
|
</ul>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section class="login-panel">
|
||||||
|
<div class="login-panel__header">
|
||||||
|
<h2>登录控制台</h2>
|
||||||
|
<p>使用服务端配置的 Web 账号进入管理界面。</p>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
|
||||||
|
|
||||||
<n-form @submit.prevent="handleLogin">
|
<form class="login-form" @submit.prevent="handleLogin">
|
||||||
<n-form-item label="用户名">
|
<label class="form-group">
|
||||||
<n-input
|
<span>用户名</span>
|
||||||
v-model:value="username"
|
<input v-model="username" class="glass-input" type="text" autocomplete="username" placeholder="请输入用户名" />
|
||||||
placeholder="请输入用户名"
|
</label>
|
||||||
:disabled="loading"
|
<label class="form-group">
|
||||||
/>
|
<span>密码</span>
|
||||||
</n-form-item>
|
<input v-model="password" class="glass-input" type="password" autocomplete="current-password" placeholder="请输入密码" />
|
||||||
|
</label>
|
||||||
|
|
||||||
<n-form-item label="密码">
|
<div v-if="error" class="error-alert">{{ error }}</div>
|
||||||
<n-input
|
|
||||||
v-model:value="password"
|
|
||||||
type="password"
|
|
||||||
placeholder="请输入密码"
|
|
||||||
:disabled="loading"
|
|
||||||
show-password-on="click"
|
|
||||||
/>
|
|
||||||
</n-form-item>
|
|
||||||
|
|
||||||
<n-alert v-if="error" type="error" :show-icon="true" style="margin-bottom: 16px;">
|
<button class="glass-btn primary submit-btn" type="submit" :disabled="!canSubmit">
|
||||||
{{ error }}
|
{{ loading ? '登录中...' : '进入控制台' }}
|
||||||
</n-alert>
|
</button>
|
||||||
|
</form>
|
||||||
<n-button
|
</section>
|
||||||
type="primary"
|
</div>
|
||||||
block
|
|
||||||
:loading="loading"
|
|
||||||
attr-type="submit"
|
|
||||||
>
|
|
||||||
{{ loading ? '登录中...' : '登录' }}
|
|
||||||
</n-button>
|
|
||||||
</n-form>
|
|
||||||
|
|
||||||
<template #footer>
|
|
||||||
<div class="login-footer">欢迎使用 GoTunnel</div>
|
|
||||||
</template>
|
|
||||||
</n-card>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -87,36 +82,140 @@ const handleLogin = async () => {
|
|||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
background: linear-gradient(135deg, #e8f5e9 0%, #c8e6c9 100%);
|
padding: 24px;
|
||||||
padding: 16px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.login-card {
|
.login-shell {
|
||||||
width: 100%;
|
width: min(1080px, 100%);
|
||||||
max-width: 400px;
|
display: grid;
|
||||||
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
|
grid-template-columns: minmax(0, 1.2fr) minmax(320px, 420px);
|
||||||
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
.login-header {
|
.login-hero,
|
||||||
text-align: center;
|
.login-panel {
|
||||||
|
padding: 40px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.logo {
|
.login-hero {
|
||||||
font-size: 28px;
|
display: flex;
|
||||||
font-weight: 700;
|
flex-direction: column;
|
||||||
color: #18a058;
|
justify-content: center;
|
||||||
margin: 0 0 8px 0;
|
gap: 18px;
|
||||||
|
background: linear-gradient(135deg, rgba(59, 130, 246, 0.14), rgba(139, 92, 246, 0.08));
|
||||||
|
border-right: 1px solid var(--color-border);
|
||||||
}
|
}
|
||||||
|
|
||||||
.subtitle {
|
.login-badge {
|
||||||
color: #666;
|
width: fit-content;
|
||||||
|
padding: 6px 10px;
|
||||||
|
border-radius: 999px;
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 600;
|
||||||
|
letter-spacing: 0.04em;
|
||||||
|
color: var(--color-accent);
|
||||||
|
background: rgba(59, 130, 246, 0.12);
|
||||||
|
border: 1px solid rgba(59, 130, 246, 0.18);
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-hero h1 {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
font-size: 14px;
|
font-size: clamp(34px, 4.5vw, 54px);
|
||||||
|
line-height: 1.1;
|
||||||
|
letter-spacing: -0.05em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.login-footer {
|
.login-hero p {
|
||||||
text-align: center;
|
margin: 0;
|
||||||
color: #999;
|
color: var(--color-text-secondary);
|
||||||
font-size: 14px;
|
font-size: 15px;
|
||||||
|
line-height: 1.8;
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-hero ul {
|
||||||
|
display: grid;
|
||||||
|
gap: 12px;
|
||||||
|
padding: 0;
|
||||||
|
margin: 8px 0 0;
|
||||||
|
list-style: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-hero li {
|
||||||
|
padding: 14px 16px;
|
||||||
|
border-radius: 16px;
|
||||||
|
background: var(--glass-bg-light);
|
||||||
|
border: 1px solid var(--color-border-light);
|
||||||
|
color: var(--color-text-primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-panel {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 26px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-panel__header h2 {
|
||||||
|
margin: 0 0 8px;
|
||||||
|
font-size: 28px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-panel__header p {
|
||||||
|
margin: 0;
|
||||||
|
color: var(--color-text-secondary);
|
||||||
|
line-height: 1.7;
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-form {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-group {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-group span {
|
||||||
|
color: var(--color-text-secondary);
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.submit-btn {
|
||||||
|
justify-content: center;
|
||||||
|
width: 100%;
|
||||||
|
margin-top: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.error-alert {
|
||||||
|
padding: 12px 14px;
|
||||||
|
border-radius: 14px;
|
||||||
|
color: var(--color-error);
|
||||||
|
background: rgba(239, 68, 68, 0.1);
|
||||||
|
border: 1px solid rgba(239, 68, 68, 0.18);
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 900px) {
|
||||||
|
.login-shell {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-hero {
|
||||||
|
border-right: none;
|
||||||
|
border-bottom: 1px solid var(--color-border);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 640px) {
|
||||||
|
.login-page {
|
||||||
|
padding: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-hero,
|
||||||
|
.login-panel {
|
||||||
|
padding: 28px 22px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -1,576 +0,0 @@
|
|||||||
<script setup lang="ts">
|
|
||||||
import { ref, onMounted, computed } from 'vue'
|
|
||||||
import { useRouter } from 'vue-router'
|
|
||||||
import {
|
|
||||||
NCard, NButton, NSpace, NTag, NStatistic, NGrid, NGi,
|
|
||||||
NEmpty, NSpin, NIcon, NSwitch, NTabs, NTabPane, useMessage,
|
|
||||||
NSelect, NModal, NInput, NInputNumber
|
|
||||||
} from 'naive-ui'
|
|
||||||
import { ArrowBackOutline, ExtensionPuzzleOutline, StorefrontOutline, CodeSlashOutline, SettingsOutline } from '@vicons/ionicons5'
|
|
||||||
import {
|
|
||||||
getPlugins, enablePlugin, disablePlugin, getStorePlugins, getJSPlugins,
|
|
||||||
pushJSPluginToClient, getClients, installStorePlugin, updateJSPluginConfig, setJSPluginEnabled
|
|
||||||
} from '../api'
|
|
||||||
import type { PluginInfo, StorePluginInfo, JSPlugin, ClientStatus } from '../types'
|
|
||||||
|
|
||||||
const router = useRouter()
|
|
||||||
const message = useMessage()
|
|
||||||
const plugins = ref<PluginInfo[]>([])
|
|
||||||
const storePlugins = ref<StorePluginInfo[]>([])
|
|
||||||
const jsPlugins = ref<JSPlugin[]>([])
|
|
||||||
const clients = ref<ClientStatus[]>([])
|
|
||||||
const loading = ref(true)
|
|
||||||
const storeLoading = ref(false)
|
|
||||||
const jsLoading = ref(false)
|
|
||||||
const activeTab = ref('installed')
|
|
||||||
|
|
||||||
const loadPlugins = async () => {
|
|
||||||
try {
|
|
||||||
const { data } = await getPlugins()
|
|
||||||
plugins.value = data || []
|
|
||||||
} catch (e) {
|
|
||||||
console.error('Failed to load plugins', e)
|
|
||||||
} finally {
|
|
||||||
loading.value = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const loadStorePlugins = async () => {
|
|
||||||
storeLoading.value = true
|
|
||||||
try {
|
|
||||||
const { data } = await getStorePlugins()
|
|
||||||
storePlugins.value = data.plugins || []
|
|
||||||
} catch (e) {
|
|
||||||
console.error('Failed to load store plugins', e)
|
|
||||||
} finally {
|
|
||||||
storeLoading.value = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const proxyPlugins = computed(() =>
|
|
||||||
plugins.value.filter(p => p.type === 'proxy')
|
|
||||||
)
|
|
||||||
|
|
||||||
const appPlugins = computed(() =>
|
|
||||||
plugins.value.filter(p => p.type === 'app')
|
|
||||||
)
|
|
||||||
|
|
||||||
const togglePlugin = async (plugin: PluginInfo) => {
|
|
||||||
try {
|
|
||||||
if (plugin.enabled) {
|
|
||||||
await disablePlugin(plugin.name)
|
|
||||||
message.success(`已禁用 ${plugin.name}`)
|
|
||||||
} else {
|
|
||||||
await enablePlugin(plugin.name)
|
|
||||||
message.success(`已启用 ${plugin.name}`)
|
|
||||||
}
|
|
||||||
plugin.enabled = !plugin.enabled
|
|
||||||
} catch (e) {
|
|
||||||
message.error('操作失败')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const getTypeLabel = (type: string) => {
|
|
||||||
const labels: Record<string, string> = {
|
|
||||||
proxy: '协议',
|
|
||||||
app: '应用',
|
|
||||||
service: '服务',
|
|
||||||
tool: '工具'
|
|
||||||
}
|
|
||||||
return labels[type] || type
|
|
||||||
}
|
|
||||||
|
|
||||||
const getTypeColor = (type: string) => {
|
|
||||||
const colors: Record<string, 'info' | 'success' | 'warning' | 'error' | 'default'> = {
|
|
||||||
proxy: 'info',
|
|
||||||
app: 'success',
|
|
||||||
service: 'warning',
|
|
||||||
tool: 'default'
|
|
||||||
}
|
|
||||||
return colors[type] || 'default'
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleTabChange = (tab: string) => {
|
|
||||||
if (tab === 'store' && storePlugins.value.length === 0) {
|
|
||||||
loadStorePlugins()
|
|
||||||
}
|
|
||||||
if (tab === 'js' && jsPlugins.value.length === 0) {
|
|
||||||
loadJSPlugins()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// JS 插件相关
|
|
||||||
/* 安全加固:暂时禁用创建/删除功能
|
|
||||||
const showJSModal = ref(false)
|
|
||||||
const jsForm = ref<JSPlugin>({...})
|
|
||||||
const configItems = ref<Array<{ key: string; value: string }>>([])
|
|
||||||
const configToObject = () => {...}
|
|
||||||
const handleCreateJSPlugin = async () => {...}
|
|
||||||
const handleDeleteJSPlugin = async (name: string) => {...}
|
|
||||||
const resetJSForm = () => {...}
|
|
||||||
*/
|
|
||||||
|
|
||||||
const loadJSPlugins = async () => {
|
|
||||||
jsLoading.value = true
|
|
||||||
try {
|
|
||||||
const { data } = await getJSPlugins()
|
|
||||||
jsPlugins.value = data || []
|
|
||||||
} catch (e) {
|
|
||||||
console.error('Failed to load JS plugins', e)
|
|
||||||
} finally {
|
|
||||||
jsLoading.value = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const loadClients = async () => {
|
|
||||||
try {
|
|
||||||
const { data } = await getClients()
|
|
||||||
clients.value = data || []
|
|
||||||
} catch (e) {
|
|
||||||
console.error('Failed to load clients', e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// JS 插件推送相关
|
|
||||||
const showPushModal = ref(false)
|
|
||||||
const selectedJSPlugin = ref<JSPlugin | null>(null)
|
|
||||||
const pushClientId = ref('')
|
|
||||||
const pushRemotePort = ref<number | null>(8080)
|
|
||||||
const pushing = ref(false)
|
|
||||||
|
|
||||||
const openPushModal = (plugin: JSPlugin) => {
|
|
||||||
selectedJSPlugin.value = plugin
|
|
||||||
pushClientId.value = ''
|
|
||||||
pushRemotePort.value = 8080
|
|
||||||
showPushModal.value = true
|
|
||||||
}
|
|
||||||
|
|
||||||
const handlePushJSPlugin = async () => {
|
|
||||||
if (!selectedJSPlugin.value || !pushClientId.value) {
|
|
||||||
message.warning('请选择要推送到的客户端')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
pushing.value = true
|
|
||||||
try {
|
|
||||||
await pushJSPluginToClient(selectedJSPlugin.value.name, pushClientId.value, pushRemotePort.value || 0)
|
|
||||||
message.success(`已推送 ${selectedJSPlugin.value.name} 到 ${pushClientId.value},监听端口: ${pushRemotePort.value || '未指定'}`)
|
|
||||||
showPushModal.value = false
|
|
||||||
} catch (e: any) {
|
|
||||||
message.error(e.response?.data || '推送失败')
|
|
||||||
} finally {
|
|
||||||
pushing.value = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const onlineClients = computed(() => clients.value.filter(c => c.online))
|
|
||||||
|
|
||||||
// JS 插件配置相关
|
|
||||||
const showJSConfigModal = ref(false)
|
|
||||||
const currentJSPlugin = ref<JSPlugin | null>(null)
|
|
||||||
const jsConfigItems = ref<Array<{ key: string; value: string }>>([])
|
|
||||||
const jsConfigSaving = ref(false)
|
|
||||||
|
|
||||||
const openJSConfigModal = (plugin: JSPlugin) => {
|
|
||||||
currentJSPlugin.value = plugin
|
|
||||||
// 将 config 转换为数组形式便于编辑
|
|
||||||
jsConfigItems.value = Object.entries(plugin.config || {}).map(([key, value]) => ({ key, value }))
|
|
||||||
if (jsConfigItems.value.length === 0) {
|
|
||||||
jsConfigItems.value.push({ key: '', value: '' })
|
|
||||||
}
|
|
||||||
showJSConfigModal.value = true
|
|
||||||
}
|
|
||||||
|
|
||||||
const addJSConfigItem = () => {
|
|
||||||
jsConfigItems.value.push({ key: '', value: '' })
|
|
||||||
}
|
|
||||||
|
|
||||||
const removeJSConfigItem = (index: number) => {
|
|
||||||
jsConfigItems.value.splice(index, 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
const saveJSPluginConfig = async () => {
|
|
||||||
if (!currentJSPlugin.value) return
|
|
||||||
|
|
||||||
jsConfigSaving.value = true
|
|
||||||
try {
|
|
||||||
// 将数组转换回对象
|
|
||||||
const config: Record<string, string> = {}
|
|
||||||
for (const item of jsConfigItems.value) {
|
|
||||||
if (item.key.trim()) {
|
|
||||||
config[item.key.trim()] = item.value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await updateJSPluginConfig(currentJSPlugin.value.name, config)
|
|
||||||
// 更新本地数据
|
|
||||||
const plugin = jsPlugins.value.find(p => p.name === currentJSPlugin.value!.name)
|
|
||||||
if (plugin) {
|
|
||||||
plugin.config = config
|
|
||||||
}
|
|
||||||
message.success('配置已保存')
|
|
||||||
showJSConfigModal.value = false
|
|
||||||
} catch (e: any) {
|
|
||||||
message.error(e.response?.data || '保存失败')
|
|
||||||
} finally {
|
|
||||||
jsConfigSaving.value = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 切换 JS 插件启用状态
|
|
||||||
const toggleJSPlugin = async (plugin: JSPlugin) => {
|
|
||||||
try {
|
|
||||||
await setJSPluginEnabled(plugin.name, !plugin.enabled)
|
|
||||||
plugin.enabled = !plugin.enabled
|
|
||||||
message.success(plugin.enabled ? `已启用 ${plugin.name}` : `已禁用 ${plugin.name}`)
|
|
||||||
} catch (e: any) {
|
|
||||||
message.error(e.response?.data || '操作失败')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 商店插件安装相关
|
|
||||||
const showInstallModal = ref(false)
|
|
||||||
const selectedStorePlugin = ref<StorePluginInfo | null>(null)
|
|
||||||
const selectedClientId = ref('')
|
|
||||||
const installing = ref(false)
|
|
||||||
const installRemotePort = ref<number | null>(8080)
|
|
||||||
const installAuthEnabled = ref(false)
|
|
||||||
const installAuthUsername = ref('')
|
|
||||||
const installAuthPassword = ref('')
|
|
||||||
|
|
||||||
const openInstallModal = (plugin: StorePluginInfo) => {
|
|
||||||
selectedStorePlugin.value = plugin
|
|
||||||
selectedClientId.value = ''
|
|
||||||
installRemotePort.value = 8080
|
|
||||||
installAuthEnabled.value = false
|
|
||||||
installAuthUsername.value = ''
|
|
||||||
installAuthPassword.value = ''
|
|
||||||
showInstallModal.value = true
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleInstallStorePlugin = async () => {
|
|
||||||
if (!selectedStorePlugin.value || !selectedClientId.value) {
|
|
||||||
message.warning('请选择要安装到的客户端')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (!selectedStorePlugin.value.download_url) {
|
|
||||||
message.error('该插件没有下载地址')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (!selectedStorePlugin.value.signature_url) {
|
|
||||||
message.error('该插件没有签名文件')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
installing.value = true
|
|
||||||
try {
|
|
||||||
await installStorePlugin(
|
|
||||||
selectedStorePlugin.value.name,
|
|
||||||
selectedStorePlugin.value.download_url,
|
|
||||||
selectedStorePlugin.value.signature_url,
|
|
||||||
selectedClientId.value,
|
|
||||||
installRemotePort.value || 8080,
|
|
||||||
selectedStorePlugin.value.version,
|
|
||||||
selectedStorePlugin.value.config_schema,
|
|
||||||
installAuthEnabled.value,
|
|
||||||
installAuthUsername.value,
|
|
||||||
installAuthPassword.value
|
|
||||||
)
|
|
||||||
message.success(`已安装 ${selectedStorePlugin.value.name}`)
|
|
||||||
showInstallModal.value = false
|
|
||||||
} catch (e: any) {
|
|
||||||
message.error(e.response?.data || '安装失败')
|
|
||||||
} finally {
|
|
||||||
installing.value = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onMounted(() => {
|
|
||||||
loadPlugins()
|
|
||||||
loadClients()
|
|
||||||
})
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<div class="plugins-view">
|
|
||||||
<n-space justify="space-between" align="center" style="margin-bottom: 24px;">
|
|
||||||
<div>
|
|
||||||
<h2 style="margin: 0 0 8px 0;">插件管理</h2>
|
|
||||||
<p style="margin: 0; color: #666;">管理已安装插件和浏览插件商店</p>
|
|
||||||
</div>
|
|
||||||
<n-button quaternary @click="router.push('/')">
|
|
||||||
<template #icon><n-icon><ArrowBackOutline /></n-icon></template>
|
|
||||||
返回首页
|
|
||||||
</n-button>
|
|
||||||
</n-space>
|
|
||||||
|
|
||||||
<n-tabs v-model:value="activeTab" type="line" @update:value="handleTabChange">
|
|
||||||
<!-- 已安装插件 -->
|
|
||||||
<n-tab-pane name="installed" tab="已安装插件">
|
|
||||||
<n-spin :show="loading">
|
|
||||||
<n-grid :cols="3" :x-gap="16" :y-gap="16" style="margin-bottom: 24px;">
|
|
||||||
<n-gi>
|
|
||||||
<n-card>
|
|
||||||
<n-statistic label="总插件数" :value="plugins.length" />
|
|
||||||
</n-card>
|
|
||||||
</n-gi>
|
|
||||||
<n-gi>
|
|
||||||
<n-card>
|
|
||||||
<n-statistic label="协议插件" :value="proxyPlugins.length" />
|
|
||||||
</n-card>
|
|
||||||
</n-gi>
|
|
||||||
<n-gi>
|
|
||||||
<n-card>
|
|
||||||
<n-statistic label="应用插件" :value="appPlugins.length" />
|
|
||||||
</n-card>
|
|
||||||
</n-gi>
|
|
||||||
</n-grid>
|
|
||||||
|
|
||||||
<n-empty v-if="!loading && plugins.length === 0" description="暂无已安装插件" />
|
|
||||||
|
|
||||||
<n-grid v-else :cols="3" :x-gap="16" :y-gap="16" responsive="screen" cols-s="1" cols-m="2">
|
|
||||||
<n-gi v-for="plugin in plugins" :key="plugin.name">
|
|
||||||
<n-card hoverable>
|
|
||||||
<template #header>
|
|
||||||
<n-space align="center">
|
|
||||||
<img v-if="plugin.icon" :src="plugin.icon" style="width: 24px; height: 24px;" />
|
|
||||||
<n-icon v-else size="24" color="#18a058"><ExtensionPuzzleOutline /></n-icon>
|
|
||||||
<span>{{ plugin.name }}</span>
|
|
||||||
</n-space>
|
|
||||||
</template>
|
|
||||||
<template #header-extra>
|
|
||||||
<n-switch :value="plugin.enabled" @update:value="togglePlugin(plugin)" />
|
|
||||||
</template>
|
|
||||||
<n-space vertical :size="8">
|
|
||||||
<n-space>
|
|
||||||
<n-tag size="small">v{{ plugin.version }}</n-tag>
|
|
||||||
<n-tag size="small" :type="getTypeColor(plugin.type)">
|
|
||||||
{{ getTypeLabel(plugin.type) }}
|
|
||||||
</n-tag>
|
|
||||||
<n-tag size="small" :type="plugin.source === 'builtin' ? 'default' : 'info'">
|
|
||||||
{{ plugin.source === 'builtin' ? '内置' : 'JS' }}
|
|
||||||
</n-tag>
|
|
||||||
</n-space>
|
|
||||||
<p style="margin: 0; color: #666;">{{ plugin.description }}</p>
|
|
||||||
</n-space>
|
|
||||||
</n-card>
|
|
||||||
</n-gi>
|
|
||||||
</n-grid>
|
|
||||||
</n-spin>
|
|
||||||
</n-tab-pane>
|
|
||||||
|
|
||||||
<!-- 插件商店 -->
|
|
||||||
<n-tab-pane name="store" tab="插件商店">
|
|
||||||
<n-spin :show="storeLoading">
|
|
||||||
<n-empty v-if="!storeLoading && storePlugins.length === 0" description="插件商店暂无可用插件" />
|
|
||||||
|
|
||||||
<n-grid v-else :cols="3" :x-gap="16" :y-gap="16" responsive="screen" cols-s="1" cols-m="2">
|
|
||||||
<n-gi v-for="plugin in storePlugins" :key="plugin.name">
|
|
||||||
<n-card hoverable>
|
|
||||||
<template #header>
|
|
||||||
<n-space align="center">
|
|
||||||
<img v-if="plugin.icon" :src="plugin.icon" style="width: 24px; height: 24px;" />
|
|
||||||
<n-icon v-else size="24" color="#18a058"><StorefrontOutline /></n-icon>
|
|
||||||
<span>{{ plugin.name }}</span>
|
|
||||||
</n-space>
|
|
||||||
</template>
|
|
||||||
<template #header-extra>
|
|
||||||
<n-button
|
|
||||||
v-if="plugin.download_url && plugin.signature_url && onlineClients.length > 0"
|
|
||||||
size="small"
|
|
||||||
type="primary"
|
|
||||||
@click="openInstallModal(plugin)"
|
|
||||||
>
|
|
||||||
安装
|
|
||||||
</n-button>
|
|
||||||
</template>
|
|
||||||
<n-space vertical :size="8">
|
|
||||||
<n-space>
|
|
||||||
<n-tag size="small">v{{ plugin.version }}</n-tag>
|
|
||||||
<n-tag size="small" :type="getTypeColor(plugin.type)">
|
|
||||||
{{ getTypeLabel(plugin.type) }}
|
|
||||||
</n-tag>
|
|
||||||
</n-space>
|
|
||||||
<p style="margin: 0; color: #666;">{{ plugin.description }}</p>
|
|
||||||
<p style="margin: 0; color: #999; font-size: 12px;">作者: {{ plugin.author }}</p>
|
|
||||||
</n-space>
|
|
||||||
</n-card>
|
|
||||||
</n-gi>
|
|
||||||
</n-grid>
|
|
||||||
</n-spin>
|
|
||||||
</n-tab-pane>
|
|
||||||
|
|
||||||
<!-- JS 插件 -->
|
|
||||||
<n-tab-pane name="js" tab="JS 插件">
|
|
||||||
<n-spin :show="jsLoading">
|
|
||||||
<n-empty v-if="!jsLoading && jsPlugins.length === 0" description="暂无 JS 插件" />
|
|
||||||
|
|
||||||
<n-grid v-else :cols="2" :x-gap="16" :y-gap="16" responsive="screen" cols-s="1">
|
|
||||||
<n-gi v-for="plugin in jsPlugins" :key="plugin.name">
|
|
||||||
<n-card hoverable>
|
|
||||||
<template #header>
|
|
||||||
<n-space align="center">
|
|
||||||
<n-icon size="24" color="#f0a020"><CodeSlashOutline /></n-icon>
|
|
||||||
<span>{{ plugin.name }}</span>
|
|
||||||
<n-tag v-if="plugin.version" size="small">v{{ plugin.version }}</n-tag>
|
|
||||||
</n-space>
|
|
||||||
</template>
|
|
||||||
<template #header-extra>
|
|
||||||
<n-switch :value="plugin.enabled" @update:value="toggleJSPlugin(plugin)" />
|
|
||||||
</template>
|
|
||||||
<n-space vertical :size="8">
|
|
||||||
<n-space>
|
|
||||||
<n-tag size="small" type="warning">JS</n-tag>
|
|
||||||
<n-tag v-if="plugin.auto_start" size="small" type="success">自动启动</n-tag>
|
|
||||||
<n-tag v-if="plugin.signature" size="small" type="info">已签名</n-tag>
|
|
||||||
</n-space>
|
|
||||||
<p style="margin: 0; color: #666;">{{ plugin.description || '无描述' }}</p>
|
|
||||||
<p v-if="plugin.author" style="margin: 0; color: #999; font-size: 12px;">作者: {{ plugin.author }}</p>
|
|
||||||
|
|
||||||
<!-- 配置预览 -->
|
|
||||||
<div v-if="Object.keys(plugin.config || {}).length > 0" style="margin-top: 8px;">
|
|
||||||
<p style="margin: 0 0 4px 0; color: #999; font-size: 12px;">配置:</p>
|
|
||||||
<n-space :size="4" wrap>
|
|
||||||
<n-tag v-for="(value, key) in plugin.config" :key="key" size="small" type="default">
|
|
||||||
{{ key }}: {{ value.length > 10 ? value.slice(0, 10) + '...' : value }}
|
|
||||||
</n-tag>
|
|
||||||
</n-space>
|
|
||||||
</div>
|
|
||||||
</n-space>
|
|
||||||
<template #action>
|
|
||||||
<n-space justify="space-between">
|
|
||||||
<n-button size="small" quaternary @click="openJSConfigModal(plugin)">
|
|
||||||
<template #icon><n-icon><SettingsOutline /></n-icon></template>
|
|
||||||
配置
|
|
||||||
</n-button>
|
|
||||||
<n-button
|
|
||||||
v-if="onlineClients.length > 0"
|
|
||||||
size="small"
|
|
||||||
type="primary"
|
|
||||||
@click="openPushModal(plugin)"
|
|
||||||
>
|
|
||||||
推送到客户端
|
|
||||||
</n-button>
|
|
||||||
</n-space>
|
|
||||||
</template>
|
|
||||||
</n-card>
|
|
||||||
</n-gi>
|
|
||||||
</n-grid>
|
|
||||||
</n-spin>
|
|
||||||
</n-tab-pane>
|
|
||||||
</n-tabs>
|
|
||||||
|
|
||||||
<!-- 安全加固:暂时禁用创建 JS 插件 Modal
|
|
||||||
<n-modal v-model:show="showJSModal" preset="card" title="新建 JS 插件" style="width: 600px;">
|
|
||||||
... 已屏蔽 ...
|
|
||||||
</n-modal>
|
|
||||||
-->
|
|
||||||
|
|
||||||
<!-- 安装商店插件模态框 -->
|
|
||||||
<n-modal v-model:show="showInstallModal" preset="card" title="安装插件" style="width: 450px;">
|
|
||||||
<n-space vertical :size="16">
|
|
||||||
<div v-if="selectedStorePlugin">
|
|
||||||
<p style="margin: 0 0 8px 0;"><strong>插件:</strong> {{ selectedStorePlugin.name }}</p>
|
|
||||||
<p style="margin: 0; color: #666;">{{ selectedStorePlugin.description }}</p>
|
|
||||||
</div>
|
|
||||||
<n-select
|
|
||||||
v-model:value="selectedClientId"
|
|
||||||
placeholder="选择要安装到的客户端"
|
|
||||||
:options="onlineClients.map(c => ({ label: c.nickname || c.id, value: c.id }))"
|
|
||||||
/>
|
|
||||||
<div>
|
|
||||||
<p style="margin: 0 0 8px 0; color: #666; font-size: 13px;">远程端口:</p>
|
|
||||||
<n-input-number
|
|
||||||
v-model:value="installRemotePort"
|
|
||||||
:min="1"
|
|
||||||
:max="65535"
|
|
||||||
placeholder="输入端口号"
|
|
||||||
style="width: 100%;"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<n-space align="center" :size="8">
|
|
||||||
<n-switch v-model:value="installAuthEnabled" />
|
|
||||||
<span style="color: #666;">启用 HTTP Basic Auth</span>
|
|
||||||
</n-space>
|
|
||||||
</div>
|
|
||||||
<template v-if="installAuthEnabled">
|
|
||||||
<n-input v-model:value="installAuthUsername" placeholder="用户名" />
|
|
||||||
<n-input v-model:value="installAuthPassword" type="password" placeholder="密码" show-password-on="click" />
|
|
||||||
</template>
|
|
||||||
</n-space>
|
|
||||||
<template #footer>
|
|
||||||
<n-space justify="end">
|
|
||||||
<n-button @click="showInstallModal = false">取消</n-button>
|
|
||||||
<n-button
|
|
||||||
type="primary"
|
|
||||||
:loading="installing"
|
|
||||||
:disabled="!selectedClientId"
|
|
||||||
@click="handleInstallStorePlugin"
|
|
||||||
>
|
|
||||||
安装
|
|
||||||
</n-button>
|
|
||||||
</n-space>
|
|
||||||
</template>
|
|
||||||
</n-modal>
|
|
||||||
|
|
||||||
<!-- JS 插件配置模态框 -->
|
|
||||||
<n-modal v-model:show="showJSConfigModal" preset="card" :title="`${currentJSPlugin?.name || ''} 配置`" style="width: 500px;">
|
|
||||||
<n-space vertical :size="12">
|
|
||||||
<p style="margin: 0; color: #666; font-size: 13px;">编辑插件配置参数(键值对形式)</p>
|
|
||||||
<div v-for="(item, index) in jsConfigItems" :key="index">
|
|
||||||
<n-space :size="8" align="center">
|
|
||||||
<n-input v-model:value="item.key" placeholder="参数名" style="width: 150px;" />
|
|
||||||
<n-input v-model:value="item.value" placeholder="参数值" style="width: 200px;" />
|
|
||||||
<n-button v-if="jsConfigItems.length > 1" quaternary type="error" size="small" @click="removeJSConfigItem(index)">
|
|
||||||
删除
|
|
||||||
</n-button>
|
|
||||||
</n-space>
|
|
||||||
</div>
|
|
||||||
<n-button dashed size="small" @click="addJSConfigItem">添加配置项</n-button>
|
|
||||||
</n-space>
|
|
||||||
<template #footer>
|
|
||||||
<n-space justify="end">
|
|
||||||
<n-button @click="showJSConfigModal = false">取消</n-button>
|
|
||||||
<n-button type="primary" :loading="jsConfigSaving" @click="saveJSPluginConfig">保存</n-button>
|
|
||||||
</n-space>
|
|
||||||
</template>
|
|
||||||
</n-modal>
|
|
||||||
|
|
||||||
<!-- JS 插件推送模态框 -->
|
|
||||||
<n-modal v-model:show="showPushModal" preset="card" title="推送插件到客户端" style="width: 400px;">
|
|
||||||
<n-space vertical :size="16">
|
|
||||||
<div v-if="selectedJSPlugin">
|
|
||||||
<p style="margin: 0 0 8px 0;"><strong>插件:</strong> {{ selectedJSPlugin.name }}</p>
|
|
||||||
<p style="margin: 0; color: #666;">{{ selectedJSPlugin.description || '无描述' }}</p>
|
|
||||||
</div>
|
|
||||||
<n-select
|
|
||||||
v-model:value="pushClientId"
|
|
||||||
placeholder="选择要推送到的客户端"
|
|
||||||
:options="onlineClients.map(c => ({ label: c.nickname || c.id, value: c.id }))"
|
|
||||||
/>
|
|
||||||
<div>
|
|
||||||
<p style="margin: 0 0 8px 0; color: #666; font-size: 13px;">远程端口(服务端监听端口):</p>
|
|
||||||
<n-input-number
|
|
||||||
v-model:value="pushRemotePort"
|
|
||||||
:min="1"
|
|
||||||
:max="65535"
|
|
||||||
placeholder="输入端口号"
|
|
||||||
style="width: 100%;"
|
|
||||||
/>
|
|
||||||
<p style="margin: 8px 0 0 0; color: #999; font-size: 12px;">用户可以通过 服务端IP:端口 访问此插件提供的服务</p>
|
|
||||||
</div>
|
|
||||||
</n-space>
|
|
||||||
<template #footer>
|
|
||||||
<n-space justify="end">
|
|
||||||
<n-button @click="showPushModal = false">取消</n-button>
|
|
||||||
<n-button
|
|
||||||
type="primary"
|
|
||||||
:loading="pushing"
|
|
||||||
:disabled="!pushClientId"
|
|
||||||
@click="handlePushJSPlugin"
|
|
||||||
>
|
|
||||||
推送
|
|
||||||
</n-button>
|
|
||||||
</n-space>
|
|
||||||
</template>
|
|
||||||
</n-modal>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
216
web/src/views/SettingsView.vue
Normal file
216
web/src/views/SettingsView.vue
Normal file
@@ -0,0 +1,216 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { onMounted, ref } from 'vue'
|
||||||
|
import MetricCard from '../components/MetricCard.vue'
|
||||||
|
import PageShell from '../components/PageShell.vue'
|
||||||
|
import SectionCard from '../components/SectionCard.vue'
|
||||||
|
import {
|
||||||
|
getServerConfig,
|
||||||
|
getVersionInfo,
|
||||||
|
updateServerConfig,
|
||||||
|
type ServerConfigResponse,
|
||||||
|
type UpdateServerConfigRequest,
|
||||||
|
type VersionInfo,
|
||||||
|
} from '../api'
|
||||||
|
import { useToast } from '../composables/useToast'
|
||||||
|
|
||||||
|
const message = useToast()
|
||||||
|
const versionInfo = ref<VersionInfo | null>(null)
|
||||||
|
const serverConfig = ref<ServerConfigResponse | null>(null)
|
||||||
|
const loadingVersion = ref(true)
|
||||||
|
const loadingConfig = ref(true)
|
||||||
|
const saving = ref(false)
|
||||||
|
|
||||||
|
const configForm = ref({
|
||||||
|
heartbeat_sec: 30,
|
||||||
|
heartbeat_timeout: 90,
|
||||||
|
web_username: '',
|
||||||
|
web_password: '',
|
||||||
|
})
|
||||||
|
|
||||||
|
const loadVersionInfo = async () => {
|
||||||
|
loadingVersion.value = true
|
||||||
|
try {
|
||||||
|
const { data } = await getVersionInfo()
|
||||||
|
versionInfo.value = data
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to load version info', error)
|
||||||
|
} finally {
|
||||||
|
loadingVersion.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const loadServerConfig = async () => {
|
||||||
|
loadingConfig.value = true
|
||||||
|
try {
|
||||||
|
const { data } = await getServerConfig()
|
||||||
|
serverConfig.value = data
|
||||||
|
configForm.value = {
|
||||||
|
heartbeat_sec: data.server.heartbeat_sec,
|
||||||
|
heartbeat_timeout: data.server.heartbeat_timeout,
|
||||||
|
web_username: data.web.username,
|
||||||
|
web_password: '',
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to load server config', error)
|
||||||
|
message.error('服务器配置加载失败')
|
||||||
|
} finally {
|
||||||
|
loadingConfig.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleSaveConfig = async () => {
|
||||||
|
saving.value = true
|
||||||
|
try {
|
||||||
|
const payload: UpdateServerConfigRequest = {
|
||||||
|
server: {
|
||||||
|
heartbeat_sec: configForm.value.heartbeat_sec,
|
||||||
|
heartbeat_timeout: configForm.value.heartbeat_timeout,
|
||||||
|
},
|
||||||
|
web: {
|
||||||
|
username: configForm.value.web_username,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
if (configForm.value.web_password) {
|
||||||
|
payload.web = {
|
||||||
|
...payload.web,
|
||||||
|
password: configForm.value.web_password,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await updateServerConfig(payload)
|
||||||
|
configForm.value.web_password = ''
|
||||||
|
message.success('配置已保存,部分配置需要重启后生效')
|
||||||
|
} catch (error: any) {
|
||||||
|
message.error(error.response?.data || '保存配置失败')
|
||||||
|
} finally {
|
||||||
|
saving.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
loadVersionInfo()
|
||||||
|
loadServerConfig()
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<PageShell title="系统设置" eyebrow="Settings" subtitle="统一整理运行版本与服务配置,减少样式重复并保留关键运维操作。">
|
||||||
|
<template #actions>
|
||||||
|
<button class="glass-btn" @click="loadVersionInfo">刷新版本</button>
|
||||||
|
<button class="glass-btn primary" :disabled="saving" @click="handleSaveConfig">{{ saving ? '保存中...' : '保存配置' }}</button>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template #metrics>
|
||||||
|
<MetricCard label="当前版本" :value="versionInfo?.version || '—'" :hint="versionInfo?.git_commit?.slice(0, 8) || '未知提交'" />
|
||||||
|
<MetricCard label="Go 版本" :value="versionInfo?.go_version || '—'" hint="运行时版本" tone="info" />
|
||||||
|
<MetricCard label="运行平台" :value="versionInfo ? `${versionInfo.os}/${versionInfo.arch}` : '—'" hint="服务端当前平台" tone="success" />
|
||||||
|
<MetricCard label="Web 用户名" :value="configForm.web_username || '—'" hint="控制台登录账号" tone="warning" />
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<div class="settings-grid">
|
||||||
|
<SectionCard title="版本信息" description="查看当前服务端构建信息,方便排查环境与升级状态。">
|
||||||
|
<div v-if="loadingVersion" class="empty-state">正在加载版本信息...</div>
|
||||||
|
<dl v-else-if="versionInfo" class="info-grid">
|
||||||
|
<div><dt>版本号</dt><dd>{{ versionInfo.version }}</dd></div>
|
||||||
|
<div><dt>Git 提交</dt><dd>{{ versionInfo.git_commit || 'N/A' }}</dd></div>
|
||||||
|
<div><dt>构建时间</dt><dd>{{ versionInfo.build_time || 'N/A' }}</dd></div>
|
||||||
|
<div><dt>Go 版本</dt><dd>{{ versionInfo.go_version }}</dd></div>
|
||||||
|
<div><dt>操作系统</dt><dd>{{ versionInfo.os }}</dd></div>
|
||||||
|
<div><dt>架构</dt><dd>{{ versionInfo.arch }}</dd></div>
|
||||||
|
</dl>
|
||||||
|
<div v-else class="empty-state">无法获取版本信息。</div>
|
||||||
|
</SectionCard>
|
||||||
|
|
||||||
|
<SectionCard title="服务配置" description="保留最常用的心跳与登录项配置,页面结构更精简。">
|
||||||
|
<div v-if="loadingConfig" class="empty-state">正在加载服务器配置...</div>
|
||||||
|
<form v-else class="config-form" @submit.prevent="handleSaveConfig">
|
||||||
|
<label class="form-group">
|
||||||
|
<span>心跳间隔(秒)</span>
|
||||||
|
<input v-model.number="configForm.heartbeat_sec" class="glass-input" min="1" max="300" type="number" />
|
||||||
|
</label>
|
||||||
|
<label class="form-group">
|
||||||
|
<span>心跳超时(秒)</span>
|
||||||
|
<input v-model.number="configForm.heartbeat_timeout" class="glass-input" min="1" max="600" type="number" />
|
||||||
|
</label>
|
||||||
|
<label class="form-group form-group--full">
|
||||||
|
<span>Web 用户名</span>
|
||||||
|
<input v-model="configForm.web_username" class="glass-input" type="text" placeholder="admin" />
|
||||||
|
</label>
|
||||||
|
<label class="form-group form-group--full">
|
||||||
|
<span>Web 密码</span>
|
||||||
|
<input v-model="configForm.web_password" class="glass-input" type="password" placeholder="留空则保持不变" />
|
||||||
|
</label>
|
||||||
|
</form>
|
||||||
|
</SectionCard>
|
||||||
|
</div>
|
||||||
|
</PageShell>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.settings-grid {
|
||||||
|
display: grid;
|
||||||
|
gap: 20px;
|
||||||
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||||
|
}
|
||||||
|
|
||||||
|
.info-grid {
|
||||||
|
display: grid;
|
||||||
|
gap: 14px;
|
||||||
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||||
|
}
|
||||||
|
|
||||||
|
.info-grid div,
|
||||||
|
.form-group {
|
||||||
|
padding: 16px;
|
||||||
|
border-radius: 16px;
|
||||||
|
background: var(--glass-bg-light);
|
||||||
|
border: 1px solid var(--color-border-light);
|
||||||
|
}
|
||||||
|
|
||||||
|
.info-grid dt,
|
||||||
|
.form-group span {
|
||||||
|
display: block;
|
||||||
|
margin-bottom: 8px;
|
||||||
|
color: var(--color-text-secondary);
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.info-grid dd {
|
||||||
|
color: var(--color-text-primary);
|
||||||
|
word-break: break-word;
|
||||||
|
}
|
||||||
|
|
||||||
|
.config-form {
|
||||||
|
display: grid;
|
||||||
|
gap: 14px;
|
||||||
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-group {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-group--full {
|
||||||
|
grid-column: 1 / -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.empty-state {
|
||||||
|
padding: 48px 20px;
|
||||||
|
text-align: center;
|
||||||
|
color: var(--color-text-secondary);
|
||||||
|
background: var(--glass-bg-light);
|
||||||
|
border: 1px dashed var(--color-border);
|
||||||
|
border-radius: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 960px) {
|
||||||
|
.settings-grid,
|
||||||
|
.info-grid,
|
||||||
|
.config-form {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -1,328 +0,0 @@
|
|||||||
<script setup lang="ts">
|
|
||||||
import { ref, onMounted, computed } from 'vue'
|
|
||||||
import { useRouter } from 'vue-router'
|
|
||||||
import {
|
|
||||||
NCard, NButton, NSpace, NTag, NGrid, NGi, NEmpty, NSpin, NIcon,
|
|
||||||
NAlert, NSelect, useMessage, useDialog
|
|
||||||
} from 'naive-ui'
|
|
||||||
import { ArrowBackOutline, CloudDownloadOutline, RefreshOutline, RocketOutline } from '@vicons/ionicons5'
|
|
||||||
import {
|
|
||||||
getVersionInfo, checkServerUpdate, checkClientUpdate, applyServerUpdate, applyClientUpdate,
|
|
||||||
getClients, type UpdateInfo, type VersionInfo
|
|
||||||
} from '../api'
|
|
||||||
import type { ClientStatus } from '../types'
|
|
||||||
|
|
||||||
const router = useRouter()
|
|
||||||
const message = useMessage()
|
|
||||||
const dialog = useDialog()
|
|
||||||
|
|
||||||
const versionInfo = ref<VersionInfo | null>(null)
|
|
||||||
const serverUpdate = ref<UpdateInfo | null>(null)
|
|
||||||
const clientUpdate = ref<UpdateInfo | null>(null)
|
|
||||||
const clients = ref<ClientStatus[]>([])
|
|
||||||
const loading = ref(true)
|
|
||||||
const checkingServer = ref(false)
|
|
||||||
const checkingClient = ref(false)
|
|
||||||
const updatingServer = ref(false)
|
|
||||||
const selectedClientId = ref('')
|
|
||||||
|
|
||||||
const onlineClients = computed(() => clients.value.filter(c => c.online))
|
|
||||||
|
|
||||||
const loadVersionInfo = async () => {
|
|
||||||
try {
|
|
||||||
const { data } = await getVersionInfo()
|
|
||||||
versionInfo.value = data
|
|
||||||
} catch (e) {
|
|
||||||
console.error('Failed to load version info', e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const loadClients = async () => {
|
|
||||||
try {
|
|
||||||
const { data } = await getClients()
|
|
||||||
clients.value = data || []
|
|
||||||
} catch (e) {
|
|
||||||
console.error('Failed to load clients', e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleCheckServerUpdate = async () => {
|
|
||||||
checkingServer.value = true
|
|
||||||
try {
|
|
||||||
const { data } = await checkServerUpdate()
|
|
||||||
serverUpdate.value = data
|
|
||||||
if (data.available) {
|
|
||||||
message.success('发现新版本: ' + data.latest)
|
|
||||||
} else {
|
|
||||||
message.info('已是最新版本')
|
|
||||||
}
|
|
||||||
} catch (e: any) {
|
|
||||||
message.error(e.response?.data || '检查更新失败')
|
|
||||||
} finally {
|
|
||||||
checkingServer.value = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleCheckClientUpdate = async () => {
|
|
||||||
checkingClient.value = true
|
|
||||||
try {
|
|
||||||
const { data } = await checkClientUpdate()
|
|
||||||
clientUpdate.value = data
|
|
||||||
if (data.download_url) {
|
|
||||||
message.success('找到客户端更新包: ' + data.latest)
|
|
||||||
} else {
|
|
||||||
message.warning('未找到对应平台的更新包')
|
|
||||||
}
|
|
||||||
} catch (e: any) {
|
|
||||||
message.error(e.response?.data || '检查更新失败')
|
|
||||||
} finally {
|
|
||||||
checkingClient.value = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleApplyServerUpdate = () => {
|
|
||||||
if (!serverUpdate.value?.download_url) {
|
|
||||||
message.error('没有可用的下载链接')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
dialog.warning({
|
|
||||||
title: '确认更新服务端',
|
|
||||||
content: `即将更新服务端到 ${serverUpdate.value.latest},更新后服务器将自动重启。确定要继续吗?`,
|
|
||||||
positiveText: '更新并重启',
|
|
||||||
negativeText: '取消',
|
|
||||||
onPositiveClick: async () => {
|
|
||||||
updatingServer.value = true
|
|
||||||
try {
|
|
||||||
await applyServerUpdate(serverUpdate.value!.download_url)
|
|
||||||
message.success('更新已开始,服务器将在几秒后重启')
|
|
||||||
// 显示倒计时或等待
|
|
||||||
setTimeout(() => {
|
|
||||||
window.location.reload()
|
|
||||||
}, 5000)
|
|
||||||
} catch (e: any) {
|
|
||||||
message.error(e.response?.data || '更新失败')
|
|
||||||
updatingServer.value = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleApplyClientUpdate = async () => {
|
|
||||||
if (!selectedClientId.value) {
|
|
||||||
message.warning('请选择要更新的客户端')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!clientUpdate.value?.download_url) {
|
|
||||||
message.error('没有可用的下载链接')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const clientName = onlineClients.value.find(c => c.id === selectedClientId.value)?.nickname || selectedClientId.value
|
|
||||||
|
|
||||||
dialog.warning({
|
|
||||||
title: '确认更新客户端',
|
|
||||||
content: `即将更新客户端 "${clientName}" 到 ${clientUpdate.value.latest},更新后客户端将自动重启。确定要继续吗?`,
|
|
||||||
positiveText: '更新',
|
|
||||||
negativeText: '取消',
|
|
||||||
onPositiveClick: async () => {
|
|
||||||
try {
|
|
||||||
await applyClientUpdate(selectedClientId.value, clientUpdate.value!.download_url)
|
|
||||||
message.success(`更新命令已发送到客户端 ${clientName}`)
|
|
||||||
} catch (e: any) {
|
|
||||||
message.error(e.response?.data || '更新失败')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const formatBytes = (bytes: number): string => {
|
|
||||||
if (bytes === 0) return '0 B'
|
|
||||||
const k = 1024
|
|
||||||
const sizes = ['B', 'KB', 'MB', 'GB']
|
|
||||||
const i = Math.floor(Math.log(bytes) / Math.log(k))
|
|
||||||
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i]
|
|
||||||
}
|
|
||||||
|
|
||||||
onMounted(async () => {
|
|
||||||
await Promise.all([loadVersionInfo(), loadClients()])
|
|
||||||
loading.value = false
|
|
||||||
})
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<div class="update-view">
|
|
||||||
<n-space justify="space-between" align="center" style="margin-bottom: 24px;">
|
|
||||||
<div>
|
|
||||||
<h2 style="margin: 0 0 8px 0;">系统更新</h2>
|
|
||||||
<p style="margin: 0; color: #666;">检查并应用服务端和客户端更新</p>
|
|
||||||
</div>
|
|
||||||
<n-button quaternary @click="router.push('/')">
|
|
||||||
<template #icon><n-icon><ArrowBackOutline /></n-icon></template>
|
|
||||||
返回首页
|
|
||||||
</n-button>
|
|
||||||
</n-space>
|
|
||||||
|
|
||||||
<n-spin :show="loading">
|
|
||||||
<!-- 当前版本信息 -->
|
|
||||||
<n-card title="当前版本" style="margin-bottom: 16px;">
|
|
||||||
<n-grid v-if="versionInfo" :cols="6" :x-gap="16" responsive="screen" cols-s="2" cols-m="3">
|
|
||||||
<n-gi>
|
|
||||||
<div class="info-item">
|
|
||||||
<span class="label">版本号</span>
|
|
||||||
<span class="value">{{ versionInfo.version }}</span>
|
|
||||||
</div>
|
|
||||||
</n-gi>
|
|
||||||
<n-gi>
|
|
||||||
<div class="info-item">
|
|
||||||
<span class="label">Git 提交</span>
|
|
||||||
<span class="value">{{ versionInfo.git_commit?.slice(0, 8) || 'N/A' }}</span>
|
|
||||||
</div>
|
|
||||||
</n-gi>
|
|
||||||
<n-gi>
|
|
||||||
<div class="info-item">
|
|
||||||
<span class="label">构建时间</span>
|
|
||||||
<span class="value">{{ versionInfo.build_time || 'N/A' }}</span>
|
|
||||||
</div>
|
|
||||||
</n-gi>
|
|
||||||
<n-gi>
|
|
||||||
<div class="info-item">
|
|
||||||
<span class="label">Go 版本</span>
|
|
||||||
<span class="value">{{ versionInfo.go_version }}</span>
|
|
||||||
</div>
|
|
||||||
</n-gi>
|
|
||||||
<n-gi>
|
|
||||||
<div class="info-item">
|
|
||||||
<span class="label">操作系统</span>
|
|
||||||
<span class="value">{{ versionInfo.os }}</span>
|
|
||||||
</div>
|
|
||||||
</n-gi>
|
|
||||||
<n-gi>
|
|
||||||
<div class="info-item">
|
|
||||||
<span class="label">架构</span>
|
|
||||||
<span class="value">{{ versionInfo.arch }}</span>
|
|
||||||
</div>
|
|
||||||
</n-gi>
|
|
||||||
</n-grid>
|
|
||||||
<n-empty v-else description="加载中..." />
|
|
||||||
</n-card>
|
|
||||||
|
|
||||||
<n-grid :cols="2" :x-gap="16" responsive="screen" cols-s="1">
|
|
||||||
<!-- 服务端更新 -->
|
|
||||||
<n-gi>
|
|
||||||
<n-card title="服务端更新">
|
|
||||||
<template #header-extra>
|
|
||||||
<n-button size="small" :loading="checkingServer" @click="handleCheckServerUpdate">
|
|
||||||
<template #icon><n-icon><RefreshOutline /></n-icon></template>
|
|
||||||
检查更新
|
|
||||||
</n-button>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<n-empty v-if="!serverUpdate" description="点击检查更新按钮查看是否有新版本" />
|
|
||||||
|
|
||||||
<template v-else>
|
|
||||||
<n-alert v-if="serverUpdate.available" type="success" style="margin-bottom: 16px;">
|
|
||||||
发现新版本 {{ serverUpdate.latest }},当前版本 {{ serverUpdate.current }}
|
|
||||||
</n-alert>
|
|
||||||
<n-alert v-else type="info" style="margin-bottom: 16px;">
|
|
||||||
当前已是最新版本 {{ serverUpdate.current }}
|
|
||||||
</n-alert>
|
|
||||||
|
|
||||||
<n-space vertical :size="12">
|
|
||||||
<div v-if="serverUpdate.download_url">
|
|
||||||
<p style="margin: 0 0 8px 0; color: #666;">
|
|
||||||
下载文件: {{ serverUpdate.asset_name }}
|
|
||||||
<n-tag size="small" style="margin-left: 8px;">{{ formatBytes(serverUpdate.asset_size) }}</n-tag>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div v-if="serverUpdate.release_note" style="max-height: 150px; overflow-y: auto;">
|
|
||||||
<p style="margin: 0 0 4px 0; color: #666; font-size: 12px;">更新日志:</p>
|
|
||||||
<pre style="margin: 0; white-space: pre-wrap; font-size: 12px; color: #333;">{{ serverUpdate.release_note }}</pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<n-button
|
|
||||||
v-if="serverUpdate.available && serverUpdate.download_url"
|
|
||||||
type="primary"
|
|
||||||
:loading="updatingServer"
|
|
||||||
@click="handleApplyServerUpdate"
|
|
||||||
>
|
|
||||||
<template #icon><n-icon><CloudDownloadOutline /></n-icon></template>
|
|
||||||
下载并更新服务端
|
|
||||||
</n-button>
|
|
||||||
</n-space>
|
|
||||||
</template>
|
|
||||||
</n-card>
|
|
||||||
</n-gi>
|
|
||||||
|
|
||||||
<!-- 客户端更新 -->
|
|
||||||
<n-gi>
|
|
||||||
<n-card title="客户端更新">
|
|
||||||
<template #header-extra>
|
|
||||||
<n-button size="small" :loading="checkingClient" @click="handleCheckClientUpdate">
|
|
||||||
<template #icon><n-icon><RefreshOutline /></n-icon></template>
|
|
||||||
检查更新
|
|
||||||
</n-button>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<n-empty v-if="!clientUpdate" description="点击检查更新按钮查看客户端更新" />
|
|
||||||
|
|
||||||
<template v-else>
|
|
||||||
<n-space vertical :size="12">
|
|
||||||
<div v-if="clientUpdate.download_url">
|
|
||||||
<p style="margin: 0 0 8px 0; color: #666;">
|
|
||||||
最新版本: {{ clientUpdate.latest }}
|
|
||||||
</p>
|
|
||||||
<p style="margin: 0 0 8px 0; color: #666;">
|
|
||||||
下载文件: {{ clientUpdate.asset_name }}
|
|
||||||
<n-tag size="small" style="margin-left: 8px;">{{ formatBytes(clientUpdate.asset_size) }}</n-tag>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<n-empty v-if="onlineClients.length === 0" description="没有在线的客户端" />
|
|
||||||
|
|
||||||
<template v-else>
|
|
||||||
<n-select
|
|
||||||
v-model:value="selectedClientId"
|
|
||||||
placeholder="选择要更新的客户端"
|
|
||||||
:options="onlineClients.map(c => ({ label: c.nickname || c.id, value: c.id }))"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<n-button
|
|
||||||
type="primary"
|
|
||||||
:disabled="!selectedClientId || !clientUpdate.download_url"
|
|
||||||
@click="handleApplyClientUpdate"
|
|
||||||
>
|
|
||||||
<template #icon><n-icon><RocketOutline /></n-icon></template>
|
|
||||||
推送更新到客户端
|
|
||||||
</n-button>
|
|
||||||
</template>
|
|
||||||
</n-space>
|
|
||||||
</template>
|
|
||||||
</n-card>
|
|
||||||
</n-gi>
|
|
||||||
</n-grid>
|
|
||||||
</n-spin>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<style scoped>
|
|
||||||
.info-item {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
padding: 8px 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.info-item .label {
|
|
||||||
font-size: 12px;
|
|
||||||
color: #999;
|
|
||||||
margin-bottom: 4px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.info-item .value {
|
|
||||||
font-size: 14px;
|
|
||||||
color: #333;
|
|
||||||
font-weight: 500;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
@@ -1,24 +1,10 @@
|
|||||||
import { defineConfig } from 'vite'
|
import { defineConfig } from 'vite'
|
||||||
import vue from '@vitejs/plugin-vue'
|
import vue from '@vitejs/plugin-vue'
|
||||||
import AutoImport from 'unplugin-auto-import/vite'
|
|
||||||
import Components from 'unplugin-vue-components/vite'
|
|
||||||
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers'
|
|
||||||
|
|
||||||
// https://vite.dev/config/
|
// https://vite.dev/config/
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [
|
plugins: [
|
||||||
vue(),
|
vue()
|
||||||
AutoImport({
|
|
||||||
imports: [
|
|
||||||
'vue',
|
|
||||||
{
|
|
||||||
'naive-ui': ['useDialog', 'useMessage', 'useNotification', 'useLoadingBar']
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}),
|
|
||||||
Components({
|
|
||||||
resolvers: [NaiveUiResolver()]
|
|
||||||
})
|
|
||||||
],
|
],
|
||||||
build: {
|
build: {
|
||||||
chunkSizeWarningLimit: 1500,
|
chunkSizeWarningLimit: 1500,
|
||||||
|
|||||||
Reference in New Issue
Block a user