Compare commits

..
22 Commits
Author SHA1 Message Date
viaeon a3a199ff0e ci: 用 git clone 替代 actions/checkout(golang 镜像无 node)
CI and Docker Build / Build Binaries (push) Successful in 47s
CI and Docker Build / Build and Push Docker Images (push) Successful in 49s
CI and Docker Build / Deploy to Remote Server (push) Successful in 23s
2026-10-30 16:19:16 +08:00
viaeon 79866f7795 ci: 迁移 CI 到 Gitea Actions,构建推送 nps/npc 镜像
CI and Docker Build / Build Binaries (push) Failing after 14s
CI and Docker Build / Build and Push Docker Images (push) Skipped
CI and Docker Build / Deploy to Remote Server (push) Skipped
2026-10-30 15:53:35 +08:00
yisier 495acc683a Update sponsorship section in README.md 2026-10-27 13:50:54 +08:00
yisier 35b2054d84 Merge pull request #364 from Bald-guy69/master
fix: receiveWindowQueue.Pop busy loop when a mux conn is closed while reading
2026-10-26 17:01:02 +08:00
Bald-gyu69 19eba0c05d fix: stop receiveWindowQueue.Pop spinning forever after a concurrent release 2026-10-23 00:01:09 +08:00
yisier dbe417f418 nps 服务端升级后自动重启服务 2026-10-10 17:13:03 +08:00
yisier 7566207b8f 管理面板证书加载问题修复 2026-10-10 14:57:04 +08:00
yisier 1b95dcde25 修复 SOCKS5 代理 DSN 污染问题 2026-10-10 14:44:57 +08:00
yisier e7ac30ecb3 用户手动切换语言后长期持久化修复 2026-10-10 14:28:30 +08:00
yisier b3c15a59bf Merge pull request #359 from prq0705/master
修复验证码图片路径未跟随 web_base_url,反代子路径后无法登录
2026-10-10 14:13:41 +08:00
pengruiqi4374 435784f863 web_base_url 未作用于验证码:open_captcha=true 时验证码仍请求根路径 /captcha/,子路径反代下登录页验证码 404
同时配置 `web_base_url=/nps` 与 `open_captcha=true` 时,登录页验证码图片的 URL 仍然从根路径请求,导致使用反代时验证码404
2026-10-04 14:21:22 +08:00
yisier 97d2a45b3b Update NATNPS cloud penetration description
Reformatted NATNPS cloud penetration section for clarity.
2026-09-17 15:26:36 +08:00
yisier e696090912 Remove Rainyun sponsorship section from README
Removed sponsorship information for Rainyun cloud service.
2026-09-17 15:22:05 +08:00
yisier e974cfbff6 Update funding model with PayPal link 2026-08-27 13:52:30 +08:00
yisier 215a316363 Add custom sponsorship URL to FUNDING.yml
Added a custom sponsorship URL for PayPal.
2026-08-27 13:52:09 +08:00
yisier 195c8e661a Delete .github/FUNDING.yml 2026-08-27 13:51:50 +08:00
yisier 14328fe0a3 Refactor custom funding links format in FUNDING.yml 2026-08-27 13:46:23 +08:00
yisier b92b63331a Update FUNDING.yml 2026-08-27 13:41:19 +08:00
yisier d778c1f79e Create FUNDING.yml 2026-08-27 13:36:58 +08:00
yisier b93d7f1f8c gui img 2026-08-25 16:16:00 +08:00
yisier 9a074e7fd7 gui img 2026-08-25 16:14:37 +08:00
yisier 96a2344178 gui img 2026-08-25 16:06:50 +08:00
21 changed files with 452 additions and 500 deletions
+1
View File
@@ -0,0 +1 @@
custom: ["https://paypal.me/yisier"]
+140
View File
@@ -0,0 +1,140 @@
name: CI and Docker Build
on:
push:
branches:
- main
- master
tags:
- 'v*'
pull_request:
branches:
- main
- master
jobs:
build:
name: Build Binaries
runs-on: ubuntu
container:
image: golang:1.24
env:
# actions/checkout 是 JS action,需要 node,golang 镜像里没有,所以直接用 git clone
GOPROXY: https://goproxy.cn,direct
steps:
- name: Checkout repository
run: |
rm -rf /tmp/repo
git clone https://admin:${{ secrets.TOKEN }}@git.viaeon.com/admin/nps.git /tmp/repo
cd /tmp/repo
git checkout ${{ github.sha }} || true
git log --oneline -1
- name: Build nps and npc
run: |
cd /tmp/repo
go mod download
echo "Building nps..."
CGO_ENABLED=0 go build -v -o /tmp/nps ./cmd/nps/nps.go
echo "Building npc..."
CGO_ENABLED=0 go build -v -o /tmp/npc ./cmd/npc/npc.go
ls -la /tmp/nps /tmp/npc
docker:
name: Build and Push Docker Images
runs-on: ubuntu
needs: [build]
if: github.event_name == 'push'
env:
RUNNER_TOOL_CACHE: /toolcache
steps:
- name: Install Docker CLI
run: |
if ! command -v docker &> /dev/null; then
if command -v apk &> /dev/null; then
apk add --no-cache docker-cli
elif command -v apt-get &> /dev/null; then
apt-get update && apt-get install -y docker.io
else
curl -fsSL https://download.docker.com/linux/static/stable/x86_64/docker-24.0.7.tgz | tar xz -C /tmp
mv /tmp/docker/docker /usr/local/bin/
chmod +x /usr/local/bin/docker
fi
fi
docker --version
- name: Checkout repository
run: |
rm -rf /tmp/repo
git clone https://admin:${{ secrets.TOKEN }}@git.viaeon.com/admin/nps.git /tmp/repo
cd /tmp/repo
git checkout ${{ github.ref_name }} || true
git log --oneline -1
- name: Login to Gitea Container Registry
run: |
echo "${{ secrets.TOKEN }}" | docker login git.viaeon.com -u "${{ github.actor }}" --password-stdin 2>&1
- name: Build and push nps
run: |
cd /tmp/repo
docker build \
--label "org.opencontainers.image.source=https://git.viaeon.com/admin/nps" \
--label "org.opencontainers.image.revision=${{ github.sha }}" \
--build-arg GOPROXY=https://goproxy.cn,direct \
-f Dockerfile.nps \
-t git.viaeon.com/admin/nps:${{ github.ref_name }} \
-t git.viaeon.com/admin/nps:latest . 2>&1
docker push git.viaeon.com/admin/nps:${{ github.ref_name }} 2>&1
docker push git.viaeon.com/admin/nps:latest 2>&1
- name: Build and push npc
run: |
cd /tmp/repo
docker build \
--label "org.opencontainers.image.source=https://git.viaeon.com/admin/nps" \
--label "org.opencontainers.image.revision=${{ github.sha }}" \
--build-arg GOPROXY=https://goproxy.cn,direct \
-f Dockerfile.npc \
-t git.viaeon.com/admin/npc:${{ github.ref_name }} \
-t git.viaeon.com/admin/npc:latest . 2>&1
docker push git.viaeon.com/admin/npc:${{ github.ref_name }} 2>&1
docker push git.viaeon.com/admin/npc:latest 2>&1
deploy:
name: Deploy to Remote Server
runs-on: ubuntu
needs: docker
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
steps:
- name: Install SSH Client
run: |
if command -v apk &> /dev/null; then
apk add --no-cache openssh-client sshpass
elif command -v apt-get &> /dev/null; then
apt-get update && apt-get install -y openssh-client sshpass
else
echo "Cannot install sshpass"
exit 1
fi
ssh -V
- name: Deploy via SSH
run: |
sshpass -p '${{ secrets.DEPLOY_PASSWORD }}' ssh -o StrictHostKeyChecking=no -p ${{ secrets.DEPLOY_PORT || '22' }} ${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }} << ENDSSH
set -e
cd "${{ secrets.DEPLOY_PATH }}"
echo "Current directory: \$(pwd)"
ls -la
echo "Pulling latest image..."
docker pull git.viaeon.com/admin/nps:latest
echo "Restarting containers..."
docker compose down || true
docker compose up -d
echo "Cleaning up old images..."
docker image prune -f
echo "Deployment completed!"
ENDSSH
-60
View File
@@ -1,60 +0,0 @@
name: Deploy Docs to GitHub Pages
on:
push:
branches: [master]
paths:
- 'docs/**'
- '.github/workflows/docs.yml'
workflow_dispatch:
permissions:
contents: read
pages: write
id-token: write
# 并发:同一时刻只允许一次部署,新的提交会取消上一个未完成的运行
concurrency:
group: pages
cancel-in-progress: false
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # lastUpdated 需要完整 git 历史
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
- name: Install dependencies
working-directory: docs
run: npm install --legacy-peer-deps
- name: Build VuePress site
working-directory: docs
run: npm run docs:build
- name: Setup Pages
uses: actions/configure-pages@v4
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: docs/.vuepress/dist
deploy:
needs: build
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
-344
View File
@@ -1,344 +0,0 @@
name: Release
on:
push:
tags:
- 'v*'
workflow_dispatch:
permissions:
contents: write
env:
GUI_DIR: cmd/npc/npc-gui
FRONTEND_DIR: cmd/npc/npc-gui/frontend
WAILS_VERSION: v3.0.0-beta.12
APP_NAME: npc-gui
jobs:
# ==================== 跨平台服务端/客户端打包 ====================
build_assets:
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: "1.22"
- name: Check out code
uses: actions/checkout@v2
- name: Get dependencies
run: |
go get -v -t -d ./...
if [ -f Gopkg.toml ]; then
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
dep ensure
fi
- name: Build
run: |
chmod +x build.assets.sh
./build.assets.sh
- name: Upload
uses: softprops/action-gh-release@v2
if: github.ref_type == 'tag' || github.event_name == 'workflow_dispatch'
with:
files: |
freebsd_386_client.tar.gz
freebsd_386_server.tar.gz
freebsd_amd64_client.tar.gz
freebsd_amd64_server.tar.gz
freebsd_arm_client.tar.gz
freebsd_arm_server.tar.gz
linux_386_client.tar.gz
linux_386_server.tar.gz
linux_amd64_client.tar.gz
linux_amd64_server.tar.gz
linux_arm64_client.tar.gz
linux_arm64_server.tar.gz
linux_arm_v5_client.tar.gz
linux_arm_v6_client.tar.gz
linux_arm_v7_client.tar.gz
linux_arm_v5_server.tar.gz
linux_arm_v6_server.tar.gz
linux_arm_v7_server.tar.gz
linux_mips64le_client.tar.gz
linux_mips64le_server.tar.gz
linux_mips64_client.tar.gz
linux_mips64_server.tar.gz
linux_mipsle_client.tar.gz
linux_mipsle_server.tar.gz
linux_mips_client.tar.gz
linux_mips_server.tar.gz
darwin_amd64_client.tar.gz
darwin_amd64_server.tar.gz
darwin_arm64_client.tar.gz
darwin_arm64_server.tar.gz
windows_386_client.tar.gz
windows_386_server.tar.gz
windows_amd64_client.tar.gz
windows_amd64_server.tar.gz
npc_sdk.tar.gz
tag_name: ${{ github.ref_name }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# ==================== Android APK ====================
build_android:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4
- 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
ls -la android_client.apk
- name: Upload
uses: softprops/action-gh-release@v2
if: github.ref_type == 'tag' || github.event_name == 'workflow_dispatch'
with:
files: |
android_client.apk
tag_name: ${{ github.ref_name }}
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:
matrix:
include:
- platform: windows/386
os_name: windows
arch: 386
- platform: windows/amd64
os_name: windows
arch: amd64
- platform: windows/arm64
os_name: windows
arch: arm64
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: 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/v3/cmd/wails3@${{ env.WAILS_VERSION }}
working-directory: ${{ env.GUI_DIR }}
- name: Build and package (Windows)
shell: pwsh
working-directory: ${{ env.GUI_DIR }}
run: |
$env:GOOS = "windows"
$env:GOARCH = "${{ matrix.arch }}"
wails3 build --tags npcgui
Set-Location bin
$zipName = "$env:APP_NAME-${{ matrix.os_name }}-${{ matrix.arch }}.zip"
$exe = Get-ChildItem -Path . -Filter *.exe | Select-Object -First 1
if (-not $exe) {
Write-Host "No build output found in bin"
Get-ChildItem -Path . | Format-Table -AutoSize
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 }}/bin/${{ env.APP_NAME }}-${{ matrix.os_name }}-${{ matrix.arch }}.zip
- name: Upload Windows release asset
uses: softprops/action-gh-release@v2
if: github.ref_type == 'tag' || github.event_name == 'workflow_dispatch'
with:
files: ${{ env.GUI_DIR }}/bin/${{ env.APP_NAME }}-${{ matrix.os_name }}-${{ matrix.arch }}.zip
tag_name: ${{ github.ref_name }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# ==================== macOS GUI ====================
build_macos_gui:
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- platform: darwin/amd64
os_name: darwin
arch: amd64
os: macos-14
- platform: darwin/arm64
os_name: darwin
arch: arm64
os: macos-latest
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: 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/v3/cmd/wails3@${{ env.WAILS_VERSION }}
working-directory: ${{ env.GUI_DIR }}
- name: Build and package (macOS)
shell: bash
working-directory: ${{ env.GUI_DIR }}
run: |
export GOOS=darwin
export GOARCH="${{ matrix.arch }}"
# wails3 package builds with EXTRA_TAGS=npcgui (Package has no --tags
# flag; the var flows into the build dep) and then assembles a proper
# bin/npc-gui.app bundle with ad-hoc codesign.
wails3 package EXTRA_TAGS=npcgui
cd bin
# Guard the .app lookups so a no-match does not abort the script
# under `set -e -o pipefail`; keep the raw-binary fallback as safety.
app="$(ls -1d *.app 2>/dev/null | head -n 1 || true)"
if [ -z "$app" ]; then
app="$(find . -maxdepth 1 -type f -perm -111 -exec basename {} \; | head -n 1 || true)"
fi
if [ -z "$app" ]; then
echo "No build output found in bin"
ls -la
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 }}/bin/${{ env.APP_NAME }}-${{ matrix.os_name }}-${{ matrix.arch }}.zip
- name: Upload macOS release asset
uses: softprops/action-gh-release@v2
if: github.ref_type == 'tag' || github.event_name == 'workflow_dispatch'
with:
files: ${{ env.GUI_DIR }}/bin/${{ env.APP_NAME }}-${{ matrix.os_name }}-${{ matrix.arch }}.zip
tag_name: ${{ github.ref_name }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# ==================== Linux GUI ====================
build_linux_gui:
runs-on: ubuntu-latest
strategy:
matrix:
include:
- platform: linux/amd64
os_name: linux
arch: amd64
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Install Linux dependencies
run: |
sudo apt-get update
sudo apt-get install -y build-essential libgtk-4-dev libwebkitgtk-6.0-dev libsoup-3.0-dev libjavascriptcoregtk-6.0-dev libayatana-appindicator3-dev librsvg2-dev patchelf pkg-config
- 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: 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/v3/cmd/wails3@${{ env.WAILS_VERSION }}
working-directory: ${{ env.GUI_DIR }}
- name: Build and package (Linux)
shell: bash
working-directory: ${{ env.GUI_DIR }}
run: |
export GOOS=linux
export GOARCH="${{ matrix.arch }}"
wails3 build --tags npcgui
cd bin
bin="$(find . -maxdepth 1 -type f -perm -111 -printf '%f\n' | head -n 1)"
if [ -z "$bin" ]; then
echo "No executable file found in bin"
ls -la
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 }}/bin/${{ env.APP_NAME }}-${{ matrix.os_name }}-${{ matrix.arch }}.zip
- name: Upload Linux release asset
uses: softprops/action-gh-release@v2
if: github.ref_type == 'tag' || github.event_name == 'workflow_dispatch'
with:
files: ${{ env.GUI_DIR }}/bin/${{ env.APP_NAME }}-${{ matrix.os_name }}-${{ matrix.arch }}.zip
tag_name: ${{ github.ref_name }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+11 -5
View File
@@ -1,6 +1,6 @@
# NPS
![Version](https://img.shields.io/badge/version-v0.26.38-blue)
![Version](https://img.shields.io/badge/version-v0.26.39-blue)
![License](https://img.shields.io/badge/license-GPL--3.0-green)
![Go](https://img.shields.io/badge/Go-%3E%3D1.22-00ADD8?logo=go)
@@ -12,11 +12,10 @@
---
## 💰 赞助 / 推荐
#### ☁️ [雨云 — 国内便宜稳定的云服务器,首月 5 折](https://www.rainyun.com/MjY0MzY1_)
500M 带宽,高仿物理机,云服务器**15 元起**,通过此链接注册首月 5 折。
#### 【腾讯云】— [WorkBuddy 全场景 AI 办公工作台](https://curl.qcloud.com/Fw85I52h)
#### 【NATNPS 云穿透】 — [无需自备服务器,注册即用,免费 3M 带宽 / 2 条隧道](https://natnps.com/register?utm_from=MQ==)
#### 🚀 [NATNPS 云穿透 — 免费 3M 带宽 / 2 条隧道](https://natnps.com/register?utm_from=MQ==)
无需自备服务器,注册即用。免费版 3M 带宽 2 条隧道;6.8 元 12M 带宽 10 条隧道;13.8 元 24M 带宽 20 条隧道。
---
## 🚀 快速开始
@@ -46,6 +45,12 @@
![image](https://raw.githubusercontent.com/yisier/nps/master/docs/.vuepress/public/image/new/cmd.png)
#### GUI
![image](https://yisier.github.io/nps/image/new/gui.png)
#### 命令行直接启动
```shell
@@ -54,6 +59,7 @@ npc -server=ip:8025 -vkey=xxx -tls_enable=true # TLS 桥接
npc -server=ip:8024 -vkey=vkey1,vkey2 # 多隧道
```
---
## ☕ 请作者喝杯咖啡
+1 -1
View File
@@ -1,5 +1,5 @@
#/bash/sh
export VERSION=0.26.38
export VERSION=0.26.39
export GOPROXY=direct
sudo apt-get update
+1 -1
View File
@@ -280,7 +280,7 @@ func printSlogan() {
fmt.Printf("\033[32;0m# \033[31mNPS内网穿透客户端\033[0m #\n")
fmt.Printf("\033[32;0m# #\n")
fmt.Printf("\033[32;0m#\033[32m 地址:\033[31;0mhttps://github.com/yisier/nps\033[0m #\n")
fmt.Printf("\033[32;0m#\033[32m 提示:\033[32;0m1、涉及到系统服务的需要以管理员身份运行\033[0m\033[32;0m #\n")
fmt.Printf("\033[32;0m#\033[32m 提示:\033[32;0m1、涉及到系统服务的需要以管理员/root身份运行\033[0m\033[32;0m #\n")
fmt.Printf("\033[32;0m#\033[32m \033[32;0m2、直接启动或[注册系统服务]需要使用[快捷启动命令]\033[0m\033[32;0m #\n")
fmt.Printf("\033[32;0m#\033[32m \033[32;0m3、其他命令如卸载/启动/停止只需要输入[vkey]\033[0m\033[32;0m #\n")
fmt.Printf("\033[32;0m###########################################################\n")
+120 -44
View File
@@ -50,12 +50,6 @@ func main() {
common.PrintVersion()
return
}
if *serverCmd {
_ = logs.SetLogger(logs.AdapterConsole, `{"level":7,"color":true}`)
printSlogan()
inputCmd()
return
}
var logPath string
// *confPath why get null value ?
@@ -73,6 +67,13 @@ func main() {
}
}
if *serverCmd {
_ = logs.SetLogger(logs.AdapterConsole, `{"level":7,"color":true}`)
printSlogan()
inputCmd()
return
}
// auto-generate default config files if not exist
initConfig(filepath.Join(common.GetRunPath(), "conf"))
@@ -198,7 +199,11 @@ func main() {
}
return
case "update":
install.UpdateNps()
if updated, err := install.UpdateNps(); err != nil {
logs.Error("更新失败:", err)
} else if updated {
restartNpsService(s)
}
return
//default:
// logs.Error("command is not support")
@@ -210,35 +215,117 @@ func main() {
}
func printSlogan() {
confFile := ""
for _, dir := range []string{common.GetAppPath(), common.GetRunPath()} {
if p := filepath.Join(dir, "conf", "nps.conf"); common.FileExists(p) {
confFile = p
break
}
}
configLoaded := false
if confFile != "" {
if err := beego.LoadAppConfig("ini", confFile); err == nil {
configLoaded = true
}
}
green := color.New(color.FgGreen).SprintFunc()
// 第一次输入,如果输入 1,2,3,4 则需要输入秘钥,否则
w := color.Output
fmt.Printf("%s", green(""))
fmt.Fprintf(w, "%s", green(""))
fmt.Printf("\033[32;0m欢迎使用 NPS 管理脚本,当前版本:v%s\n", version.VERSION)
fmt.Printf("\033[0m") // 重置颜色
fmt.Fprintf(w, "\033[32;0m###########################################################\n")
fmt.Fprintf(w, "\033[32;0m# \033[31mNPS内网穿透服务端\033[0m #\n")
fmt.Fprintf(w, "\033[32;0m# #\n")
fmt.Fprintf(w, "\033[32;0m#\033[32m 地址:\033[31;0mhttps://github.com/yisier/nps\033[0m #\n")
fmt.Fprintf(w, "\033[32;0m#\033[32m 提示:\033[32;0m1、涉及到系统服务的需要以管理员/root身份运行\033[0m #\n")
fmt.Fprintf(w, "\033[32;0m#\033[32m \033[32;0m2、安装/卸载/更新请选择对应的菜单项\033[0m #\n")
fmt.Fprintf(w, "\033[32;0m#\033[32m \033[32;0m3、启动/停止/重启操作的是系统服务\033[0m #\n")
fmt.Fprintf(w, "\033[32;0m###########################################################\n")
fmt.Fprintf(w, "\033[0m") // 重置颜色
fmt.Printf("\n")
fmt.Fprintf(w, "\n")
fmt.Printf("\u001B[32m输入[1]\u001B[0m - 安装 NPS\n")
fmt.Printf("\u001B[32m输入[2]\u001B[0m - 卸载 NPS\n")
fmt.Printf("\u001B[32m输入[3]\u001B[0m - 更新 NPS\n")
fmt.Printf("---------------------\n")
fmt.Printf("\u001B[32m输入[4]\u001B[0m - 查看状态\n")
fmt.Printf("---------------------\n")
fmt.Printf("\u001B[32m输入[5]\u001B[0m - 启动 NPS\n")
fmt.Printf("\u001B[32m输入[6]\u001B[0m - 停止 NPS\n")
fmt.Printf("\u001B[32m输入[7]\u001B[0m - 重启 NPS\n")
fmt.Printf("---------------------\n")
fmt.Printf("\u001B[32m输入[0]\u001B[0m - 退出脚本\n")
fmt.Printf("---------------------\n")
fmt.Printf("\n")
fmt.Fprintf(w, "\u001B[32m输入 [1]\u001B[0m - 安装 NPS\n")
fmt.Fprintf(w, "\u001B[32m输入 [2]\u001B[0m - 卸载 NPS\n")
fmt.Fprintf(w, "\u001B[32m输入 [3]\u001B[0m - 更新 NPS\n")
fmt.Fprintf(w, "---------------------\n")
fmt.Fprintf(w, "\u001B[32m输入 [4]\u001B[0m - 启动 NPS\n")
fmt.Fprintf(w, "\u001B[32m输入 [5]\u001B[0m - 停止 NPS\n")
fmt.Fprintf(w, "\u001B[32m输入 [6]\u001B[0m - 重启 NPS\n")
fmt.Fprintf(w, "---------------------\n")
fmt.Fprintf(w, "\u001B[32m输入 [0]\u001B[0m - 退出脚本\n")
fmt.Fprintf(w, "---------------------\n")
status := npsServiceStatus()
fmt.Fprintf(w, "\u001B[32m当前版本:v%s\u001B[0m\n", version.VERSION)
fmt.Fprintf(w, "\u001B[32m服务状态:%s\u001B[0m\n", status)
// 管理面板地址仅当服务已启动时显示
if status == "运行中" {
fmt.Fprintf(w, "\u001B[32m管理面板:%s\u001B[0m\n", npsPanelAddr(configLoaded))
}
fmt.Fprintf(w, "\n")
}
// npsServiceStatus 返回 Nps 系统服务的运行状态描述。
func npsServiceStatus() string {
prg := &nps{exit: make(chan struct{})}
s, err := service.New(prg, &service.Config{Name: "Nps"})
if err != nil {
return "未知"
}
st, err := s.Status()
if err != nil {
return "未安装"
}
switch st {
case service.StatusRunning:
return "运行中"
case service.StatusStopped:
return "已停止"
}
return "未知"
}
// npsPanelAddr 返回管理面板的访问地址(基于当前配置)。
// configLoaded 为 false 表示未找到配置文件,无法判断面板地址。
func npsPanelAddr(configLoaded bool) string {
if !configLoaded {
return "未找到配置文件 conf/nps.conf"
}
port := strings.TrimSpace(beego.AppConfig.String("web_port"))
if port == "" {
return "未配置 web_port(管理面板已关闭)"
}
scheme := "http"
if beego.AppConfig.DefaultBool("web_open_ssl", false) {
scheme = "https"
}
host := strings.TrimSpace(beego.AppConfig.String("web_host"))
if host == "" || host == "a.o.com" {
host = "127.0.0.1"
}
base := strings.TrimSuffix(beego.AppConfig.String("web_base_url"), "/")
return scheme + "://" + host + ":" + port + base
}
// restartNpsService 在更新完成后自动重启已安装的 Nps 系统服务,使新版本生效。
// 未安装为系统服务时不改动当前进程,仅提示手动重启。
func restartNpsService(s service.Service) {
if _, err := s.Status(); err != nil {
fmt.Println("未检测到已安装的 Nps 服务,请手动重启 nps 使新版本生效")
return
}
if err := service.Control(s, "restart"); err != nil {
fmt.Println("Nps 服务自动重启失败,请手动重启:", err)
return
}
fmt.Println("Nps 服务已自动重启,新版本已生效")
}
func inputCmd() {
var flag string
fmt.Printf("请输入[0-7]:")
fmt.Print("请输入[0-6]:")
stdin := bufio.NewReader(os.Stdin)
_, err := fmt.Fscanln(stdin, &flag)
@@ -348,24 +435,13 @@ func inputCmd() {
}
break
case "3":
install.UpdateNpsNew()
if updated, err := install.UpdateNps(); err != nil {
fmt.Println("更新失败:", err)
} else if updated {
restartNpsService(s)
}
break
case "4":
// 查看状态
var statusMsg = ""
status, err := s.Status()
if err != nil {
statusMsg = "\u001B[31m未运行\u001B[0m"
} else {
if status == 1 {
statusMsg = "\u001B[32m运行中\u001B[0m"
} else {
statusMsg = "\u001B[31m未运行\u001B[0m"
}
}
fmt.Println("NPS服务状态:" + statusMsg)
break
case "5":
// 启动 NPS
err := service.Control(s, "start")
if err != nil {
@@ -375,7 +451,7 @@ func inputCmd() {
}
break
case "6":
case "5":
// 停止 NPS
err := service.Control(s, "stop")
if err != nil {
@@ -385,7 +461,7 @@ func inputCmd() {
}
break
case "7":
case "6":
// 重启 NPS
err := service.Control(s, "restart")
if err != nil {
+16
View File
@@ -0,0 +1,16 @@
# 部署端使用的 compose(放到服务器的 DEPLOY_PATH 目录下)
# 管理后台:http://<服务器IP>:8081 默认账号密码见 conf/nps.conf(admin/123,务必修改)
# npc(客户端)镜像是 git.viaeon.com/admin/npc:latest,通常跑在别的机器上,不在此 compose 内
services:
nps:
image: git.viaeon.com/admin/nps:latest
container_name: nps
restart: unless-stopped
ports:
- "8081:8081" # web 管理面板
- "8024:8024" # 桥接端口,npc 连这个
- "80:80" # http 代理(按需)
- "443:443" # https 代理(按需)
volumes:
- ./conf:/conf
Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 43 KiB

+10 -1
View File
@@ -1,8 +1,17 @@
# 更新日志
- 2026-10-10 v0.26.39
- 修复:
- 同时开启 `web_base_url` 与 `open_captcha` 时,验证码图片路径未跟随 `web_base_url`,反向代理到子路径后无法登录 [#359](https://github.com/yisier/nps/pull/359)
- Web 面板语言机制:浏览器语言按前缀归一化匹配(`zh*`→`zh-CN`、`en*`→`en-US`),匹配不到时回退默认 `en-US`;用户手动切换语言后长期持久化,不再因关闭浏览器而失效 [#356](https://github.com/yisier/nps/issues/356)
- SOCKS5(私密代理)UDP ASSOCIATE 回复的中继地址 `BND.ADDR` 优先使用客户端实际连接到的服务端地址,避免外网 IP 探测被运营商 HTTP 劫持返回错误 IP 导致 UDP 不通;外网探测改为 HTTPS 端点并加超时与校验 [#355](https://github.com/yisier/nps/issues/355)
- 开启 `web_open_ssl=true` 后以系统服务方式启动时 Web 面板无法访问:证书相对路径按进程工作目录解析失败,改为基于 nps 运行目录解析 `web_cert_file` / `web_key_file` [#353](https://github.com/yisier/nps/issues/353)
- `nps` 服务端升级后自动重启服务 [#47](https://github.com/yisier/nps/issues/347)
- 2026-08-24 v0.26.38
- 新增:
- GUI 客户端(npc-gui)迁移到 Wails v3
- GUI 客户端新增版本自动更新:启动时自动检查 GitHub 最新 release,支持一键下载并热替换当前可执行文件后自动重启
- GUI 客户端新增版本自动更新:启动时自动检查 GitHub 最新 release,支持一键下载并热替换当前可执行文件后自动重启
![img.png](/image/new/gui.png)
- 修复:
- 客户端内网地址为 192.169.x.x 等非标准私网段时,Web 面板客户端列表不显示本机 IP [#348](https://github.com/yisier/nps/issues/348)
+47 -12
View File
@@ -20,6 +20,7 @@ import (
"strconv"
"strings"
"sync"
"time"
"ehang.io/nps/lib/crypt"
)
@@ -452,18 +453,41 @@ func GetExtFromPath(path string) string {
var externalIp string
// externalIpServices are queried in order until one returns a valid IP.
// HTTPS plain-text echo services are preferred, because a plain HTTP endpoint
// can be hijacked or transparently cached by some ISPs (see #355).
var externalIpServices = []string{
"https://ifconfig.me/ip",
"https://ipinfo.io/ip",
"http://v4.ipip.net",
}
// GetExternalIp returns the public IP of this server by asking an external
// "what is my IP" service. The result is cached only after a valid answer,
// so a transient failure or a hijacked/empty response is not cached forever.
func GetExternalIp() string {
if externalIp != "" {
return externalIp
}
resp, err := http.Get("http://myexternalip.com/raw")
if err != nil {
return ""
client := &http.Client{Timeout: 3 * time.Second}
for _, url := range externalIpServices {
resp, err := client.Get(url)
if err != nil {
continue
}
content, _ := ioutil.ReadAll(io.LimitReader(resp.Body, 64))
resp.Body.Close()
if resp.StatusCode != http.StatusOK {
continue
}
ip := strings.TrimSpace(string(content))
if net.ParseIP(ip) == nil {
continue
}
externalIp = ip
return externalIp
}
defer resp.Body.Close()
content, _ := ioutil.ReadAll(resp.Body)
externalIp = string(content)
return externalIp
return ""
}
func GetIntranetIp() (error, string) {
@@ -609,12 +633,23 @@ func IsPublicIP(IP net.IP) bool {
return false
}
func GetServerIpByClientIp(clientIp net.IP) string {
if IsPublicIP(clientIp) {
return GetExternalIp()
// GetServerIpByClientIp returns an address the SOCKS5 client can use to reach
// the server's UDP relay (the SOCKS5 BND.ADDR).
//
// - LAN client: the server's intranet IP.
// - WAN client: the local IP the client actually connected to, which is
// guaranteed to be reachable because the TCP control connection succeeded.
// Only when that address is not public (the server sits behind NAT) do we
// fall back to querying an external "what is my IP" service.
func GetServerIpByClientIp(clientIp, localIp net.IP) string {
if !IsPublicIP(clientIp) {
_, ip := GetIntranetIp()
return ip
}
_, ip := GetIntranetIp()
return ip
if IsPublicIP(localIp) {
return localIp.String()
}
return GetExternalIp()
}
func PrintVersion() {
+10 -24
View File
@@ -136,43 +136,29 @@ RestartSec=120
WantedBy=multi-user.target
`
func UpdateNps() {
destPath, err := downloadLatest("server")
if err != nil {
log.Println("下载更新失败:", err)
return
}
//复制文件到对应目录
if _, err := copyStaticFile(destPath, "nps"); err != nil {
log.Println("替换服务端文件失败:", err)
return
}
fmt.Println("Update completed, please restart")
}
func UpdateNpsNew() {
// UpdateNps 检查并替换服务端到最新版本。
// 返回 updated=true 表示已用新版本替换当前二进制(调用方应重启服务使其生效);
// updated=false 且 err=nil 表示当前已是最新版本,未做任何改动。
func UpdateNps() (updated bool, err error) {
latest, err := fetchLatestVersion()
if err != nil {
log.Println("获取最新版本失败:", err)
return
return false, err
}
fmt.Println("最新版本为:", latest)
if compareVersion(version.VERSION, latest) >= 0 {
fmt.Println("当前已是最新版本,无需更新")
return
return false, nil
}
tempDir := filepath.Join(common.GetAppPath(), "temp")
destPath, err := downloadLatest2("server", tempDir)
if err != nil {
log.Println("下载更新失败:", err)
return
return false, err
}
//复制文件到对应目录
if err := copyStaticFileReplaceNps(destPath, common.GetAppPath()); err != nil {
log.Println("替换服务端文件失败:", err)
return
return false, err
}
fmt.Println("更新成功,请重启服务")
fmt.Println("更新成功")
return true, nil
}
func fetchLatestVersion() (string, error) {
+5
View File
@@ -275,6 +275,11 @@ startPop:
if element != nil {
return
}
// the element counted in length may have been taken by release() when the
// window was closed concurrently, re-check the length instead of spinning forever
if length, _ = Self.chain.head.unpack(atomic.LoadUint64(&Self.lengthWait)); length == 0 {
goto startPop
}
runtime.Gosched() // another goroutine is still pushing
}
}
+33
View File
@@ -0,0 +1,33 @@
package nps_mux
import (
"io"
"sync/atomic"
"testing"
"time"
)
// A reader that has already seen an element counted in length must not spin
// forever when release() takes that element first because the conn was closed.
func TestReceiveWindowQueuePopAfterConcurrentRelease(t *testing.T) {
q := newReceiveWindowQueue()
// the reader sees one element in the queue...
atomic.StoreUint64(&q.lengthWait, q.chain.head.pack(1, 0))
done := make(chan error, 1)
go func() {
_, err := q.Pop()
done <- err
}()
time.Sleep(10 * time.Millisecond)
// ...but the window is closed and release() drains that element first
q.Stop()
atomic.StoreUint64(&q.lengthWait, 0)
select {
case err := <-done:
if err != io.EOF {
t.Fatalf("Pop returned %v, want io.EOF", err)
}
case <-time.After(time.Second):
t.Fatal("Pop is still spinning after the queue was stopped and drained")
}
}
+1 -1
View File
@@ -1,6 +1,6 @@
package version
const VERSION = "0.26.38"
const VERSION = "0.26.39"
// Compulsory minimum version, Minimum downward compatibility to this version
func GetVersion() string {
+6 -1
View File
@@ -267,7 +267,12 @@ func (s *Sock5ModeServer) handleUDP(c net.Conn) {
return
}
// reply the local addr
s.sendUdpReply(c, reply, succeeded, common.GetServerIpByClientIp(c.RemoteAddr().(*net.TCPAddr).IP))
// Use the address the client actually connected to as BND.ADDR whenever it
// is public; only fall back to external IP detection when the server is
// behind NAT (see #355).
clientIp := c.RemoteAddr().(*net.TCPAddr).IP
localIp := c.LocalAddr().(*net.TCPAddr).IP
s.sendUdpReply(c, reply, succeeded, common.GetServerIpByClientIp(clientIp, localIp))
defer reply.Close()
// new a tunnel to client
link := conn.NewLink("udp5", "", s.task.Client.Cnf.Crypt, s.task.Client.Cnf.Compress, c.RemoteAddr().String(), false, "")
+10
View File
@@ -7,6 +7,7 @@ import (
"errors"
"net"
"net/http"
"path/filepath"
"strconv"
"ehang.io/nps/bridge"
@@ -75,6 +76,15 @@ func (s *WebServer) Start() error {
if beego.AppConfig.String("web_open_ssl") == "true" {
keyPath := beego.AppConfig.String("web_key_file")
certPath := beego.AppConfig.String("web_cert_file")
// Resolve relative paths against the nps run path instead of the
// process working directory. Otherwise the web panel fails to start
// when nps runs from another directory (e.g. as a system service).
if !filepath.IsAbs(certPath) {
certPath = filepath.Join(common.GetRunPath(), certPath)
}
if !filepath.IsAbs(keyPath) {
keyPath = filepath.Join(common.GetRunPath(), keyPath)
}
err = http.ServeTLS(l, beego.BeeApp.Handlers, certPath, keyPath)
} else {
err = http.Serve(l, beego.BeeApp.Handlers)
+15 -2
View File
@@ -5,6 +5,7 @@ import (
"github.com/astaxie/beego/utils/captcha"
"math/rand"
"net"
"strings"
"sync"
"time"
@@ -27,10 +28,22 @@ type record struct {
lastLoginTime time.Time
}
func init() {
// InitCaptcha registers the captcha image route and the create_captcha template
// function. The image URL prefix must include web_base_url, otherwise the login
// page would request the captcha from the site root and fail behind a reverse
// proxy that only forwards the web_base_url sub path.
//
// It must be called after beego.LoadAppConfig, so it cannot live in init():
// package init() runs before main() loads conf/nps.conf, where web_base_url
// would still be empty.
func InitCaptcha() {
// use beego cache system store the captcha data
store := cache.NewMemoryCache()
cpt = captcha.NewWithFilter("/captcha/", store)
base := strings.TrimSuffix(beego.AppConfig.String("web_base_url"), "/")
if base != "" && !strings.HasPrefix(base, "/") {
base = "/" + base
}
cpt = captcha.NewWithFilter(base+"/captcha/", store)
}
func (self *LoginController) Index() {
+4
View File
@@ -6,6 +6,10 @@ import (
)
func Init() {
// The captcha image path and its filter are built from web_base_url, so it
// has to be registered here (after the config is loaded) instead of in an
// init() function.
controllers.InitCaptcha()
web_base_url := beego.AppConfig.String("web_base_url")
if len(web_base_url) > 0 {
ns := beego.NewNamespace(web_base_url,
+21 -4
View File
@@ -56,6 +56,23 @@
if (flag) { return {'value':(langobj[languages['current']] || langobj[languages['default']] || 'N/A')}}
}
// Match a browser language (e.g. "zh", "zh-TW", "en-GB") to an available
// menu language key (e.g. "zh-CN", "en-US"). Exact match wins, then the
// primary subtag (before the first "-"). Returns null when nothing matches
// so the caller can fall back to the default language.
function normalizeLang (lang) {
if (!lang) return null;
var lower = ('' + lang).toLowerCase();
var primary = lower.split('-')[0];
var fallback = null;
for (var key in languages['menu']) {
var k = key.toLowerCase();
if (k === lower) return key;
if (fallback == null && k.split('-')[0] === primary) fallback = key;
}
return fallback;
}
$.fn.cloudLang = function () {
$.ajax({
type: 'GET',
@@ -65,7 +82,7 @@
languages['content'] = xml2json($(xml).children())['content'];
languages['menu'] = languages['content']['languages'];
languages['default'] = languages['content']['default'];
languages['navigator'] = (getCookie ('lang') || navigator.language || navigator.browserLanguage);
languages['navigator'] = (getCookie ('lang') || normalizeLang(navigator.language || navigator.browserLanguage) || languages['default']);
for(var key in languages['menu']){
$('#languagemenu').next().append('<li lang="' + key + '"><a><img src="' + window.nps.web_base_url + '/static/img/flag/' + key + '.png"> ' + languages['menu'][key] +'</a></li>');
if ( key == languages['navigator'] ) languages['current'] = key;
@@ -76,11 +93,11 @@
});
};
$.fn.setLang = function (dom) {
$.fn.setLang = function (dom, persistLang) {
languages['current'] = $('#languagemenu').attr('lang');
if ( dom == '' ) {
$('#languagemenu span').text(' ' + languages['menu'][languages['current']]);
if (languages['current'] != getCookie('lang')) setCookie('lang', languages['current']);
if (persistLang && languages['current'] != getCookie('lang')) setCookie('lang', languages['current'], 36500);
if($("#table").length>0) $('#table').bootstrapTable('refreshOptions', { 'locale': languages['current']});
}
$.each($(dom + ' [langtag]'), function (i, item) {
@@ -122,7 +139,7 @@ $(document).ready(function () {
$('body').cloudLang();
$('body').on('click','li[lang]',function(){
$('#languagemenu').attr('lang',$(this).attr('lang'));
$('body').setLang ('');
$('body').setLang ('', true);
});
});