Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6750103337 | ||
|
|
eaff3b8c39 | ||
|
|
c9a9807dd5 | ||
|
|
2b04bf8b5a | ||
|
|
62c84206a4 | ||
|
|
2650174eed | ||
|
|
d199b26ce2 | ||
|
|
0c25ec5978 | ||
|
|
055ff30e39 | ||
|
|
0f39cdbe7b | ||
|
|
4710432572 | ||
|
|
e0c8c73b91 |
@@ -1,27 +0,0 @@
|
||||
name: Android
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
release:
|
||||
types: [published]
|
||||
branches: [ master ]
|
||||
|
||||
jobs:
|
||||
|
||||
build_android:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check out code into the Go module directory
|
||||
uses: actions/checkout@v2
|
||||
- name: Build
|
||||
run: |
|
||||
chmod +x build.android.sh
|
||||
docker run --rm -i -w /app -v $(pwd):/app -e ANDROID_HOME=/usr/local/android_sdk -e GOPROXY=direct fyneio/fyne-cross:android-latest /app/build.android.sh
|
||||
- name: Upload
|
||||
uses: softprops/action-gh-release@v1
|
||||
if: startsWith(github.ref, 'refs/tags/')
|
||||
with:
|
||||
files: |
|
||||
android_client.apk
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
@@ -1,55 +0,0 @@
|
||||
name: Docker
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
release:
|
||||
types: [published]
|
||||
# branches: [ master ]
|
||||
tags: [v*]
|
||||
|
||||
jobs:
|
||||
build_docker:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
||||
- name: Check out code into the Go module directory
|
||||
uses: actions/checkout@v2
|
||||
- name: Set env
|
||||
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v1
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v1
|
||||
- name: Cache Docker layers
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: /tmp/.buildx-cache
|
||||
key: ${{ runner.os }}-buildx-${{ github.sha }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-buildx-
|
||||
- name: Login to DockerHub
|
||||
uses: docker/login-action@v1
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
- name: Build and push nps
|
||||
uses: docker/build-push-action@v2
|
||||
with:
|
||||
context: .
|
||||
file: ./Dockerfile.nps
|
||||
platforms: linux/amd64,linux/arm,linux/arm64
|
||||
push: true
|
||||
tags: |
|
||||
${{ secrets.DOCKERHUB_USERNAME }}/nps:latest
|
||||
${{ secrets.DOCKERHUB_USERNAME }}/nps:${{ env.RELEASE_VERSION }}
|
||||
- name: Build and push npc
|
||||
uses: docker/build-push-action@v2
|
||||
with:
|
||||
context: .
|
||||
file: ./Dockerfile.npc
|
||||
platforms: linux/amd64,linux/arm,linux/arm64
|
||||
push: true
|
||||
tags: |
|
||||
${{ secrets.DOCKERHUB_USERNAME }}/npc:latest
|
||||
${{ secrets.DOCKERHUB_USERNAME }}/npc:${{ env.RELEASE_VERSION }}
|
||||
@@ -2,9 +2,6 @@ name: Release
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
release:
|
||||
types: [published]
|
||||
branches: [ master ]
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
@@ -17,17 +14,15 @@ env:
|
||||
|
||||
jobs:
|
||||
|
||||
# ==================== 跨平台服务端/客户端打包 ====================
|
||||
build_assets:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
||||
- name: Set up Go 1.x
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: 1.22
|
||||
id: go
|
||||
- name: Check out code into the Go module directory
|
||||
go-version: "1.22"
|
||||
- name: Check out code
|
||||
uses: actions/checkout@v2
|
||||
- name: Get dependencies
|
||||
run: |
|
||||
@@ -84,10 +79,11 @@ jobs:
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
# ==================== Android APK ====================
|
||||
build_android:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check out code into the Go module directory
|
||||
- name: Check out code
|
||||
uses: actions/checkout@v4
|
||||
- name: Build
|
||||
run: |
|
||||
@@ -104,6 +100,52 @@ jobs:
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
# ==================== Docker 镜像 ====================
|
||||
build_docker:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check out code
|
||||
uses: actions/checkout@v2
|
||||
- name: Set env
|
||||
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v1
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v1
|
||||
- name: Cache Docker layers
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: /tmp/.buildx-cache
|
||||
key: ${{ runner.os }}-buildx-${{ github.sha }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-buildx-
|
||||
- name: Login to DockerHub
|
||||
uses: docker/login-action@v1
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
- name: Build and push nps
|
||||
uses: docker/build-push-action@v2
|
||||
with:
|
||||
context: .
|
||||
file: ./Dockerfile.nps
|
||||
platforms: linux/amd64,linux/arm,linux/arm64
|
||||
push: true
|
||||
tags: |
|
||||
${{ secrets.DOCKERHUB_USERNAME }}/nps:latest
|
||||
${{ secrets.DOCKERHUB_USERNAME }}/nps:${{ env.RELEASE_VERSION }}
|
||||
- name: Build and push npc
|
||||
uses: docker/build-push-action@v2
|
||||
with:
|
||||
context: .
|
||||
file: ./Dockerfile.npc
|
||||
platforms: linux/amd64,linux/arm,linux/arm64
|
||||
push: true
|
||||
tags: |
|
||||
${{ secrets.DOCKERHUB_USERNAME }}/npc:latest
|
||||
${{ secrets.DOCKERHUB_USERNAME }}/npc:${{ env.RELEASE_VERSION }}
|
||||
|
||||
# ==================== Windows GUI ====================
|
||||
build_windows_gui:
|
||||
runs-on: windows-latest
|
||||
strategy:
|
||||
@@ -121,40 +163,33 @@ jobs:
|
||||
steps:
|
||||
- name: Check out code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: "20"
|
||||
cache: yarn
|
||||
cache-dependency-path: ${{ env.FRONTEND_DIR }}/yarn.lock
|
||||
|
||||
- name: Enable Yarn (corepack)
|
||||
run: corepack enable
|
||||
|
||||
- name: Install frontend dependencies
|
||||
run: yarn install --frozen-lockfile
|
||||
working-directory: ${{ env.FRONTEND_DIR }}
|
||||
|
||||
- name: Build frontend
|
||||
run: yarn build
|
||||
working-directory: ${{ env.FRONTEND_DIR }}
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version-file: ${{ env.GUI_DIR }}/go.mod
|
||||
check-latest: true
|
||||
|
||||
- name: Install Wails CLI
|
||||
run: go install github.com/wailsapp/wails/v2/cmd/wails@${{ env.WAILS_VERSION }}
|
||||
working-directory: ${{ env.GUI_DIR }}
|
||||
|
||||
- name: Build and package (Windows)
|
||||
shell: pwsh
|
||||
working-directory: ${{ env.GUI_DIR }}
|
||||
run: |
|
||||
$wails = Join-Path (go env GOPATH) "bin\\wails.exe"
|
||||
$wails = Join-Path (go env GOPATH) "bin\wails.exe"
|
||||
$tagArgs = @()
|
||||
if ($env:WAILS_TAGS) { $tagArgs += @("-tags", $env:WAILS_TAGS) }
|
||||
& $wails build -m -s -trimpath -skipbindings @tagArgs -platform ${{ matrix.platform }} -o "$env:APP_NAME.exe"
|
||||
@@ -170,13 +205,13 @@ jobs:
|
||||
exit 1
|
||||
}
|
||||
Compress-Archive -Path $exe.Name -DestinationPath $zipName -Force
|
||||
|
||||
- name: Upload Windows artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: windows-builds-${{ matrix.arch }}
|
||||
path: ${{ env.GUI_DIR }}/build/bin/${{ env.APP_NAME }}-${{ matrix.os_name }}-${{ matrix.arch }}.zip
|
||||
|
||||
# ==================== macOS GUI ====================
|
||||
build_macos_gui:
|
||||
runs-on: macos-latest
|
||||
strategy:
|
||||
@@ -191,35 +226,28 @@ jobs:
|
||||
steps:
|
||||
- name: Check out code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: "20"
|
||||
cache: yarn
|
||||
cache-dependency-path: ${{ env.FRONTEND_DIR }}/yarn.lock
|
||||
|
||||
- name: Enable Yarn (corepack)
|
||||
run: corepack enable
|
||||
|
||||
- name: Install frontend dependencies
|
||||
run: yarn install --frozen-lockfile
|
||||
working-directory: ${{ env.FRONTEND_DIR }}
|
||||
|
||||
- name: Build frontend
|
||||
run: yarn build
|
||||
working-directory: ${{ env.FRONTEND_DIR }}
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version-file: ${{ env.GUI_DIR }}/go.mod
|
||||
check-latest: true
|
||||
|
||||
- name: Install Wails CLI
|
||||
run: go install github.com/wailsapp/wails/v2/cmd/wails@${{ env.WAILS_VERSION }}
|
||||
working-directory: ${{ env.GUI_DIR }}
|
||||
|
||||
- name: Build and package (macOS)
|
||||
shell: bash
|
||||
working-directory: ${{ env.GUI_DIR }}
|
||||
@@ -238,13 +266,13 @@ jobs:
|
||||
exit 1
|
||||
fi
|
||||
zip -q -r "$APP_NAME-${{ matrix.os_name }}-${{ matrix.arch }}.zip" "$app"
|
||||
|
||||
- name: Upload macOS artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: macos-builds-${{ matrix.arch }}
|
||||
path: ${{ env.GUI_DIR }}/build/bin/${{ env.APP_NAME }}-${{ matrix.os_name }}-${{ matrix.arch }}.zip
|
||||
|
||||
# ==================== Linux GUI ====================
|
||||
build_linux_gui:
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
@@ -258,40 +286,32 @@ jobs:
|
||||
steps:
|
||||
- name: Check out code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install Linux dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.1-dev
|
||||
|
||||
- name: Set up Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: "20"
|
||||
cache: yarn
|
||||
cache-dependency-path: ${{ env.FRONTEND_DIR }}/yarn.lock
|
||||
|
||||
- name: Enable Yarn (corepack)
|
||||
run: corepack enable
|
||||
|
||||
- name: Install frontend dependencies
|
||||
run: yarn install --frozen-lockfile
|
||||
working-directory: ${{ env.FRONTEND_DIR }}
|
||||
|
||||
- name: Build frontend
|
||||
run: yarn build
|
||||
working-directory: ${{ env.FRONTEND_DIR }}
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version-file: ${{ env.GUI_DIR }}/go.mod
|
||||
check-latest: true
|
||||
|
||||
- name: Install Wails CLI
|
||||
run: go install github.com/wailsapp/wails/v2/cmd/wails@${{ env.WAILS_VERSION }}
|
||||
working-directory: ${{ env.GUI_DIR }}
|
||||
|
||||
- name: Build and package (Linux)
|
||||
shell: bash
|
||||
working-directory: ${{ env.GUI_DIR }}
|
||||
@@ -310,13 +330,13 @@ jobs:
|
||||
exit 1
|
||||
fi
|
||||
zip -q "$APP_NAME-${{ matrix.os_name }}-${{ matrix.arch }}.zip" "$bin"
|
||||
|
||||
- name: Upload Linux artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: linux-builds-${{ matrix.arch }}
|
||||
path: ${{ env.GUI_DIR }}/build/bin/${{ env.APP_NAME }}-${{ matrix.os_name }}-${{ matrix.arch }}.zip
|
||||
|
||||
# ==================== GUI Release 上传 ====================
|
||||
upload_gui_release:
|
||||
runs-on: ubuntu-latest
|
||||
needs: [build_windows_gui, build_macos_gui, build_linux_gui]
|
||||
@@ -326,7 +346,6 @@ jobs:
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
path: release-assets
|
||||
|
||||
- name: Upload release assets
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
@@ -7,6 +7,5 @@ RUN CGO_ENABLED=0 go build -ldflags="-w -s -extldflags -static" ./cmd/nps/nps.go
|
||||
|
||||
FROM scratch
|
||||
COPY --from=builder /go/src/ehang.io/nps/nps /
|
||||
COPY --from=builder /go/src/ehang.io/nps/web /web
|
||||
VOLUME /conf
|
||||
CMD ["/nps"]
|
||||
|
||||
@@ -31,6 +31,20 @@
|
||||
|
||||
|
||||
# 更新日志
|
||||
- 2026-05-23 v0.26.33
|
||||
- 新增:
|
||||
- 配置文件自动生成:启动时若 conf 目录或 nps.conf 不存在,自动创建并写入默认配置,方便 Docker 部署
|
||||
- 首次启动默认 web_username/admin、web_password、auth_key、auth_crypt_key 均改为随机生成,并打印到终端,提升安全性
|
||||
- Web 静态文件打包进可执行文件 + 静态文件 URL 加入版本号参数,升级后自动刷新缓存,部署无需单独拷贝 web 目录
|
||||
- 精简发布包:去除打包时冗余的 conf/nps.conf、web 目录
|
||||
- 清理失效配置项:移除 appname、runmode、https_default_cert_file、https_default_key_file、https_just_proxy
|
||||
- 修复:
|
||||
- [#184](https://github.com/yisier/nps/issues/184) 限速导致隧道中断:UpdateClient 在 RateLimit=0 时创建零速率令牌桶导致永久阻塞
|
||||
- [#159](https://github.com/yisier/nps/issues/159) 关闭隧道端口仍可用:StopServer 错误时提前返回未更新状态 + 重复 OpenTask case 导致隧道被自动重启
|
||||
- [#170](https://github.com/yisier/nps/issues/170) TCP 负载均衡只有一个后端可达:GetRandomTarget 未处理 \r 换行符和尾部空行
|
||||
- [#319](https://github.com/yisier/nps/issues/319) 客户端列表不显示实时网速:NowRate 计算逻辑错误,改为统计每秒实际消耗字节数
|
||||
- [#306](https://github.com/yisier/nps/issues/306) [#316](https://github.com/yisier/nps/issues/316) TCP Basic 认证与域名解析冲突:移除 TCP 隧道 Basic 认证探测,域名解析继续使用客户端 Basic 认证
|
||||
|
||||
- 2026-03-27 v0.26.32
|
||||
- 修复:
|
||||
- 客户端注册参数未正确处理[快捷启动命令]和[TLS快捷启动命令] [#303](https://github.com/yisier/nps/issues/303)
|
||||
|
||||
+17
-17
@@ -85,83 +85,83 @@ tar -czvf darwin_arm64_client.tar.gz npc
|
||||
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/nps/nps.go
|
||||
|
||||
tar -czvf linux_amd64_server.tar.gz conf/nps.conf conf/tasks.json conf/clients.json conf/hosts.json conf/server.key conf/server.pem web/views web/static nps
|
||||
tar -czvf linux_amd64_server.tar.gz nps
|
||||
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=386 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/nps/nps.go
|
||||
|
||||
tar -czvf linux_386_server.tar.gz conf/nps.conf conf/tasks.json conf/clients.json conf/hosts.json conf/server.key conf/server.pem web/views web/static nps
|
||||
tar -czvf linux_386_server.tar.gz nps
|
||||
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=5 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/nps/nps.go
|
||||
|
||||
tar -czvf linux_arm_v5_server.tar.gz conf/nps.conf conf/tasks.json conf/clients.json conf/hosts.json conf/server.key conf/server.pem web/views web/static nps
|
||||
tar -czvf linux_arm_v5_server.tar.gz nps
|
||||
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=6 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/nps/nps.go
|
||||
|
||||
tar -czvf linux_arm_v6_server.tar.gz conf/nps.conf conf/tasks.json conf/clients.json conf/hosts.json conf/server.key conf/server.pem web/views web/static nps
|
||||
tar -czvf linux_arm_v6_server.tar.gz nps
|
||||
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=7 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/nps/nps.go
|
||||
|
||||
tar -czvf linux_arm_v7_server.tar.gz conf/nps.conf conf/tasks.json conf/clients.json conf/hosts.json conf/server.key conf/server.pem web/views web/static nps
|
||||
tar -czvf linux_arm_v7_server.tar.gz nps
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/nps/nps.go
|
||||
|
||||
tar -czvf linux_arm64_server.tar.gz conf/nps.conf conf/tasks.json conf/clients.json conf/hosts.json conf/server.key conf/server.pem web/views web/static nps
|
||||
tar -czvf linux_arm64_server.tar.gz nps
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=freebsd GOARCH=arm go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/nps/nps.go
|
||||
|
||||
tar -czvf freebsd_arm_server.tar.gz conf/nps.conf conf/tasks.json conf/clients.json conf/hosts.json conf/server.key conf/server.pem web/views web/static nps
|
||||
tar -czvf freebsd_arm_server.tar.gz nps
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=freebsd GOARCH=386 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/nps/nps.go
|
||||
|
||||
tar -czvf freebsd_386_server.tar.gz conf/nps.conf conf/tasks.json conf/clients.json conf/hosts.json conf/server.key conf/server.pem web/views web/static nps
|
||||
tar -czvf freebsd_386_server.tar.gz nps
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=freebsd GOARCH=amd64 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/nps/nps.go
|
||||
|
||||
tar -czvf freebsd_amd64_server.tar.gz conf/nps.conf conf/tasks.json conf/clients.json conf/hosts.json conf/server.key conf/server.pem web/views web/static nps
|
||||
tar -czvf freebsd_amd64_server.tar.gz nps
|
||||
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=mips go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/nps/nps.go
|
||||
|
||||
tar -czvf linux_mips_server.tar.gz conf/nps.conf conf/tasks.json conf/clients.json conf/hosts.json conf/server.key conf/server.pem web/views web/static nps
|
||||
tar -czvf linux_mips_server.tar.gz nps
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=mips64 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/nps/nps.go
|
||||
|
||||
tar -czvf linux_mips64_server.tar.gz conf/nps.conf conf/tasks.json conf/clients.json conf/hosts.json conf/server.key conf/server.pem web/views web/static nps
|
||||
tar -czvf linux_mips64_server.tar.gz nps
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=mips64le go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/nps/nps.go
|
||||
|
||||
tar -czvf linux_mips64le_server.tar.gz conf/nps.conf conf/tasks.json conf/clients.json conf/hosts.json conf/server.key conf/server.pem web/views web/static nps
|
||||
tar -czvf linux_mips64le_server.tar.gz nps
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=mipsle go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/nps/nps.go
|
||||
|
||||
tar -czvf linux_mipsle_server.tar.gz conf/nps.conf conf/tasks.json conf/clients.json conf/hosts.json conf/server.key conf/server.pem web/views web/static nps
|
||||
tar -czvf linux_mipsle_server.tar.gz nps
|
||||
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/nps/nps.go
|
||||
|
||||
tar -czvf darwin_amd64_server.tar.gz conf/nps.conf conf/tasks.json conf/clients.json conf/hosts.json conf/server.key conf/server.pem web/views web/static nps
|
||||
tar -czvf darwin_amd64_server.tar.gz nps
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/nps/nps.go
|
||||
|
||||
tar -czvf darwin_arm64_server.tar.gz conf/nps.conf conf/tasks.json conf/clients.json conf/hosts.json conf/server.key conf/server.pem web/views web/static nps
|
||||
tar -czvf darwin_arm64_server.tar.gz nps
|
||||
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/nps/nps.go
|
||||
|
||||
tar -czvf windows_amd64_server.tar.gz conf/nps.conf conf/tasks.json conf/clients.json conf/hosts.json conf/server.key conf/server.pem web/views web/static nps.exe
|
||||
tar -czvf windows_amd64_server.tar.gz nps.exe
|
||||
|
||||
|
||||
CGO_ENABLED=0 GOOS=windows GOARCH=386 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/nps/nps.go
|
||||
|
||||
tar -czvf windows_386_server.tar.gz conf/nps.conf conf/tasks.json conf/clients.json conf/hosts.json conf/server.key conf/server.pem web/views web/static nps.exe
|
||||
tar -czvf windows_386_server.tar.gz nps.exe
|
||||
@@ -1,5 +1,5 @@
|
||||
#/bash/sh
|
||||
export VERSION=0.26.32
|
||||
export VERSION=0.26.33
|
||||
export GOPROXY=direct
|
||||
|
||||
sudo apt-get update
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
},
|
||||
"info": {
|
||||
"productName": "NPS Client",
|
||||
"productVersion": "0.26.32",
|
||||
"productVersion": "0.26.33",
|
||||
"companyName": "NPS",
|
||||
"copyright": "Copyright © 2026 NPS"
|
||||
},
|
||||
|
||||
@@ -26,6 +26,7 @@ import (
|
||||
|
||||
"ehang.io/nps/lib/common"
|
||||
"ehang.io/nps/lib/crypt"
|
||||
"ehang.io/nps/web"
|
||||
"github.com/astaxie/beego"
|
||||
"github.com/astaxie/beego/logs"
|
||||
|
||||
@@ -72,6 +73,9 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
// auto-generate default config files if not exist
|
||||
initConfig(filepath.Join(common.GetRunPath(), "conf"))
|
||||
|
||||
if err := beego.LoadAppConfig("ini", filepath.Join(common.GetRunPath(), "conf", "nps.conf")); err != nil {
|
||||
log.Fatalln("load config file error", err.Error())
|
||||
}
|
||||
@@ -444,3 +448,83 @@ func run() {
|
||||
}
|
||||
go server.StartNewServer(bridgePort, task, beego.AppConfig.String("bridge_type"), timeout)
|
||||
}
|
||||
|
||||
func initConfig(confDir string) {
|
||||
if !common.FileExists(confDir) {
|
||||
os.MkdirAll(confDir, 0755)
|
||||
}
|
||||
confPath := filepath.Join(confDir, "nps.conf")
|
||||
if !common.FileExists(confPath) {
|
||||
webPassword := crypt.GetRandomString(8)
|
||||
authKey := crypt.GetRandomString(8)
|
||||
authCryptKey := crypt.GetRandomString(16)
|
||||
content := strings.Replace(defaultNpsConf, "web_password=123", "web_password="+webPassword, 1)
|
||||
content = strings.Replace(content, "auth_key=123", "auth_key="+authKey, 1)
|
||||
content = strings.Replace(content, "auth_crypt_key =213", "auth_crypt_key ="+authCryptKey, 1)
|
||||
f, err := os.Create(confPath)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer f.Close()
|
||||
f.WriteString(content)
|
||||
logs.Info("Auto-generated default config file:", confPath)
|
||||
logs.Info("Web login username: admin, password:", webPassword)
|
||||
logs.Info("auth_key:", authKey)
|
||||
logs.Info("auth_crypt_key:", authCryptKey)
|
||||
}
|
||||
web.ExtractWebFiles(common.GetRunPath())
|
||||
}
|
||||
|
||||
const defaultNpsConf = `http_proxy_ip=0.0.0.0
|
||||
http_proxy_port=80
|
||||
https_proxy_port=443
|
||||
show_http_proxy_port=true
|
||||
|
||||
bridge_type=tcp
|
||||
bridge_port=8024
|
||||
bridge_ip=0.0.0.0
|
||||
|
||||
public_vkey=123
|
||||
|
||||
flow_store_interval=1
|
||||
|
||||
log_level=6
|
||||
log_path=nps.log
|
||||
|
||||
web_host=a.o.com
|
||||
web_username=admin
|
||||
web_password=123
|
||||
web_port = 8081
|
||||
web_ip=0.0.0.0
|
||||
web_base_url=
|
||||
web_open_ssl=false
|
||||
web_cert_file=conf/server.pem
|
||||
web_key_file=conf/server.key
|
||||
|
||||
auth_key=123
|
||||
auth_crypt_key =213
|
||||
|
||||
allow_user_login=true
|
||||
allow_user_register=false
|
||||
allow_user_change_username=true
|
||||
|
||||
allow_flow_limit=true
|
||||
allow_rate_limit=true
|
||||
allow_tunnel_num_limit=true
|
||||
allow_local_proxy=false
|
||||
allow_connection_num_limit=true
|
||||
allow_multi_ip=true
|
||||
system_info_display=true
|
||||
|
||||
http_add_origin_header=true
|
||||
|
||||
http_cache=false
|
||||
http_cache_length=100
|
||||
|
||||
disconnect_timeout=60
|
||||
|
||||
open_captcha=false
|
||||
|
||||
tls_enable=true
|
||||
tls_bridge_port=8025
|
||||
`
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
{"Cnf":{"U":"","P":"","Compress":false,"Crypt":false},"Id":2,"VerifyKey":"aceecc399e","Addr":"127.0.0.1","Remark":"","Status":true,"IsConnect":true,"RateLimit":0,"Flow":{"ExportFlow":7888065,"InletFlow":7888065,"FlowLimit":0},"Rate":{"NowRate":17179869184},"NoStore":false,"NoDisplay":false,"MaxConn":0,"NowConn":0,"WebUserName":"","WebPassword":"","ConfigConnAllow":true,"MaxTunnelNum":0,"Version":"0.26.19","BlackIpList":[],"CreateTime":"2026-05-14 16:37:55","LastOnlineTime":"2026-05-14 17:30:13","IpWhite":false,"IpWhitePass":"","IpWhiteList":[]}
|
||||
*#*
|
||||
+3
-10
@@ -1,16 +1,9 @@
|
||||
appname = nps
|
||||
#Boot mode(dev|pro)
|
||||
runmode = dev
|
||||
|
||||
#HTTP(S) proxy port, no startup if empty
|
||||
http_proxy_ip=0.0.0.0
|
||||
http_proxy_port=80
|
||||
https_proxy_port=443
|
||||
https_just_proxy=true
|
||||
#default https certificate setting
|
||||
https_default_cert_file=conf/server.pem
|
||||
https_default_key_file=conf/server.key
|
||||
|
||||
# 是否展示非【80】端口
|
||||
show_http_proxy_port=true
|
||||
##bridge
|
||||
bridge_type=tcp
|
||||
bridge_port=8024
|
||||
@@ -99,4 +92,4 @@ open_captcha=false
|
||||
|
||||
# 是否开启tls
|
||||
tls_enable=true
|
||||
tls_bridge_port=8025
|
||||
tls_bridge_port=8025
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
MIIEpAIBAAKCAQEA2MVLOHvgU8FCp6LgQrPfaWcGygrsRk7TL9hbT8MxbCRUSLV7
|
||||
Lbt3q5Knz8eTN4NWmwE6L5glOcH2x3Hnn+hPjbvgq35XBBIccAm0cYYKqoKkikeK
|
||||
FZM0Gp/WhSrhJ4laTyQqyleIFKpwD9kHDiC/sxjGDhSFmHKhhAnsQIRm2tppFXX0
|
||||
aAMqJEm88jzk1BN2QtKjEAn1u8v1+QW1KP3WuzdXH4L7hhMll66/KIm6Hfs2FRHQ
|
||||
pRUWqZeJY4q79NW5p5f+siGwOsGpxb/p11pM+0xnCH3UIFbm3zCTzP4sLvkfFGAe
|
||||
yAHsAwmaP8dJxh40ej3NN8uNiNvt8nw2Vb/1LwIDAQABAoIBAD40x/RKoEKIyE8B
|
||||
D6g0pB1EQo+CePFoN3SYewO1uR4WgtVmtxWVoa7r5BpdZGLe3uCWhpMX7z7W6bGs
|
||||
f1LFQOckjkHIfMIfTGfecRjO5Yqu+Pbxtq+gUah+S/plJr3IzdC+SUVNvzBnBMeX
|
||||
eU3Vmg2UQ2nQ+9GWu8D/c/vDwxx0X8oQ2G8QaxX0tUurlSMNA3M7xySwEvhx54fO
|
||||
UrDF3Q4yF48eA4butxVLFWf3cnlY+nR8uYd2vKfmp689/8C6kkfoM9igB78e93sm
|
||||
uDM2eRLm4kU5WLl301T42n6AF7w8J0MhLLVOIeLs4l5gZPa3uKvYFmuHQao7e/5R
|
||||
U/jHKrECgYEA8alPXuxFSVOvdhIsSN//Frj9CdExVdYmaLkt/2LO4FMnOaWh1xh7
|
||||
5iCY1bJT8D9dhfbqRg3qW2oguZD8gu04R8fTRegQ89qmAIwsEYqVf9salR41lZU4
|
||||
Rc+5yc7O11WIe9Lzu+ONFBFkAh3UFMR4zVZ/JhKIG/P5Srm7SUdKW2cCgYEA5aHo
|
||||
x2LR+yKhjkrBzHG3Qrfy1PtlYHjOpYYAKHQcBFuiG08W3CK/vkYl+mhv0uyhT7mn
|
||||
q6NDqrpZPRnDlOoEqgRS1X/QWKN6Pgd4HNLIawvp0vK9jYXDPcAXFzVthXCIwFcn
|
||||
3a3m4cHiuLdRNOHkydiHQyTOF6eEneN07TDvwvkCgYEApzOd1u9igPmFzQuF2GYi
|
||||
+HXFnaU/nUQuDwcQ7EJRIKRn31raPxiRoQesty5LJU6yRp4wOYgnPliPi9Tk4TGA
|
||||
XynC4/tMv2vorzhMxVY9Wdke602bhYNZC/RNd3O/aP2lEQdD3Bv04I2nxE8fDb9i
|
||||
VbAjCRSJV83WDf2zt1+78sECgYEAzezjRiKdcZu9y0/I+WEk2cUCE/MaF2he0FsZ
|
||||
uy1cjp/qAJltQ5452xUnK6cKWNlxU4CHF0mC/hC8xCldliZCZoEYE3PaUBLSJdwm
|
||||
35o6tpxpZI3gZJCG5NJlIp/8BkVDrVC7ZHV17hAkFEf4n/bPaB8wNYtE8jt8luaK
|
||||
TcarzGkCgYBn2alN0RLN2PHDurraFZB6GuCvh/arEjSCY3SDFQPF10CVjTDV7sx3
|
||||
eqJkwJ81syTmfJwZIceWbOFGgsuSx37UrQAVlHZSvzeqEg9dA5HqSoOACyidJI7j
|
||||
RG2+HB+KpsIZjGgLrEM4i7VOpYUDRdaouIXngFq/t9HNT+MDck5/Lw==
|
||||
-----END RSA PRIVATE KEY-----
|
||||
@@ -1,22 +0,0 @@
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIDtTCCAp2gAwIBAgIJAPXRSiP0Fs7sMA0GCSqGSIb3DQEBBQUAMEUxCzAJBgNV
|
||||
BAYTAkFVMRMwEQYDVQQIEwpTb21lLVN0YXRlMSEwHwYDVQQKExhJbnRlcm5ldCBX
|
||||
aWRnaXRzIFB0eSBMdGQwHhcNMTcxMTA3MDg1MzQ2WhcNMjcxMTA1MDg1MzQ2WjBF
|
||||
MQswCQYDVQQGEwJBVTETMBEGA1UECBMKU29tZS1TdGF0ZTEhMB8GA1UEChMYSW50
|
||||
ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB
|
||||
CgKCAQEA2MVLOHvgU8FCp6LgQrPfaWcGygrsRk7TL9hbT8MxbCRUSLV7Lbt3q5Kn
|
||||
z8eTN4NWmwE6L5glOcH2x3Hnn+hPjbvgq35XBBIccAm0cYYKqoKkikeKFZM0Gp/W
|
||||
hSrhJ4laTyQqyleIFKpwD9kHDiC/sxjGDhSFmHKhhAnsQIRm2tppFXX0aAMqJEm8
|
||||
8jzk1BN2QtKjEAn1u8v1+QW1KP3WuzdXH4L7hhMll66/KIm6Hfs2FRHQpRUWqZeJ
|
||||
Y4q79NW5p5f+siGwOsGpxb/p11pM+0xnCH3UIFbm3zCTzP4sLvkfFGAeyAHsAwma
|
||||
P8dJxh40ej3NN8uNiNvt8nw2Vb/1LwIDAQABo4GnMIGkMB0GA1UdDgQWBBQdPc0R
|
||||
a8alY6Ab7voidkTGaH4PxzB1BgNVHSMEbjBsgBQdPc0Ra8alY6Ab7voidkTGaH4P
|
||||
x6FJpEcwRTELMAkGA1UEBhMCQVUxEzARBgNVBAgTClNvbWUtU3RhdGUxITAfBgNV
|
||||
BAoTGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZIIJAPXRSiP0Fs7sMAwGA1UdEwQF
|
||||
MAMBAf8wDQYJKoZIhvcNAQEFBQADggEBAH1IZNkjuvt2nZPzXsuiVNyCE1vm346z
|
||||
naE0Uzt3aseAN9m/iiB8mLz+ryvWc2aFMX5lTdsHdm2rqmqBCBXeRwTLf4OeHIju
|
||||
ZQW6makWt6PxANEo6gbdPbQXbS420ssUhnR2irIH1SdI31iikVFPdiS0baRRE/gS
|
||||
+440M1jOOOnKm0Qin92ejsshmji/0qaD2+6D5TNw4HmIZaFTBw+kfjxCL6trfeBn
|
||||
4fT0RJ121V3G3+AtG5sWQ93B3pCg+jtD+fGKkNSLhphq84bD1Zv7l73QGOoylkEn
|
||||
Sc0ajTLOXFBb83yRdlgV3Da95jH9rDZ4jSod48m+KemoZTDQw0vSwAU=
|
||||
-----END CERTIFICATE-----
|
||||
@@ -0,0 +1,2 @@
|
||||
{"Id":1,"Port":33833,"ServerIp":"0.0.0.0","Mode":"tcp","Status":true,"RunStatus":true,"Client":{"Cnf":{"U":"","P":"","Compress":false,"Crypt":false},"Id":2,"VerifyKey":"aceecc399e","Addr":"127.0.0.1","Remark":"","Status":true,"IsConnect":true,"RateLimit":0,"Flow":{"ExportFlow":7888065,"InletFlow":7888065,"FlowLimit":0},"Rate":{"NowRate":0},"NoStore":false,"NoDisplay":false,"MaxConn":0,"NowConn":0,"WebUserName":"","WebPassword":"","ConfigConnAllow":true,"MaxTunnelNum":0,"Version":"0.26.19","BlackIpList":[],"CreateTime":"2026-05-14 16:37:55","LastOnlineTime":"2026-05-14 17:30:13","IpWhite":false,"IpWhitePass":"","IpWhiteList":[]},"Ports":"","Flow":{"ExportFlow":0,"InletFlow":0,"FlowLimit":0},"Password":"","Remark":"","TargetAddr":"","NoStore":false,"LocalPath":"","StripPre":"","ProtoVersion":"","Target":{"TargetStr":"192.168.225.103:8081","TargetArr":["192.168.225.103:8081"],"LocalProxy":false},"MultiAccount":null,"HealthCheckTimeout":0,"HealthMaxFail":0,"HealthCheckInterval":0,"HealthNextTime":"0001-01-01T00:00:00Z","HealthMap":null,"HttpHealthUrl":"","HealthRemoveArr":null,"HealthCheckType":"","HealthCheckTarget":""}
|
||||
*#*
|
||||
+5
-3
@@ -39,10 +39,10 @@ func (s *Conn) readRequest(buf []byte) (n int, err error) {
|
||||
var rd int
|
||||
for {
|
||||
rd, err = s.Read(buf[n:])
|
||||
n += rd
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
n += rd
|
||||
if n < 4 {
|
||||
continue
|
||||
}
|
||||
@@ -61,10 +61,12 @@ func (s *Conn) readRequest(buf []byte) (n int, err error) {
|
||||
func (s *Conn) GetHost() (method, address string, rb []byte, err error, r *http.Request) {
|
||||
var b [32 * 1024]byte
|
||||
var n int
|
||||
if n, err = s.readRequest(b[:]); err != nil {
|
||||
if n, err = s.readRequest(b[:]); n > 0 {
|
||||
rb = b[:n]
|
||||
}
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
rb = b[:n]
|
||||
r, err = http.ReadRequest(bufio.NewReader(bytes.NewReader(rb)))
|
||||
if err != nil {
|
||||
return
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
package conn
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"net"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
type bytesThenErrConn struct {
|
||||
net.Conn
|
||||
payload []byte
|
||||
err error
|
||||
read bool
|
||||
}
|
||||
|
||||
func (c *bytesThenErrConn) Read(b []byte) (int, error) {
|
||||
if c.read {
|
||||
return 0, c.err
|
||||
}
|
||||
c.read = true
|
||||
return copy(b, c.payload), c.err
|
||||
}
|
||||
|
||||
func TestGetHostReturnsBufferedBytesOnReadError(t *testing.T) {
|
||||
clientConn, serverConn := net.Pipe()
|
||||
defer clientConn.Close()
|
||||
defer serverConn.Close()
|
||||
|
||||
payload := []byte("SSH-2.0-OpenSSH_9.0\r\n")
|
||||
if err := serverConn.SetReadDeadline(time.Now().Add(50 * time.Millisecond)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
type result struct {
|
||||
rb []byte
|
||||
err error
|
||||
}
|
||||
done := make(chan result, 1)
|
||||
go func() {
|
||||
_, _, rb, err, _ := NewConn(serverConn).GetHost()
|
||||
done <- result{rb: rb, err: err}
|
||||
}()
|
||||
|
||||
if _, err := clientConn.Write(payload); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
select {
|
||||
case got := <-done:
|
||||
if got.err == nil {
|
||||
t.Fatal("expected GetHost to fail for non-HTTP payload")
|
||||
}
|
||||
if !bytes.Equal(got.rb, payload) {
|
||||
t.Fatalf("expected buffered payload %q, got %q", payload, got.rb)
|
||||
}
|
||||
case <-time.After(time.Second):
|
||||
t.Fatal("GetHost did not return after read deadline")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetHostReturnsBufferedBytesWhenReadReturnsBytesAndError(t *testing.T) {
|
||||
payload := []byte("SSH-2.0-OpenSSH_9.0\r\n")
|
||||
c := &bytesThenErrConn{
|
||||
payload: payload,
|
||||
err: io.ErrUnexpectedEOF,
|
||||
}
|
||||
|
||||
_, _, rb, err, _ := NewConn(c).GetHost()
|
||||
if err == nil {
|
||||
t.Fatal("expected GetHost to fail for non-HTTP payload")
|
||||
}
|
||||
if !bytes.Equal(rb, payload) {
|
||||
t.Fatalf("expected buffered payload %q, got %q", payload, rb)
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -273,7 +273,7 @@ func (s *DbUtils) VerifyUserName(username string, id int) (res bool) {
|
||||
func (s *DbUtils) UpdateClient(t *Client) error {
|
||||
s.JsonDb.Clients.Store(t.Id, t)
|
||||
if t.RateLimit == 0 {
|
||||
t.Rate = rate.NewRate(0)
|
||||
t.Rate = rate.NewRate(int64((2 << 23) * 1024))
|
||||
t.Rate.Start()
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -158,6 +158,9 @@ func (s *JsonDb) GetHostId() int32 {
|
||||
}
|
||||
|
||||
func loadSyncMapFromFile(filePath string, f func(value string)) {
|
||||
if !common.FileExists(filePath) {
|
||||
return
|
||||
}
|
||||
b, err := common.ReadAllFromFile(filePath)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
||||
+13
-7
@@ -207,22 +207,28 @@ type MultiAccount struct {
|
||||
}
|
||||
|
||||
func (s *Target) GetRandomTarget() (string, error) {
|
||||
s.Lock()
|
||||
if s.TargetArr == nil {
|
||||
s.TargetArr = strings.Split(s.TargetStr, "\n")
|
||||
}
|
||||
if len(s.TargetArr) == 1 {
|
||||
return s.TargetArr[0], nil
|
||||
arr := strings.Split(s.TargetStr, "\n")
|
||||
s.TargetArr = make([]string, 0, len(arr))
|
||||
for _, v := range arr {
|
||||
v = strings.TrimRight(v, "\r")
|
||||
if v != "" {
|
||||
s.TargetArr = append(s.TargetArr, v)
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(s.TargetArr) == 0 {
|
||||
s.Unlock()
|
||||
return "", errors.New("all inward-bending targets are offline")
|
||||
}
|
||||
s.Lock()
|
||||
defer s.Unlock()
|
||||
if s.nowIndex >= len(s.TargetArr)-1 {
|
||||
s.nowIndex = -1
|
||||
}
|
||||
s.nowIndex++
|
||||
return s.TargetArr[s.nowIndex], nil
|
||||
addr := s.TargetArr[s.nowIndex]
|
||||
s.Unlock()
|
||||
return addr, nil
|
||||
}
|
||||
|
||||
type Glob struct {
|
||||
|
||||
+4
-3
@@ -2,6 +2,7 @@ package rate
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
xrate "golang.org/x/time/rate"
|
||||
@@ -11,6 +12,7 @@ type Rate struct {
|
||||
limiter *xrate.Limiter
|
||||
addSize int64
|
||||
stopChan chan struct{}
|
||||
consumed int64
|
||||
NowRate int64
|
||||
}
|
||||
|
||||
@@ -19,7 +21,6 @@ func NewRate(addSize int64) *Rate {
|
||||
limiter: xrate.NewLimiter(xrate.Limit(addSize), int(addSize)),
|
||||
addSize: addSize,
|
||||
stopChan: make(chan struct{}),
|
||||
NowRate: addSize,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +31,7 @@ func (s *Rate) Start() {
|
||||
for {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
s.NowRate = s.addSize - (int64(s.limiter.Tokens()))
|
||||
s.NowRate = atomic.SwapInt64(&s.consumed, 0)
|
||||
case <-s.stopChan:
|
||||
return
|
||||
}
|
||||
@@ -55,5 +56,5 @@ func (s *Rate) Get(size int64) {
|
||||
}
|
||||
ctx := context.Background()
|
||||
_ = s.limiter.WaitN(ctx, int(size))
|
||||
s.NowRate = s.addSize - (int64(s.limiter.Tokens()))
|
||||
atomic.AddInt64(&s.consumed, size)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package version
|
||||
|
||||
const VERSION = "0.26.32"
|
||||
const VERSION = "0.26.33"
|
||||
|
||||
// Compulsory minimum version, Minimum downward compatibility to this version
|
||||
func GetVersion() string {
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"ehang.io/nps/bridge"
|
||||
"ehang.io/nps/lib/common"
|
||||
@@ -107,23 +106,6 @@ func ProcessTunnel(c *conn.Conn, s *TunnelModeServer) error {
|
||||
logs.Warn("tcp port %d ,client id %d,task id %d connect error %s", s.task.Port, s.task.Client.Id, s.task.Id, err.Error())
|
||||
return err
|
||||
}
|
||||
|
||||
if s.task.Client.Cnf.U != "" && s.task.Client.Cnf.P != "" {
|
||||
c.Conn.SetReadDeadline(time.Now().Add(time.Millisecond * 200))
|
||||
_, _, rb, err, r := c.GetHost()
|
||||
c.Conn.SetReadDeadline(time.Time{})
|
||||
|
||||
if err == nil && !common.CheckAuth(r, s.task.Client.Cnf.U, s.task.Client.Cnf.P) {
|
||||
c.Write([]byte(common.UnauthorizedBytes))
|
||||
c.Close()
|
||||
return errors.New("401 Unauthorized")
|
||||
}
|
||||
if err == nil {
|
||||
return s.DealClient(c, s.task.Client, targetAddr, rb, common.CONN_TCP,
|
||||
nil, s.task.Client.Flow, s.task.Target.LocalProxy, s.task)
|
||||
}
|
||||
}
|
||||
|
||||
return s.DealClient(c, s.task.Client, targetAddr, nil, common.CONN_TCP, nil, s.task.Client.Flow, s.task.Target.LocalProxy, s.task)
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
package proxy
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"ehang.io/nps/lib/common"
|
||||
"ehang.io/nps/lib/conn"
|
||||
"ehang.io/nps/lib/file"
|
||||
)
|
||||
|
||||
type tunnelTestBridge struct {
|
||||
target net.Conn
|
||||
}
|
||||
|
||||
func (b *tunnelTestBridge) SendLinkInfo(clientId int, link *conn.Link, t *file.Tunnel) (net.Conn, error) {
|
||||
return b.target, nil
|
||||
}
|
||||
|
||||
func TestProcessTunnelForwardsBufferedBytesWhenAuthProbeFails(t *testing.T) {
|
||||
confPath := t.TempDir()
|
||||
confDir := filepath.Join(confPath, "conf")
|
||||
if err := os.MkdirAll(confDir, 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, name := range []string{"clients.json", "tasks.json", "hosts.json"} {
|
||||
if err := os.WriteFile(filepath.Join(confDir, name), nil, 0644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
oldConfPath := common.ConfPath
|
||||
common.ConfPath = confPath
|
||||
t.Cleanup(func() {
|
||||
common.ConfPath = oldConfPath
|
||||
})
|
||||
|
||||
clientConn, serverConn := net.Pipe()
|
||||
defer clientConn.Close()
|
||||
defer serverConn.Close()
|
||||
|
||||
targetClient, targetServer := net.Pipe()
|
||||
defer targetClient.Close()
|
||||
defer targetServer.Close()
|
||||
|
||||
client := file.NewClient("test", true, true)
|
||||
client.Id = 1
|
||||
client.Cnf.U = "user"
|
||||
client.Cnf.P = "pass"
|
||||
task := &file.Tunnel{
|
||||
Id: 1,
|
||||
Client: client,
|
||||
Target: &file.Target{
|
||||
TargetStr: "127.0.0.1:22",
|
||||
},
|
||||
}
|
||||
server := NewTunnelModeServer(ProcessTunnel, &tunnelTestBridge{target: targetServer}, task)
|
||||
|
||||
done := make(chan error, 1)
|
||||
go func() {
|
||||
done <- ProcessTunnel(conn.NewConn(serverConn), server)
|
||||
}()
|
||||
|
||||
payload := []byte("SSH-2.0-OpenSSH_9.0\r\n")
|
||||
if _, err := clientConn.Write(payload); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := targetClient.SetReadDeadline(time.Now().Add(time.Second)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got := make([]byte, len(payload))
|
||||
if _, err := io.ReadFull(targetClient, got); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !bytes.Equal(got, payload) {
|
||||
t.Fatalf("expected forwarded payload %q, got %q", payload, got)
|
||||
}
|
||||
|
||||
clientConn.Close()
|
||||
targetClient.Close()
|
||||
select {
|
||||
case err := <-done:
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
case <-time.After(time.Second):
|
||||
t.Fatal("ProcessTunnel did not exit after connections closed")
|
||||
}
|
||||
}
|
||||
+195
-56
@@ -5,6 +5,7 @@ import (
|
||||
"net"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"ehang.io/nps/bridge"
|
||||
@@ -14,20 +15,51 @@ import (
|
||||
"github.com/astaxie/beego/logs"
|
||||
)
|
||||
|
||||
const (
|
||||
udpSessionIdleTimeout = 120 * time.Second
|
||||
udpSweepInterval = 30 * time.Second
|
||||
udpReadDeadline = 60 * time.Second
|
||||
udpBuildTimeout = 5 * time.Second
|
||||
)
|
||||
|
||||
// udpSession 代表一个客户端 src addr ↔ npc 之间的 UDP 转发会话。
|
||||
//
|
||||
// 同一个 src addr 在并发场景下可能被多个 goroutine 同时尝试建立会话。为避免
|
||||
// 重复建立,采用"原子占位"模式:第一个 goroutine 通过 sync.Map.LoadOrStore
|
||||
// 占位(此时 ready 通道未关闭),后续 goroutine 检测到占位后阻塞在 ready
|
||||
// 通道上等待会话就绪,然后复用同一个 target 转发数据。这样:
|
||||
// - 同一 src addr 始终只有 1 条到 npc 的 mux stream
|
||||
// - 只有"赢家"消耗一个 NowConn 配额,输家不再重复占用
|
||||
// - 避免了 race window 期间的 NowConn 配额泄漏
|
||||
type udpSession struct {
|
||||
target io.ReadWriteCloser // 用于 Read/Write 的封装层(可能含加密/压缩)
|
||||
rawConn net.Conn // 底层 mux conn,用于 SetReadDeadline
|
||||
lastActive int64 // 最近活跃时间(unix nano,原子读写)
|
||||
ready chan struct{} // 会话就绪后关闭;建立失败时也关闭
|
||||
err error // 建立失败时设置;ready 关闭后才允许读
|
||||
}
|
||||
|
||||
func (u *udpSession) touch() {
|
||||
atomic.StoreInt64(&u.lastActive, time.Now().UnixNano())
|
||||
}
|
||||
|
||||
type UdpModeServer struct {
|
||||
BaseServer
|
||||
addrMap sync.Map
|
||||
listener *net.UDPConn
|
||||
addrMap sync.Map
|
||||
listener *net.UDPConn
|
||||
closeOnce sync.Once
|
||||
closeCh chan struct{}
|
||||
}
|
||||
|
||||
func NewUdpModeServer(bridge *bridge.Bridge, task *file.Tunnel) *UdpModeServer {
|
||||
s := new(UdpModeServer)
|
||||
s.bridge = bridge
|
||||
s.task = task
|
||||
s.closeCh = make(chan struct{})
|
||||
return s
|
||||
}
|
||||
|
||||
// 开始
|
||||
// Start 启动 UDP 监听,主循环只负责快速收包并分发,不做任何耗时操作。
|
||||
func (s *UdpModeServer) Start() error {
|
||||
var err error
|
||||
if s.task.ServerIp == "" {
|
||||
@@ -37,90 +69,197 @@ func (s *UdpModeServer) Start() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
go s.sweeper()
|
||||
for {
|
||||
buf := common.BufPoolUdp.Get().([]byte)
|
||||
n, addr, err := s.listener.ReadFromUDP(buf)
|
||||
if err != nil {
|
||||
common.BufPoolUdp.Put(buf)
|
||||
if strings.Contains(err.Error(), "use of closed network connection") {
|
||||
break
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
// 判断访问地址是否在全局黑名单内
|
||||
if IsGlobalBlackIp(addr.String()) {
|
||||
break
|
||||
common.BufPoolUdp.Put(buf)
|
||||
continue
|
||||
}
|
||||
|
||||
// 判断访问地址是否在黑名单内
|
||||
if common.IsBlackIp(addr.String(), s.task.Client.VerifyKey, s.task.Client.BlackIpList) {
|
||||
break
|
||||
common.BufPoolUdp.Put(buf)
|
||||
continue
|
||||
}
|
||||
|
||||
logs.Trace("New udp connection,client %d,remote address %s", s.task.Client.Id, addr)
|
||||
go s.process(addr, buf[:n])
|
||||
go s.process(addr, buf, n)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *UdpModeServer) process(addr *net.UDPAddr, data []byte) {
|
||||
if v, ok := s.addrMap.Load(addr.String()); ok {
|
||||
clientConn, ok := v.(io.ReadWriteCloser)
|
||||
if ok {
|
||||
_, err := clientConn.Write(data)
|
||||
if err != nil {
|
||||
logs.Warn(err)
|
||||
// process 处理单个 UDP 包。函数持有 buf 的所有权,所有路径必须归还。
|
||||
func (s *UdpModeServer) process(addr *net.UDPAddr, buf []byte, n int) {
|
||||
key := addr.String()
|
||||
data := buf[:n]
|
||||
|
||||
// 快路径:会话已存在
|
||||
if v, ok := s.addrMap.Load(key); ok {
|
||||
s.dispatch(key, v.(*udpSession), data, n)
|
||||
common.BufPoolUdp.Put(buf)
|
||||
return
|
||||
}
|
||||
|
||||
// 慢路径:尝试成为该 key 的"会话建立者"
|
||||
placeholder := &udpSession{ready: make(chan struct{})}
|
||||
placeholder.touch()
|
||||
if existing, loaded := s.addrMap.LoadOrStore(key, placeholder); loaded {
|
||||
// 输了占位竞争,等赢家把会话建好后复用
|
||||
s.dispatch(key, existing.(*udpSession), data, n)
|
||||
common.BufPoolUdp.Put(buf)
|
||||
return
|
||||
}
|
||||
|
||||
// 赢得占位 —— 我去建立会话
|
||||
s.runSession(addr, key, placeholder, buf, n)
|
||||
}
|
||||
|
||||
// dispatch 把数据写入 sess.target。若 sess 仍在建立中则阻塞等待,超时则丢包。
|
||||
func (s *UdpModeServer) dispatch(key string, sess *udpSession, data []byte, n int) {
|
||||
if sess.ready != nil {
|
||||
select {
|
||||
case <-sess.ready:
|
||||
if sess.err != nil {
|
||||
logs.Trace("udp session build failed for %s: %v", key, sess.err)
|
||||
return
|
||||
}
|
||||
s.task.Client.Flow.Add(int64(len(data)), int64(len(data)))
|
||||
}
|
||||
} else {
|
||||
if err := s.CheckFlowAndConnNum(s.task.Client); err != nil {
|
||||
logs.Warn("client id %d, task id %d,error %s, when udp connection", s.task.Client.Id, s.task.Id, err.Error())
|
||||
case <-time.After(udpBuildTimeout):
|
||||
logs.Warn("udp session build timeout for %s, drop packet", key)
|
||||
return
|
||||
case <-s.closeCh:
|
||||
return
|
||||
}
|
||||
defer s.task.Client.AddConn()
|
||||
link := conn.NewLink(common.CONN_UDP, s.task.Target.TargetStr, s.task.Client.Cnf.Crypt, s.task.Client.Cnf.Compress, addr.String(), s.task.Target.LocalProxy, "")
|
||||
if clientConn, err := s.bridge.SendLinkInfo(s.task.Client.Id, link, s.task); err != nil {
|
||||
}
|
||||
if _, err := sess.target.Write(data); err != nil {
|
||||
logs.Warn(err)
|
||||
s.removeSession(key, sess)
|
||||
return
|
||||
}
|
||||
sess.touch()
|
||||
s.task.Client.Flow.Add(int64(n), int64(n))
|
||||
}
|
||||
|
||||
// runSession 由占位赢家执行:建立到 npc 的 stream、发送首包、运行下行读循环。
|
||||
// buf 由本函数负责归还。
|
||||
func (s *UdpModeServer) runSession(addr *net.UDPAddr, key string, sess *udpSession, buf []byte, n int) {
|
||||
data := buf[:n]
|
||||
|
||||
// 失败时统一清理:关 ready 通道唤醒所有输家、删占位、归还 buf。
|
||||
failBuild := func(err error) {
|
||||
sess.err = err
|
||||
close(sess.ready)
|
||||
s.addrMap.Delete(key)
|
||||
common.BufPoolUdp.Put(buf)
|
||||
}
|
||||
|
||||
if err := s.CheckFlowAndConnNum(s.task.Client); err != nil {
|
||||
logs.Warn("client id %d, task id %d,error %s, when udp connection", s.task.Client.Id, s.task.Id, err.Error())
|
||||
failBuild(err)
|
||||
return
|
||||
}
|
||||
// 只有赢家消耗 NowConn 配额,函数返回时释放。
|
||||
defer s.task.Client.AddConn()
|
||||
|
||||
link := conn.NewLink(common.CONN_UDP, s.task.Target.TargetStr, s.task.Client.Cnf.Crypt, s.task.Client.Cnf.Compress, addr.String(), s.task.Target.LocalProxy, "")
|
||||
clientConn, err := s.bridge.SendLinkInfo(s.task.Client.Id, link, s.task)
|
||||
if err != nil {
|
||||
failBuild(err)
|
||||
return
|
||||
}
|
||||
|
||||
target := conn.GetConn(clientConn, s.task.Client.Cnf.Crypt, s.task.Client.Cnf.Compress, nil, true)
|
||||
sess.target = target
|
||||
sess.rawConn = clientConn
|
||||
sess.touch()
|
||||
close(sess.ready) // 唤醒所有等待该会话的输家
|
||||
|
||||
defer s.removeSession(key, sess)
|
||||
|
||||
logs.Trace("New udp connection,client %d,remote address %s", s.task.Client.Id, addr)
|
||||
|
||||
if _, err := target.Write(data); err != nil {
|
||||
logs.Warn(err)
|
||||
common.BufPoolUdp.Put(buf)
|
||||
return
|
||||
}
|
||||
common.BufPoolUdp.Put(buf)
|
||||
s.task.Client.Flow.Add(int64(n), int64(n))
|
||||
|
||||
// 下行读循环
|
||||
rbuf := common.BufPoolUdp.Get().([]byte)
|
||||
defer common.BufPoolUdp.Put(rbuf)
|
||||
|
||||
for {
|
||||
// 设到 rawConn 上:mux stream 的 SetReadDeadline 是底层 net.Conn 实现,
|
||||
// 比设在加密/压缩包装层 target 上更可靠。
|
||||
clientConn.SetReadDeadline(time.Now().Add(udpReadDeadline))
|
||||
rn, err := target.Read(rbuf)
|
||||
if err != nil {
|
||||
// sweeper 主动 Close、idle deadline 触发、或对端断开都会落到这里
|
||||
return
|
||||
} else {
|
||||
target := conn.GetConn(clientConn, s.task.Client.Cnf.Crypt, s.task.Client.Cnf.Compress, nil, true)
|
||||
s.addrMap.Store(addr.String(), target)
|
||||
defer target.Close()
|
||||
}
|
||||
sess.touch()
|
||||
if _, err := s.listener.WriteTo(rbuf[:rn], addr); err != nil {
|
||||
logs.Warn(err)
|
||||
return
|
||||
}
|
||||
s.task.Client.Flow.Add(int64(rn), int64(rn))
|
||||
}
|
||||
}
|
||||
|
||||
_, err := target.Write(data)
|
||||
if err != nil {
|
||||
logs.Warn(err)
|
||||
return
|
||||
}
|
||||
// removeSession 安全地从 addrMap 移除并关闭会话。
|
||||
// 用 == 比对避免误删被替换的新 session(虽然当前协议不会发生,但保持防御性)。
|
||||
func (s *UdpModeServer) removeSession(key string, sess *udpSession) {
|
||||
if v, ok := s.addrMap.Load(key); ok && v.(*udpSession) == sess {
|
||||
s.addrMap.Delete(key)
|
||||
}
|
||||
if sess.target != nil {
|
||||
sess.target.Close()
|
||||
}
|
||||
}
|
||||
|
||||
buf := common.BufPoolUdp.Get().([]byte)
|
||||
defer common.BufPoolUdp.Put(buf)
|
||||
|
||||
s.task.Client.Flow.Add(int64(len(data)), int64(len(data)))
|
||||
for {
|
||||
clientConn.SetReadDeadline(time.Now().Add(time.Duration(60) * time.Second))
|
||||
if n, err := target.Read(buf); err != nil {
|
||||
s.addrMap.Delete(addr.String())
|
||||
logs.Warn(err)
|
||||
return
|
||||
} else {
|
||||
_, err := s.listener.WriteTo(buf[:n], addr)
|
||||
if err != nil {
|
||||
logs.Warn(err)
|
||||
return
|
||||
}
|
||||
s.task.Client.Flow.Add(int64(n), int64(n))
|
||||
// sweeper 周期性扫描 addrMap,把空闲超过 udpSessionIdleTimeout 的会话清掉。
|
||||
// 关闭 target 会让阻塞中的 target.Read 立即返回错误,让对应的 runSession
|
||||
// 走 defer 链路自然退出(释放 NowConn 配额、删 addrMap 条目)。
|
||||
func (s *UdpModeServer) sweeper() {
|
||||
ticker := time.NewTicker(udpSweepInterval)
|
||||
defer ticker.Stop()
|
||||
idleNs := int64(udpSessionIdleTimeout)
|
||||
for {
|
||||
select {
|
||||
case <-s.closeCh:
|
||||
return
|
||||
case <-ticker.C:
|
||||
now := time.Now().UnixNano()
|
||||
s.addrMap.Range(func(k, v interface{}) bool {
|
||||
sess := v.(*udpSession)
|
||||
// 跳过仍在建立中的占位(target 尚未填充)
|
||||
if sess.target == nil {
|
||||
return true
|
||||
}
|
||||
//if err := s.CheckFlowAndConnNum(s.task.Client); err != nil {
|
||||
// logs.Warn("client id %d, task id %d,error %s, when udp connection", s.task.Client.Id, s.task.Id, err.Error())
|
||||
// return
|
||||
//}
|
||||
}
|
||||
if now-atomic.LoadInt64(&sess.lastActive) > idleNs {
|
||||
s.removeSession(k.(string), sess)
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *UdpModeServer) Close() error {
|
||||
s.closeOnce.Do(func() {
|
||||
close(s.closeCh)
|
||||
})
|
||||
s.addrMap.Range(func(k, v interface{}) bool {
|
||||
s.removeSession(k.(string), v.(*udpSession))
|
||||
return true
|
||||
})
|
||||
return s.listener.Close()
|
||||
}
|
||||
|
||||
+4
-11
@@ -57,7 +57,7 @@ func DealBridgeTask() {
|
||||
for {
|
||||
select {
|
||||
case t := <-Bridge.OpenTask:
|
||||
AddTask(t)
|
||||
StartTask(t.Id)
|
||||
case t := <-Bridge.CloseTask:
|
||||
StopServer(t.Id)
|
||||
case id := <-Bridge.CloseClient:
|
||||
@@ -67,8 +67,6 @@ func DealBridgeTask() {
|
||||
file.GetDb().DelClient(id)
|
||||
}
|
||||
}
|
||||
case tunnel := <-Bridge.OpenTask:
|
||||
StartTask(tunnel.Id)
|
||||
case s := <-Bridge.SecretChan:
|
||||
logs.Trace("New secret connection, addr", s.Conn.Conn.RemoteAddr())
|
||||
if t := file.GetDb().GetTaskByMd5Password(s.Password); t != nil {
|
||||
@@ -160,25 +158,20 @@ func NewMode(Bridge *bridge.Bridge, c *file.Tunnel) proxy.Service {
|
||||
|
||||
// stop server
|
||||
func StopServer(id int) error {
|
||||
//if v, ok := RunList[id]; ok {
|
||||
if v, ok := RunList.Load(id); ok {
|
||||
if svr, ok := v.(proxy.Service); ok {
|
||||
if err := svr.Close(); err != nil {
|
||||
return err
|
||||
logs.Error("stop server id %d error", id, err)
|
||||
}
|
||||
logs.Info("stop server id %d", id)
|
||||
} else {
|
||||
logs.Warn("stop server id %d error", id)
|
||||
}
|
||||
if t, err := file.GetDb().GetTask(id); err != nil {
|
||||
return err
|
||||
} else {
|
||||
RunList.Delete(id)
|
||||
if t, err := file.GetDb().GetTask(id); err == nil {
|
||||
t.Status = false
|
||||
logs.Info("close port %d,remark %s,client id %d,task id %d", t.Port, t.Remark, t.Client.Id, t.Id)
|
||||
file.GetDb().UpdateTask(t)
|
||||
}
|
||||
//delete(RunList, id)
|
||||
RunList.Delete(id)
|
||||
return nil
|
||||
}
|
||||
return errors.New("task is not running")
|
||||
|
||||
@@ -1,84 +0,0 @@
|
||||
package test
|
||||
|
||||
import (
|
||||
"log"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
|
||||
"ehang.io/nps/lib/common"
|
||||
"ehang.io/nps/lib/file"
|
||||
"github.com/astaxie/beego"
|
||||
)
|
||||
|
||||
func TestServerConfig() {
|
||||
var postTcpArr []int
|
||||
var postUdpArr []int
|
||||
file.GetDb().JsonDb.Tasks.Range(func(key, value interface{}) bool {
|
||||
v := value.(*file.Tunnel)
|
||||
if v.Mode == "udp" {
|
||||
isInArr(&postUdpArr, v.Port, v.Remark, "udp")
|
||||
} else if v.Port != 0 {
|
||||
|
||||
isInArr(&postTcpArr, v.Port, v.Remark, "tcp")
|
||||
}
|
||||
return true
|
||||
})
|
||||
p, err := beego.AppConfig.Int("web_port")
|
||||
if err != nil {
|
||||
log.Fatalln("Getting web management port error :", err)
|
||||
} else {
|
||||
isInArr(&postTcpArr, p, "Web Management port", "tcp")
|
||||
}
|
||||
|
||||
if p := beego.AppConfig.String("bridge_port"); p != "" {
|
||||
if port, err := strconv.Atoi(p); err != nil {
|
||||
log.Fatalln("get Server and client communication portserror:", err)
|
||||
} else if beego.AppConfig.String("bridge_type") == "kcp" {
|
||||
isInArr(&postUdpArr, port, "Server and client communication ports", "udp")
|
||||
} else {
|
||||
isInArr(&postTcpArr, port, "Server and client communication ports", "tcp")
|
||||
}
|
||||
}
|
||||
|
||||
if p := beego.AppConfig.String("httpProxyPort"); p != "" {
|
||||
if port, err := strconv.Atoi(p); err != nil {
|
||||
log.Fatalln("get http port error:", err)
|
||||
} else {
|
||||
isInArr(&postTcpArr, port, "https port", "tcp")
|
||||
}
|
||||
}
|
||||
if p := beego.AppConfig.String("https_proxy_port"); p != "" {
|
||||
if b, err := beego.AppConfig.Bool("https_just_proxy"); !(err == nil && b) {
|
||||
if port, err := strconv.Atoi(p); err != nil {
|
||||
log.Fatalln("get https port error", err)
|
||||
} else {
|
||||
if beego.AppConfig.String("pemPath") != "" && !common.FileExists(filepath.Join(common.GetRunPath(), beego.AppConfig.String("pemPath"))) {
|
||||
log.Fatalf("ssl certFile %s is not exist", beego.AppConfig.String("pemPath"))
|
||||
}
|
||||
if beego.AppConfig.String("keyPath") != "" && !common.FileExists(filepath.Join(common.GetRunPath(), beego.AppConfig.String("keyPath"))) {
|
||||
log.Fatalf("ssl keyFile %s is not exist", beego.AppConfig.String("pemPath"))
|
||||
}
|
||||
isInArr(&postTcpArr, port, "http port", "tcp")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func isInArr(arr *[]int, val int, remark string, tp string) {
|
||||
for _, v := range *arr {
|
||||
if v == val {
|
||||
log.Fatalf("the port %d is reused,remark: %s", val, remark)
|
||||
}
|
||||
}
|
||||
if tp == "tcp" {
|
||||
if !common.TestTcpPort(val) {
|
||||
log.Fatalf("open the %d port error ,remark: %s", val, remark)
|
||||
}
|
||||
} else {
|
||||
if !common.TestUdpPort(val) {
|
||||
log.Fatalf("open the %d port error ,remark: %s", val, remark)
|
||||
}
|
||||
}
|
||||
*arr = append(*arr, val)
|
||||
return
|
||||
}
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"ehang.io/nps/lib/common"
|
||||
"ehang.io/nps/lib/crypt"
|
||||
"ehang.io/nps/lib/file"
|
||||
"ehang.io/nps/lib/version"
|
||||
"ehang.io/nps/server"
|
||||
"github.com/astaxie/beego"
|
||||
)
|
||||
@@ -55,7 +56,6 @@ func (s *BaseController) Prepare() {
|
||||
} else {
|
||||
s.Data["isAdmin"] = true
|
||||
}
|
||||
s.Data["https_just_proxy"], _ = beego.AppConfig.Bool("https_just_proxy")
|
||||
s.Data["allow_user_login"], _ = beego.AppConfig.Bool("allow_user_login")
|
||||
s.Data["allow_flow_limit"], _ = beego.AppConfig.Bool("allow_flow_limit")
|
||||
s.Data["allow_rate_limit"], _ = beego.AppConfig.Bool("allow_rate_limit")
|
||||
@@ -65,9 +65,10 @@ func (s *BaseController) Prepare() {
|
||||
s.Data["allow_tunnel_num_limit"], _ = beego.AppConfig.Bool("allow_tunnel_num_limit")
|
||||
s.Data["allow_local_proxy"], _ = beego.AppConfig.Bool("allow_local_proxy")
|
||||
s.Data["allow_user_change_username"], _ = beego.AppConfig.Bool("allow_user_change_username")
|
||||
showHttpProxyPort := beego.AppConfig.DefaultBool("show_http_proxy_port", true)
|
||||
httpPort := beego.AppConfig.String("http_proxy_port")
|
||||
if httpPort != "80" {
|
||||
s.Data["http_proxy_port"] = ":" + beego.AppConfig.String("http_proxy_port")
|
||||
if httpPort != "80" && showHttpProxyPort {
|
||||
s.Data["http_proxy_port"] = ":" + httpPort
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,10 +98,13 @@ func (s *BaseController) display(tpl ...string) {
|
||||
|
||||
s.Data["bridgeType"] = beego.AppConfig.String("bridge_type")
|
||||
if common.IsWindows() {
|
||||
s.Data["win"] = ".exe"
|
||||
s.Data["win"] = "npc.exe"
|
||||
} else {
|
||||
s.Data["win"] = "./npc"
|
||||
}
|
||||
|
||||
s.Data["p"] = strconv.Itoa(server.Bridge.TunnelPort)
|
||||
s.Data["version"] = version.VERSION
|
||||
|
||||
if bridge.ServerTlsEnable {
|
||||
tlsPort := strconv.Itoa(beego.AppConfig.DefaultInt("tls_bridge_port", 8025))
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"ehang.io/nps/lib/common"
|
||||
"github.com/astaxie/beego/logs"
|
||||
)
|
||||
|
||||
//go:embed static
|
||||
var StaticFS embed.FS
|
||||
|
||||
//go:embed views
|
||||
var ViewsFS embed.FS
|
||||
|
||||
func ExtractWebFiles(runPath string) {
|
||||
webDir := filepath.Join(runPath, "web")
|
||||
staticDir := filepath.Join(webDir, "static")
|
||||
viewsDir := filepath.Join(webDir, "views")
|
||||
|
||||
if !common.FileExists(staticDir) {
|
||||
extractFS(StaticFS, "static", webDir)
|
||||
logs.Info("Extracted embedded web/static to", staticDir)
|
||||
}
|
||||
if !common.FileExists(viewsDir) {
|
||||
extractFS(ViewsFS, "views", webDir)
|
||||
logs.Info("Extracted embedded web/views to", viewsDir)
|
||||
}
|
||||
}
|
||||
|
||||
func extractFS(efs embed.FS, root string, destDir string) {
|
||||
fs.WalkDir(efs, ".", func(path string, d fs.DirEntry, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
targetPath := filepath.Join(destDir, path)
|
||||
if d.IsDir() {
|
||||
os.MkdirAll(targetPath, 0755)
|
||||
return nil
|
||||
}
|
||||
data, err := efs.ReadFile(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
os.MkdirAll(filepath.Dir(targetPath), 0755)
|
||||
os.WriteFile(targetPath, data, 0644)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
@@ -76,8 +76,8 @@
|
||||
+ '<b langtag="word-lastonlinetime"></b>: ' + row.LastOnlineTime + ' <br/><br/>'
|
||||
+ '<b langtag="word-quicklycommand"></b>: <span>' + encodeToBase64(row.Remark +'|'+'{{.ip}}:{{.p}}|' + row.VerifyKey + '|false') + '</span> <button class="copy btn btn-info btn-xs" onclick="copyCommand(this)" data-clipboard-text="">复制</button><br/>'
|
||||
+ '<b langtag="word-tlsquicklycommand"></b>: <span>' + encodeToBase64(row.Remark +'|'+'{{.ip}}:{{.tls_p}}|' + row.VerifyKey + '|true') + '</span> <button class="copy btn btn-info btn-xs" onclick="copyCommand(this)" data-clipboard-text="">复制</button><br/>'
|
||||
+ '<b langtag="word-commandclient"></b>: ' + "<code>./npc{{.win}} -server={{.ip}}:{{.p}} -vkey=" + row.VerifyKey + " -type=" +{{.bridgeType}} +"</code><button class=\"copy btn btn-info btn-xs\" onclick=\"copyCommand(this)\" data-clipboard-text=\"\">复制</button><br/>"
|
||||
+ '<b langtag="word-commandclient-tls"></b>: ' + "<code>./npc{{.win}} -server={{.ip}}:{{.tls_p}} -vkey=" + row.VerifyKey + " -tls_enable=true</code><button class=\"copy btn btn-info btn-xs\" onclick=\"copyCommand(this)\" data-clipboard-text=\"\">复制</button>"
|
||||
+ '<b langtag="word-commandclient"></b>: ' + "<code>{{.win}} -server={{.ip}}:{{.p}} -vkey=" + row.VerifyKey + " -type=" +{{.bridgeType}} +"</code><button class=\"copy btn btn-info btn-xs\" onclick=\"copyCommand(this)\" data-clipboard-text=\"\">复制</button><br/>"
|
||||
+ '<b langtag="word-commandclient-tls"></b>: ' + "<code>{{.win}} -server={{.ip}}:{{.tls_p}} -vkey=" + row.VerifyKey + " -tls_enable=true</code><button class=\"copy btn btn-info btn-xs\" onclick=\"copyCommand(this)\" data-clipboard-text=\"\">复制</button>"
|
||||
},
|
||||
//表格的列
|
||||
columns: [
|
||||
|
||||
@@ -79,16 +79,16 @@
|
||||
+ '<b langtag="word-protoversion"></b>: ' + row.ProtoVersion + ' '
|
||||
if (row.Mode == "p2p") {
|
||||
return tmp + "<br/><br>"
|
||||
+ '<b langtag="word-commandaccessp2p"></b>: ' + "<code>./npc{{.win}} -server={{.ip}}:{{.p}} -vkey=" + row.Client.VerifyKey
|
||||
+ '<b langtag="word-commandaccessp2p"></b>: ' + "<code>{{.win}} -server={{.ip}}:{{.p}} -vkey=" + row.Client.VerifyKey
|
||||
+ " -type=" +{{.bridgeType}} +" -password=" + row.Password + " -target=" + row.Target.TargetStr + "</code>" + "<br/><br>"
|
||||
+ '<b langtag="word-commandaccessp2ps"></b>: ' + "<code>./npc{{.win}} -server={{.ip}}:{{.p}} -vkey=" + row.Client.VerifyKey
|
||||
+ '<b langtag="word-commandaccessp2ps"></b>: ' + "<code>{{.win}} -server={{.ip}}:{{.p}} -vkey=" + row.Client.VerifyKey
|
||||
+ " -type=" +{{.bridgeType}} +" -password=" + row.Password + " -local_type=p2ps" + "</code>" + "<br/><br>"
|
||||
+ '<b langtag="word-commandaccessp2pt"></b>: ' + "<code>./npc{{.win}} -server={{.ip}}:{{.p}} -vkey=" + row.Client.VerifyKey
|
||||
+ '<b langtag="word-commandaccessp2pt"></b>: ' + "<code>{{.win}} -server={{.ip}}:{{.p}} -vkey=" + row.Client.VerifyKey
|
||||
+ " -type=" +{{.bridgeType}} +" -password=" + row.Password + " -local_type=p2pt" + "</code>"
|
||||
|
||||
}
|
||||
if (row.Mode == "secret") {
|
||||
return tmp + "<br/><br>" + '<b langtag="word-commandaccess"></b>: ' + "<code>./npc{{.win}} -server={{.ip}}:{{.p}} -vkey=" + row.Client.VerifyKey
|
||||
return tmp + "<br/><br>" + '<b langtag="word-commandaccess"></b>: ' + "<code>{{.win}} -server={{.ip}}:{{.p}} -vkey=" + row.Client.VerifyKey
|
||||
+ " -type=" +{{.bridgeType}} +" -password=" + row.Password + " -local_type=secret" + "</code>"
|
||||
}
|
||||
return tmp
|
||||
|
||||
@@ -10,16 +10,16 @@
|
||||
|
||||
<!-- Mainly scripts -->
|
||||
<!-- Latest compiled and minified CSS -->
|
||||
<link href="{{.web_base_url}}/static/css/fontawesome.min.css" rel="stylesheet">
|
||||
<link href="{{.web_base_url}}/static/css/solid.min.css" rel="stylesheet">
|
||||
<link href="{{.web_base_url}}/static/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link href="{{.web_base_url}}/static/css/style.css" rel="stylesheet">
|
||||
<link href="{{.web_base_url}}/static/css/fontawesome.min.css?v={{.version}}" rel="stylesheet">
|
||||
<link href="{{.web_base_url}}/static/css/solid.min.css?v={{.version}}" rel="stylesheet">
|
||||
<link href="{{.web_base_url}}/static/css/bootstrap.min.css?v={{.version}}" rel="stylesheet">
|
||||
<link href="{{.web_base_url}}/static/css/style.css?v={{.version}}" rel="stylesheet">
|
||||
|
||||
<!-- Latest compiled and minified JavaScript -->
|
||||
<script src="{{.web_base_url}}/static/js/jquery-3.4.1.min.js"></script>
|
||||
<script src="{{.web_base_url}}/static/js/bootstrap.min.js"></script>
|
||||
<script src="{{.web_base_url}}/static/js/jquery-3.4.1.min.js?v={{.version}}"></script>
|
||||
<script src="{{.web_base_url}}/static/js/bootstrap.min.js?v={{.version}}"></script>
|
||||
<!-- Latest compiled and minified Locales -->
|
||||
<script src="{{.web_base_url}}/static/js/language.js?v=202512054" type="text/javascript"></script>
|
||||
<script src="{{.web_base_url}}/static/js/language.js?v={{.version}}" type="text/javascript"></script>
|
||||
|
||||
</head>
|
||||
|
||||
|
||||
@@ -10,16 +10,16 @@
|
||||
|
||||
<!-- Mainly scripts -->
|
||||
<!-- Latest compiled and minified CSS -->
|
||||
<link href="{{.web_base_url}}/static/css/fontawesome.min.css" rel="stylesheet">
|
||||
<link href="{{.web_base_url}}/static/css/solid.min.css" rel="stylesheet">
|
||||
<link href="{{.web_base_url}}/static/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link href="{{.web_base_url}}/static/css/style.css" rel="stylesheet">
|
||||
<link href="{{.web_base_url}}/static/css/fontawesome.min.css?v={{.version}}" rel="stylesheet">
|
||||
<link href="{{.web_base_url}}/static/css/solid.min.css?v={{.version}}" rel="stylesheet">
|
||||
<link href="{{.web_base_url}}/static/css/bootstrap.min.css?v={{.version}}" rel="stylesheet">
|
||||
<link href="{{.web_base_url}}/static/css/style.css?v={{.version}}" rel="stylesheet">
|
||||
|
||||
<!-- Latest compiled and minified JavaScript -->
|
||||
<script src="{{.web_base_url}}/static/js/jquery-3.4.1.min.js"></script>
|
||||
<script src="{{.web_base_url}}/static/js/bootstrap.min.js"></script>
|
||||
<script src="{{.web_base_url}}/static/js/jquery-3.4.1.min.js?v={{.version}}"></script>
|
||||
<script src="{{.web_base_url}}/static/js/bootstrap.min.js?v={{.version}}"></script>
|
||||
<!-- Latest compiled and minified Locales -->
|
||||
<script src="{{.web_base_url}}/static/js/language.js?v=202512054" type="text/javascript"></script>
|
||||
<script src="{{.web_base_url}}/static/js/language.js?v={{.version}}" type="text/javascript"></script>
|
||||
|
||||
</head>
|
||||
|
||||
|
||||
@@ -11,25 +11,25 @@
|
||||
|
||||
<!-- Mainly scripts -->
|
||||
<!-- Latest compiled and minified CSS -->
|
||||
<link href="{{.web_base_url}}/static/css/toastr.min.css" rel="stylesheet">
|
||||
<link href="{{.web_base_url}}/static/css/fontawesome.min.css" rel="stylesheet">
|
||||
<link href="{{.web_base_url}}/static/css/solid.min.css" rel="stylesheet">
|
||||
<link href="{{.web_base_url}}/static/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link href="{{.web_base_url}}/static/css/bootstrap-table.min.css" rel="stylesheet">
|
||||
<link href="{{.web_base_url}}/static/css/style.css" rel="stylesheet">
|
||||
<link href="{{.web_base_url}}/static/css/toastr.min.css?v={{.version}}" rel="stylesheet">
|
||||
<link href="{{.web_base_url}}/static/css/fontawesome.min.css?v={{.version}}" rel="stylesheet">
|
||||
<link href="{{.web_base_url}}/static/css/solid.min.css?v={{.version}}" rel="stylesheet">
|
||||
<link href="{{.web_base_url}}/static/css/bootstrap.min.css?v={{.version}}" rel="stylesheet">
|
||||
<link href="{{.web_base_url}}/static/css/bootstrap-table.min.css?v={{.version}}" rel="stylesheet">
|
||||
<link href="{{.web_base_url}}/static/css/style.css?v={{.version}}" rel="stylesheet">
|
||||
|
||||
<!-- Latest compiled and minified JavaScript -->
|
||||
<script src="{{.web_base_url}}/static/js/jquery-3.4.1.min.js"></script>
|
||||
<script src="{{.web_base_url}}/static/js/clipboard.min.js"></script>
|
||||
<script src="{{.web_base_url}}/static/js/toastr.min.js"></script>
|
||||
<script src="{{.web_base_url}}/static/js/popper.min.js"></script>
|
||||
<script src="{{.web_base_url}}/static/js/bootstrap.min.js"></script>
|
||||
<script src="{{.web_base_url}}/static/js/bootstrap-table.min.js"></script>
|
||||
<script src="{{.web_base_url}}/static/js/bootstrap-table-locale-all.min.js"></script>
|
||||
<script src="{{.web_base_url}}/static/js/echarts.min.js"></script>
|
||||
<script src="{{.web_base_url}}/static/js/inspinia.js"></script>
|
||||
<script src="{{.web_base_url}}/static/js/jquery-3.4.1.min.js?v={{.version}}"></script>
|
||||
<script src="{{.web_base_url}}/static/js/clipboard.min.js?v={{.version}}"></script>
|
||||
<script src="{{.web_base_url}}/static/js/toastr.min.js?v={{.version}}"></script>
|
||||
<script src="{{.web_base_url}}/static/js/popper.min.js?v={{.version}}"></script>
|
||||
<script src="{{.web_base_url}}/static/js/bootstrap.min.js?v={{.version}}"></script>
|
||||
<script src="{{.web_base_url}}/static/js/bootstrap-table.min.js?v={{.version}}"></script>
|
||||
<script src="{{.web_base_url}}/static/js/bootstrap-table-locale-all.min.js?v={{.version}}"></script>
|
||||
<script src="{{.web_base_url}}/static/js/echarts.min.js?v={{.version}}"></script>
|
||||
<script src="{{.web_base_url}}/static/js/inspinia.js?v={{.version}}"></script>
|
||||
<!-- Latest compiled and minified Locales -->
|
||||
<script src="{{.web_base_url}}/static/js/language.js?v=202512054" type="text/javascript"></script>
|
||||
<script src="{{.web_base_url}}/static/js/language.js?v={{.version}}" type="text/javascript"></script>
|
||||
|
||||
|
||||
</head>
|
||||
|
||||
Reference in New Issue
Block a user