Compare commits

...
60 Commits
Author SHA1 Message Date
yisier 7231be3944 解决客户端/服务端在线更新失败问题 2026-07-12 22:51:56 -06:00
yisier 1ebbee14a5 back tar.gz 2026-07-12 22:31:56 -06:00
yisier f2fe889a7c 将打包格式从 tar.gz 改为 zip 2026-07-12 22:17:54 -06:00
yisier e19af0a4d1 解决客户端建连失败后的半连接假死问题 2026-07-12 22:00:52 -06:00
yisier c62a3424bc 修复HTTP正向代理和SOCKS5认证问题 2026-07-12 21:31:06 -06:00
yisier 8508c9bd5e 解决私密代理和P2P连接的TLS启用问题 2026-07-12 19:37:53 -06:00
yisier 253c58f3c8 Web 管理端客户端/隧道/域名列表业务字段支持服务端排序(备注、状态、在线等) 2026-07-12 19:28:00 -06:00
yisier 0a096ffef4 解决握手过程中的连接超时和资源堆积问题 2026-07-12 19:05:52 -06:00
yisier b45dfe048e 新增客户端内网地址上报功能 2026-07-12 18:38:47 -06:00
yisier 3c848e5216 nps -server 安装成功后 web_port 未正常显示BUG 2026-07-12 18:20:19 -06:00
yisier 0d77cd92d5 管理界面完全从可执行文件内嵌资源加载 2026-07-12 18:04:09 -06:00
yisier b9642cc9c3 修复 Android 构建脚本中的 Fyne 工具安装路径 2026-07-04 23:50:26 -06:00
yisier c6a70c53a0 添加批量删除功能 2026-07-04 23:27:32 -06:00
yisier 70a50254d6 决 MIPS 架构运行时出现非法指令错误 2026-07-04 23:16:35 -06:00
yisier 8aacbc7bc5 解决新增编辑隧道时重复提交问题 2026-07-04 23:10:14 -06:00
yisier 67cefe1278 修复HTTP代理在SVN客户端无法正常检出的问题 2026-07-04 22:39:37 -06:00
yisier c972af584c doc 2026-06-08 15:33:12 -06:00
yisier 8e889710d7 Update README.md 2026-06-08 15:18:07 -06:00
yisier af6f9243ff md 2026-06-08 15:11:18 -06:00
yisier 9a56ea5d51 doc 2026-06-08 15:06:48 -06:00
yisier 173eeba97f md 2026-06-08 15:02:08 -06:00
yisier ca6371edb1 doc 2026-06-08 14:49:43 -06:00
yisier f57b2b7b34 doc 2026-06-08 00:29:40 -06:00
yisier e263b062c5 docs 2026-06-08 00:19:52 -06:00
yisier 29b064d65f docs 2026-06-08 00:18:04 -06:00
yisier bf6b762371 docs 2026-06-08 00:16:42 -06:00
yisier 2b5aefd1e8 doc 2026-06-08 00:11:12 -06:00
yisier 438d5084c9 doc 2026-06-07 23:46:21 -06:00
yisier e3ed556f0f doc 2026-06-07 22:35:49 -06:00
yisier cfb53ca703 doc 2026-06-07 11:04:50 -06:00
yisier 0afd382e6c doc 2026-06-07 11:03:11 -06:00
yisier ef519331e2 添加客户端到期时间功能 2026-06-06 14:13:05 -06:00
yisier 19fee9b51b 添加客户端更新功能和版本显示 2026-06-06 10:29:59 -06:00
yisier 16a7f6a4c4 修复内存泄露问题 2026-06-05 17:47:42 -06:00
yisier 1aca99b2d7 隧道/域名解析/UDP 流量始终为 0 BUG 2026-06-05 16:45:35 -06:00
yisier 2733d99cf7 优化稳定性 2026-06-05 15:56:38 -06:00
yisier 6750103337 v0.26.33 2026-05-23 17:42:38 -06:00
yisier eaff3b8c39 v0.26.33 2026-05-23 17:21:28 -06:00
yisier c9a9807dd5 v0.26.33 2026-05-23 17:11:06 -06:00
yisier 2b04bf8b5a - [#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 计算逻辑错误,改为统计每秒实际消耗字节数
2026-05-23 16:34:08 -06:00
yisier 62c84206a4 web 静态文件打包进可执行文件:启动时若 web/static、web/views 目录不存在,自动释放内嵌资源,部署不再需要单独拷贝 web 目录
精简发布包:去除打包时冗余的 conf/nps.conf、web 目录
清理失效配置项:移除 appname、runmode、https_default_cert_file、https_default_key_file、https_just_proxy
2026-05-23 14:57:54 -06:00
yisier 2650174eed feat(nps): 添加配置文件自动生成功能
- 启动时自动检查并创建 conf 目录和 nps.conf 配置文件
- 配置文件中的 web_password、auth_key、auth_crypt_key 均随机生成
- 打印默认登录凭据到控制台,提升部署便利性
- 修改 loadSyncMapFromFile 函数避免文件不存在时的 panic 错误
- 更新 README.md 添加新版本更新日志说明
2026-05-23 14:34:34 -06:00
yisier d199b26ce2 Merge pull request #327 from geniucker-dev/fix/tcp-basic-auth-preserve-buffered-bytes
fix: 保留 TCP Basic 认证探测期间已读取的数据
2026-05-14 13:51:14 -06:00
geniucker-dev 0c25ec5978 fix: preserve tcp auth probe bytes 2026-05-14 21:55:40 +08:00
yisier 055ff30e39 Merge pull request #323 from MAlanWine/master
fix: udp connection aging & overflow
2026-05-13 13:37:46 -06:00
yisier 0f39cdbe7b Merge pull request #318 from gift95/master
HTTP代理端口显示逻辑 选择是否展示端口
2026-05-13 13:37:28 -06:00
MAlanWine 4710432572 fix: udp connection aging & overflow 2026-04-19 17:52:51 +08:00
gift95 e0c8c73b91 HTTP代理端口显示逻辑 选择是否展示端口 2026-04-02 15:38:39 +08:00
yisier b39f0c30ef v0.26.32 2026-03-27 16:00:27 -06:00
yisier c1753a6d19 客户端注册参数未正确处理 2026-03-27 15:52:33 -06:00
yisier 8f384eaac4 Merge pull request #312 from okawao/dev
修复https反向代理bug
2026-03-27 06:33:25 +08:00
yisier a51d6bc50a v0.26.31 2026-03-23 17:03:28 +08:00
yisier 43144804c7 v0.26.31 2026-03-23 17:02:32 +08:00
yisier dfe4748e97 TCP隧道增加Basic认证 2026-03-23 16:43:29 +08:00
yisier 30af159034 新增隧道出现secret mode keys must be unique 2026-03-23 15:37:11 +08:00
yisier 8819907be5 域名解析记录开关功能 2026-03-23 15:16:29 +08:00
okawao 1a29ab0046 在建立tls连接时不应比较location 2026-03-14 20:05:16 +08:00
okawao 0ffec7df7f Merge branch 'master' into dev 2026-03-14 17:24:01 +08:00
okawao 876b2d2588 修复无法正确解析分段client hello;新增兼容ip证书 2026-03-14 16:44:44 +08:00
yisier af4be7f130 readme 2026-03-13 11:38:53 +08:00
142 changed files with 4613 additions and 2332 deletions
-27
View File
@@ -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 }}
-55
View File
@@ -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 }}
+60
View File
@@ -0,0 +1,60 @@
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
@@ -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:
+28 -1
View File
@@ -1,2 +1,29 @@
.idea
nps
nps
# Go build outputs
/npc
/nps.exe
/npc.exe
# Node.js / VuePress
node_modules/
yarn.lock
pnpm-lock.yaml
# VuePress build artifacts
docs/.vuepress/.cache/
docs/.vuepress/.temp/
docs/.vuepress/dist/
# VuePress dev runtime
docs/vuepress-dev.log
docs/vuepress-dev.err.log
docs/vuepress-dev.pid
docs/node_modules/
docs/yarn.lock
docs/.vscode
# OS
.DS_Store
Thumbs.db
+35 -35
View File
@@ -17,41 +17,41 @@ deploy:
token: ${GH_TOKEN}
cleanup: false
file:
- 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
- windows_386_client.tar.gz
- windows_386_server.tar.gz
- windows_amd64_client.tar.gz
- windows_amd64_server.tar.gz
- npc_syno.spk
- npc_sdk.tar.gz
- android_client.apk
- 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
- windows_386_client.tar.gz
- windows_386_server.tar.gz
- windows_amd64_client.tar.gz
- windows_amd64_server.tar.gz
- npc_syno.spk
- npc_sdk.tar.gz
- android_client.apk
on:
tags: true
all_branches: true
-1
View File
@@ -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"]
+55 -196
View File
@@ -1,216 +1,75 @@
# NPS
[新特性文档](https://dqg9t9eulqq.feishu.cn/wiki/FmVVwDcEGiTZxekYJl5ccuFanlg?from=from_copylink)
![Version](https://img.shields.io/badge/version-v0.26.36-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)
# 说明
由于nps已经停更多年,存留了不少bug和未完善的功能。
> 一款轻量级、高性能、功能强大的内网穿透代理服务器,基于 [ehang-io/nps](https://github.com/ehang-io/nps) 0.26.10 二次开发 —— 修复大量 bug,持续更新中。
> 💬 聊天灌水 QQ 群:**619833483**(热心群主可提供免费远程协助)
此版本基于 nps 0.26.10的基础上二次开发而来。
### 📖 在线文档
<small>[完整文档](https://yisier.github.io/nps) · [更新日志](https://yisier.github.io/nps/changelog/) · [程序安装](https://yisier.github.io/nps/install/#%E7%A8%8B%E5%BA%8F%E5%AE%89%E8%A3%85) · [宝塔面板](https://yisier.github.io/nps/install/#%E5%AE%9D%E5%A1%94%E9%9D%A2%E6%9D%BF-%E4%B8%80%E9%94%AE%E9%83%A8%E7%BD%B2) · [Docker安装](https://yisier.github.io/nps/install/#docker-%E5%AE%89%E8%A3%85)</small>
***DockerHub***: [NPS](https://hub.docker.com/r/yisier1/nps) [NPC](https://hub.docker.com/r/yisier1/npc)
---
## 💰 赞助 / 推荐
#### ☁️ [雨云 — 国内便宜稳定的云服务器,首月 5 折](https://www.rainyun.com/MjY0MzY1_)
500M 带宽,高仿物理机,云服务器**15 元起**,通过此链接注册首月 5 折。
***宝塔面板***:[宝塔面板 Docker](docs/bt.md)
#### 🚀 [NATNPS 云穿透 — 免费 3M 带宽 / 2 条隧道](https://natnps.com/register?utm_from=MQ==)
无需自备服务器,注册即用。免费版 3M 带宽 2 条隧道;6.8 元 12M 带宽 10 条隧道;13.8 元 24M 带宽 20 条隧道。
# 交流群
聊天灌水QQ群:619833483(2000人群),770569342
---
## 🚀 快速开始
# 广告
[NPS云穿透](https://natnps.com/register?utm_from=MQ==),免费4M带宽,2条隧道;6.8元12M带宽,10条隧道;13.8元24M带宽,20条隧道。
雨云,500M带宽服务器;云服务器15元起,[专属连接,首月5折](https://www.rainyun.com/MjY0MzY1_)。
### 下载
# 提示
强烈推荐使用无配置文件模式启动客户端(删除掉npc.exe 目录下的`conf`文件夹即可),所有数据应该在服务端保存和配置,而客户端只做连接转发。客户端配置文件对小白极不友好,配置繁琐,容易出错。
0.26.21 版本后的客户端,无需再通过命令行方式启动、安装、卸载客户端,直接双击运行,按照提示输入指令即可完成,非常方便。
从 [releases](https://github.com/yisier/nps/releases) 下载对应平台版本。服务端 `nps` 和客户端 `npc` 是独立的压缩包。
### 服务端
```shell
./nps -server # 交互菜单:安装/卸载/启动/停止/更新
```
首次启动自动生成 `conf/nps.conf`,随机生成 `web_password`、`auth_key`、`auth_crypt_key`,请从启动日志或 `nps.conf` 获取。
![img](https://raw.githubusercontent.com/yisier/nps/master/docs/.vuepress/public/image/new/server.png)
### 客户端
```shell
./npc # 直接双击运行,按提示输入即可
```
在 Web 后台复制【快捷启动命令】,客户端粘贴即可注册系统服务、启停或卸载。
# 更新日志
![image](https://raw.githubusercontent.com/yisier/nps/master/docs/.vuepress/public/image/new/cmd.png)
- 2026-03-12 v0.26.30
修复:
- http 协议 websocket 错误,感谢[xiaozonglong](https://github.com/xiaozonglong) 提供的 home assistant 环境 ,[#268](https://github.com/yisier/nps/issues/268),[#296](https://github.com/yisier/nps/issues/296)
- 域名解析中,主机url点击无法跳转非80端口 [311](https://github.com/yisier/nps/issues/311)
- 新增的主机配置页面,客户端ID异常 [#310](https://github.com/yisier/nps/issues/310)
- 自动 HTTPS(301) 按照 `https_proxy_port` 配置的端口号跳转
- 2026-01-24 v0.26.29
新增:
GUI 客户端,基于 Wails 开发,[点击查看了解更多](https://github.com/yisier/nps/blob/master/cmd/npc/npc-gui/README.md),需要 WebView2 运行时,可通过两种方式添加客户端。
方式1:直接输入快捷启动命令即可
方式2:手动添加客户端,输入-server -vkey等参数
![img.png](image/new/gui.png)
修复:
Android 包未构建到 Release [72](https://github.com/yisier/nps/issues/72)
#### 命令行直接启动
- 2025-12-06 v0.26.28
-【全局参数】页面新增`服务地址`配置项,用于客户端命令地址显示、隧道访问地址显示 [293](https://github.com/yisier/nps/issues/293)
-【IP授权功能优化】,通过穿透的端口去提交 IP 认证,感谢 [Aqamoe](https://github.com/Aqamoe) 的建议 [291](https://github.com/yisier/nps/issues/291)
-【重构限速器实现】提升性能和准确性
```shell
npc -server=ip:8024 -vkey=xxx # 标准
npc -server=ip:8025 -vkey=xxx -tls_enable=true # TLS 桥接
npc -server=ip:8024 -vkey=vkey1,vkey2 # 多隧道
```
---
## ☕ 请作者喝杯咖啡
> 如果这个项目帮到了你,可以请作者喝杯咖啡 ☕ 感谢支持!
![微信/支付宝扫码赞赏](docs/.vuepress/public/image/payme.png)
- 2025-11-05 v0.26.27
新增:
- 1.客户端新增【IP白名单】,可通过两种方式添加IP:
- 方式1️⃣:在【客户端】新建/修改页面,配置IP授权密码,不在IP白名单的外网访问将被跳转到 IP 授权页面,输入正确的授权密码,即可完成添加 IP。
- 方式2️⃣:在【客户端】新建/修改页面,直接添加IP到白名单中。
![img.png](image/new/ip.png)
- 2.客户端配置移除【压缩】和【加密】功能,此功能会显著提高内存和CPU占用率,"利大于弊"。
- 3.客户端默认不再提供配置文件,***强烈推荐使用无配置文件模式启动客户端***
---
## 📈 Star History
- 2025-08-15 v0.26.26
修复:
- windows注册服务 使用tls无法连接 [269](https://github.com/yisier/nps/issues/269)
- 域名解析自动HTTPS逻辑bug [273](https://github.com/yisier/nps/issues/273)
[![Star History Chart](https://api.star-history.com/svg?repos=yisier/nps&type=Date)](https://star-history.com/#yisier/nps&Date)
---
- 2025-05-28 v0.26.25
新增:
- nps增加`nps(.exe) -server` 命令,用于管理NPS服务,安装和卸载服务在 Linux 下需要有 sudo 权限,Windows 下需要有管理员权限。
![img.png](image/new/server.png)
- 增加【TLS快捷启动命令】,可用于在tls模式下,快速启动客户端。 [257](https://github.com/yisier/nps/issues/257)
## 📃 License
- 2025-04-16 v0.26.24
新增:
- 隧道支持复制功能,在隧道页面增加复制按钮,除了端口号为随机生成外,其他参数全部拷贝。[251](https://github.com/yisier/nps/issues/251)
修复:
- 私密代理连接时服务端会报错退出,[250](https://github.com/yisier/nps/issues/250)
- 2025-04-11 v0.26.23
新增:
- TCP 隧道支持 Proxy Protocol 协议来传递经过请求的真实 IP。![img.png](image/new/protocol.png)
修复:
- 客户端较多时,协程增长过快,感谢 [@huanglei288766](https://github.com/yisier/nps/pull/244) 的PR
- 2025-01-23 v0.26.22
优化:
- 客户端注册系统服务时,(新版客户端注册方式,非 install 命令) 将按照 `npc-[vkey].log` 格式保存日志,每个客户端VKEY单独一个日志文件,windows 日志位于 `npc.exe` 同级目录下,linux 位于 `/var/log/`目录。
- 域名模式,HTTPS证书支持上传文件和文件路径,系统将自动识别路径还是证书内容。 [#175](https://github.com/yisier/nps/issues/175)
修复:
- ipv6地址显示不全 [#237](https://github.com/yisier/nps/issues/237)
- 2025-01-07 v0.26.21
新增:
- 客户端列表页面新增【快捷启动命令】,此命令为连接地址+链接秘钥的base64编码,方便一键启动、一键安装客户端。
- 域名解析和隧道列表增加访问地址,可以点击隧道链接,直接网页打开。 [#234](https://github.com/yisier/nps/issues/234)
优化:
- 修改vkey生成方式,由16位缩短至10位,截取uuid前10位,避免重复。
- 优化客户端启动方式,当npc文件目录下无配置文件时,可直接双击运行客户端,输入命令完成启动、安装、卸载客户端,直接启动和安装服务时需要输入【快捷启动命令】,卸载服务、启动服务、停止服务时,只需输入隧道秘钥【vkey】即可。安装服务以 nps-client-vkey 方式命名 ,实现注册多个服务。
![image](image/new/cmd.png)
**注意**
强烈推荐使用无配置文件模式启动客户端,所有数据应该在服务端保存和配置,而客户端只做连接转发。客户端配置文件对小白极不友好,配置繁琐,容易出错。
- 2024-11-07 v0.26.20
新增:
- 客户端增加创建时间
修复:
- 客户端限速单位不统一 [#185](https://github.com/yisier/nps/issues/185)
- 增加从下拉选择客户端,隧道列表排序,新增编辑后不会刷新界面 [#183](https://github.com/yisier/nps/issues/183)
- 隧道数量限制无法统计域名映射 [#209](https://github.com/yisier/nps/issues/209)
- 2024-06-01 v0.26.19
- golang 版本升级到 1.22.
- 增加自动https,自动将http 重定向(301)到 https.
- 客户端命令行方式启动支持多个隧道ID,使用逗号拼接,示例:`npc -server=xxx:8024 -vkey=ytkpyr0er676m0r7,iwnbjfbvygvzyzzt` .
- 移除 nps.conf 参数 `https_just_proxy` , 调整 https 处理逻辑,如果上传了 https 证书,则由nps负责SSL (此方式可以获取真实IP),
否则走端口转发模式(使用本地证书,nps 获取不到真实IP), 如下图所示。
![image](image/new/https.png)
- 2024-02-27 v0.26.18
***新增***:nps.conf 新增 `tls_bridge_port=8025` 参数,当 `tls_enable=true` 时,nps 会监听8025端口,作为 tls 的连接端口。
客户端可以选择连接 tls 端口或者非 tls 端口: `npc.exe -server=xxx:8024 -vkey=xxx` 或 `npc.exe -server=xxx:8025 -vkey=xxx -tls_enable=true`
- 2024-01-31 v0.26.17
***说明***:考虑到 npc 历史版本客户端众多,版本号不同旧版本客户端无法连接,为了兼容,仓库版本号将继续沿用 0.26.xx
- 2024-01-02 v0.27.01 (已作废,功能移动到v0.26.17 版本)
***新增***:tls 流量加密,(客户端忽略证书校验,谨慎使用,客户端与服务端需要同时开启,或同时关闭),使用方式:
服务端:nps.conf `tls_enable=true`;
客户端:npc.conf `tls_enable=true` 或者 `npc.exe -server=xxx -vkey=xxx -tls_enable=true`
- 2023-06-01 v0.26.16
***修复***:https 流量不统计 Bug 修复。
***新增***:新增全局黑名单IP,用于防止被肉鸡扫描端口或被恶意攻击。
***新增***:新增客户端上次在线时间。
- 2023-02-24 v0.26.15
***修复***:更新程序 url 更改到当前仓库中
***修复***:nps 在外部路径启动时找不到配置文件
***新增***:增加 nps 启动参数,`-conf_path=D:\test\nps`,可用于加载指定nps配置文件和web文件目录。
***window 使用示例:***
直接启动:`nps.exe -conf_path=D:\test\nps`
安装:`nps.exe install -conf_path=D:\test\nps`
安装启动:`nps.exe start`
***linux 使用示例:***
直接启动:`./nps -conf_path=/app/nps`
安装:`./nps install -conf_path=/app/nps`
安装启动:`nps start -conf_path=/app/nps`
- 2022-12-30 v0.26.14
***修复***:API 鉴权漏洞修复
- 2022-12-19
***修复***:某些场景下丢包导致服务端意外退出
***优化***:新增隧道时,不指定服务端口时,将自动生成端口号
***优化***:API返回ID, `/client/add/, /index/addhost/,/index/add/ `
***优化***:域名解析、隧道页面,增加[唯一验证密钥],方便搜查
- 2022-10-30
***新增***:在管理面板中新增客户端时,可以配置多个黑名单IP,用于防止被肉鸡扫描端口或被恶意攻击。
***优化***:0.26.12 版本还原了注册系统功能,使用方式和以前一样。无论是否注册了系统服务,直接执行 nps 时只会读取当前目录下的配置文件。
- 2022-10-27
***新增***:在管理面板登录时开启验证码校验,开启方式:nps.conf `open_captcha=true`,感谢 [@dongFangTuring](https://github.com/dongFangTuring) 提供的PR
- 2022-10-24:
***修复***:HTTP协议支持WebSocket(稳定性待测试)
- 2022-10-21:
***修复***:HTTP协议下实时统计流量,能够精准的限制住流量(上下行对等)
***优化***:删除HTTP隧道时,客户端已用流量不再清空
- 2022-10-19:
***BUG***:在TCP协议下,流量统计有问题,只有当连接断开时才会统计流量。例如,限制客户端流量20m,当传输100m的文件时,也能传输成功。
***修复***:TCP协议下实时统计流量,能够精准的限制住流量(上下行对等)
***优化***:删除TCP隧道时,客户端已用流量不再清空
![image](image/new/tcp_limit.png)
- 2022-09-14:
修改NPS工作目录为当前可执行文件目录(即配置文件和nps可执行文件放在同一目录下,直接执行nps文件即可),去除注册系统服务,启动、停止、升级等命令
# 捐赠
![image](image/new/payCode.png)
GPL-3.0 License — 基于 [ehang-io/nps](https://github.com/ehang-io/nps) 0.26.10 二次开发。
+105 -24
View File
@@ -12,6 +12,7 @@ import (
"strconv"
"strings"
"sync"
"sync/atomic"
"time"
"ehang.io/nps/lib/common"
@@ -28,11 +29,12 @@ import (
var ServerTlsEnable bool = false
type Client struct {
mu sync.Mutex // 保护 signal/tunnel/Version 等字段的并发读写
tunnel *nps_mux.Mux
signal *conn.Conn
file *nps_mux.Mux
Version string
retryTime int // it will be add 1 when ping not ok until to 3 will close the client
retryTime atomic.Int32 // it will be add 1 when ping not ok until to 3 will close the client
}
func NewClient(t, f *nps_mux.Mux, s *conn.Conn, vs string) *Client {
@@ -115,6 +117,37 @@ func (s *Bridge) StartTunnel() error {
return nil
}
// requestClientLocalAddr asks the client for private/LAN IPs on the main signal conn.
// New clients reply with WriteLenContent; old clients ignore the flag and we time out.
func (s *Bridge) requestClientLocalAddr(id int, c *conn.Conn) {
if c == nil || c.Conn == nil {
return
}
if _, err := c.Write([]byte(common.REPORT_LOCAL_IP)); err != nil {
return
}
_ = c.Conn.SetReadDeadline(time.Now().Add(2 * time.Second))
defer func() {
// clear deadline so health / later reads are not affected
_ = c.Conn.SetReadDeadline(time.Time{})
}()
b, err := c.GetShortLenContent()
if err != nil {
logs.Trace("clientId %d did not report local addr (old client or timeout): %v", id, err)
return
}
localAddr := strings.TrimSpace(string(b))
if localAddr == "" {
return
}
if client, err := file.GetDb().GetClient(id); err == nil {
client.Lock()
client.LocalAddr = localAddr
client.Unlock()
logs.Info("clientId %d local addr: %s", id, localAddr)
}
}
// get health information form client
func (s *Bridge) GetHealthFromClient(id int, c *conn.Conn) {
for {
@@ -183,6 +216,7 @@ func (s *Bridge) GetHealthFromClient(id int, c *conn.Conn) {
// 验证失败,返回错误验证flag,并且关闭连接
func (s *Bridge) verifyError(c *conn.Conn) {
c.Write([]byte(common.VERIFY_EER))
c.Close()
}
func (s *Bridge) verifySuccess(c *conn.Conn) {
@@ -190,16 +224,19 @@ func (s *Bridge) verifySuccess(c *conn.Conn) {
}
func (s *Bridge) cliProcess(c *conn.Conn) {
// 握手 10s 超时:扫描/半开连接不会一直占着 goroutine;成功后清掉
_ = c.SetReadDeadline(time.Now().Add(10 * time.Second))
//read test flag
if _, err := c.GetShortContent(3); err != nil {
logs.Info("The client %s connect error", c.Conn.RemoteAddr(), err.Error())
c.Close()
return
}
//version check
if b, err := c.GetShortLenContent(); err != nil || string(b) != version.GetVersion() {
//logs.Info("The client %s version does not match", c.Conn.RemoteAddr())
//c.Close()
//return
//version check(版本不匹配仍兼容放行;读失败则断开)
if _, err := c.GetShortLenContent(); err != nil {
c.Close()
return
}
//version get
var vs []byte
@@ -211,7 +248,7 @@ func (s *Bridge) cliProcess(c *conn.Conn) {
}
//write server version to client
c.Write([]byte(crypt.Md5(version.GetVersion())))
c.SetReadDeadlineBySecond(5)
_ = c.SetReadDeadline(time.Now().Add(10 * time.Second))
var buf []byte
//get vKey from client
if buf, err = c.GetShortContent(32); err != nil {
@@ -228,17 +265,25 @@ func (s *Bridge) cliProcess(c *conn.Conn) {
s.verifySuccess(c)
}
if flag, err := c.ReadFlag(); err == nil {
// 握手完成,交给 typeDeal 做长连接
_ = c.SetReadDeadline(time.Time{})
s.typeDeal(flag, c, id, string(vs))
} else {
logs.Warn(err, flag)
c.Close()
}
return
}
func (s *Bridge) DelClient(id int) {
if v, ok := s.Client.Load(id); ok {
if v.(*Client).signal != nil {
v.(*Client).signal.Close()
cl := v.(*Client)
cl.mu.Lock()
signalToClose := cl.signal
cl.signal = nil
cl.mu.Unlock()
if signalToClose != nil {
signalToClose.Close()
}
s.Client.Delete(id)
if file.GetDb().IsPubClient(id) {
@@ -267,18 +312,32 @@ func (s *Bridge) typeDeal(typeVal string, c *conn.Conn, id int, vs string) {
}
//the vKey connect by another ,close the client of before
if v, ok := s.Client.LoadOrStore(id, NewClient(nil, nil, c, vs)); ok {
if v.(*Client).signal != nil {
v.(*Client).signal.WriteClose()
cl := v.(*Client)
cl.mu.Lock()
oldSignal := cl.signal
cl.signal = c
cl.Version = vs
cl.mu.Unlock()
cl.retryTime.Store(0)
if oldSignal != nil {
oldSignal.WriteClose()
}
v.(*Client).signal = c
v.(*Client).Version = vs
}
// Request private/LAN IPs from client. Old clients ignore the flag; short timeout keeps compatibility.
s.requestClientLocalAddr(id, c)
go s.GetHealthFromClient(id, c)
logs.Info("clientId %d connection succeeded, address:%s ", id, c.Conn.RemoteAddr())
case common.WORK_CHAN:
muxConn := nps_mux.NewMux(c.Conn, s.tunnelType, s.disconnectTime)
if v, ok := s.Client.LoadOrStore(id, NewClient(muxConn, nil, nil, vs)); ok {
v.(*Client).tunnel = muxConn
cl := v.(*Client)
cl.mu.Lock()
oldTunnel := cl.tunnel
cl.tunnel = muxConn
cl.mu.Unlock()
if oldTunnel != nil {
oldTunnel.Close()
}
}
case common.WORK_CONFIG:
client, err := file.GetDb().GetClient(id)
@@ -299,7 +358,14 @@ func (s *Bridge) typeDeal(typeVal string, c *conn.Conn, id int, vs string) {
case common.WORK_FILE:
muxConn := nps_mux.NewMux(c.Conn, s.tunnelType, s.disconnectTime)
if v, ok := s.Client.LoadOrStore(id, NewClient(nil, muxConn, nil, vs)); ok {
v.(*Client).file = muxConn
cl := v.(*Client)
cl.mu.Lock()
oldFile := cl.file
cl.file = muxConn
cl.mu.Unlock()
if oldFile != nil {
oldFile.Close()
}
}
case common.WORK_P2P:
//read md5 secret
@@ -311,15 +377,22 @@ func (s *Bridge) typeDeal(typeVal string, c *conn.Conn, id int, vs string) {
if v, ok := s.Client.Load(t.Client.Id); !ok {
return
} else {
cl := v.(*Client)
cl.mu.Lock()
sig := cl.signal
cl.mu.Unlock()
if sig == nil {
return
}
//向密钥对应的客户端发送与服务端udp建立连接信息,地址,密钥
v.(*Client).signal.Write([]byte(common.NEW_UDP_CONN))
sig.Write([]byte(common.NEW_UDP_CONN))
svrAddr := beego.AppConfig.String("p2p_ip") + ":" + beego.AppConfig.String("p2p_port")
if err != nil {
logs.Warn("get local udp addr error")
return
}
v.(*Client).signal.WriteLenContent([]byte(svrAddr))
v.(*Client).signal.WriteLenContent(b)
sig.WriteLenContent([]byte(svrAddr))
sig.WriteLenContent(b)
//向该请求者发送建立连接请求,服务器地址
c.WriteLenContent([]byte(svrAddr))
}
@@ -356,11 +429,14 @@ func (s *Bridge) SendLinkInfo(clientId int, link *conn.Link, t *file.Tunnel) (ta
}
}
var tunnel *nps_mux.Mux
cl := v.(*Client)
cl.mu.Lock()
if t != nil && t.Mode == "file" {
tunnel = v.(*Client).file
tunnel = cl.file
} else {
tunnel = v.(*Client).tunnel
tunnel = cl.tunnel
}
cl.mu.Unlock()
if tunnel == nil {
err = errors.New("the client connect error")
return
@@ -393,14 +469,19 @@ func (s *Bridge) ping() {
arr := make([]int, 0)
s.Client.Range(func(key, value interface{}) bool {
v := value.(*Client)
if v.tunnel == nil || v.signal == nil {
v.retryTime += 1
if v.retryTime >= 3 {
v.mu.Lock()
tunnel := v.tunnel
signal := v.signal
if tunnel == nil || signal == nil {
v.mu.Unlock()
if v.retryTime.Add(1) >= 3 {
arr = append(arr, key.(int))
}
return true
}
if v.tunnel.IsClose {
isClose := tunnel.IsClose()
v.mu.Unlock()
if isClose {
arr = append(arr, key.(int))
}
return true
+1 -1
View File
@@ -18,7 +18,7 @@ export PATH="/usr/local/go/bin:$PATH"
export GOTOOLCHAIN=auto
go version
GO111MODULE=on go install fyne.io/fyne/v2/cmd/fyne@latest
GO111MODULE=on go install fyne.io/tools/cmd/fyne@latest
export PATH="$PATH:$(go env GOPATH)/bin"
#mkdir -p /go/src/fyne.io
#cd src/fyne.io
+42 -42
View File
@@ -8,160 +8,160 @@ tar -czvf npc_sdk.tar.gz npc_sdk.dll npc_sdk.so npc_sdk.h
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
tar -czvf linux_amd64_client.tar.gz npc
tar -czvf linux_amd64_client.tar.gz npc
CGO_ENABLED=0 GOOS=linux GOARCH=386 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
tar -czvf linux_386_client.tar.gz npc
tar -czvf linux_386_client.tar.gz npc
CGO_ENABLED=0 GOOS=freebsd GOARCH=386 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
tar -czvf freebsd_386_client.tar.gz npc
tar -czvf freebsd_386_client.tar.gz npc
CGO_ENABLED=0 GOOS=freebsd GOARCH=amd64 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
tar -czvf freebsd_amd64_client.tar.gz npc
tar -czvf freebsd_amd64_client.tar.gz npc
CGO_ENABLED=0 GOOS=freebsd GOARCH=arm go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
tar -czvf freebsd_arm_client.tar.gz npc
tar -czvf freebsd_arm_client.tar.gz npc
CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=7 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
tar -czvf linux_arm_v7_client.tar.gz npc
tar -czvf linux_arm_v7_client.tar.gz npc
CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=6 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
tar -czvf linux_arm_v6_client.tar.gz npc
tar -czvf linux_arm_v6_client.tar.gz npc
CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=5 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
tar -czvf linux_arm_v5_client.tar.gz npc
tar -czvf linux_arm_v5_client.tar.gz npc
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
tar -czvf linux_arm64_client.tar.gz npc
tar -czvf linux_arm64_client.tar.gz npc
CGO_ENABLED=0 GOOS=linux GOARCH=mips64 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
CGO_ENABLED=0 GOOS=linux GOARCH=mips64 GOMIPS64=softfloat go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
tar -czvf linux_mips64_client.tar.gz npc
tar -czvf linux_mips64_client.tar.gz npc
CGO_ENABLED=0 GOOS=linux GOARCH=mips64le go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
CGO_ENABLED=0 GOOS=linux GOARCH=mips64le GOMIPS64=softfloat go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
tar -czvf linux_mips64le_client.tar.gz npc
tar -czvf linux_mips64le_client.tar.gz npc
CGO_ENABLED=0 GOOS=linux GOARCH=mipsle go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
CGO_ENABLED=0 GOOS=linux GOARCH=mipsle GOMIPS=softfloat go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
tar -czvf linux_mipsle_client.tar.gz npc
tar -czvf linux_mipsle_client.tar.gz npc
CGO_ENABLED=0 GOOS=linux GOARCH=mips go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
CGO_ENABLED=0 GOOS=linux GOARCH=mips GOMIPS=softfloat go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
tar -czvf linux_mips_client.tar.gz npc
tar -czvf linux_mips_client.tar.gz npc
CGO_ENABLED=0 GOOS=windows GOARCH=386 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
tar -czvf windows_386_client.tar.gz npc.exe
tar -czvf windows_386_client.tar.gz npc.exe
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
tar -czvf windows_amd64_client.tar.gz npc.exe
tar -czvf windows_amd64_client.tar.gz npc.exe
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
tar -czvf darwin_amd64_client.tar.gz npc
tar -czvf darwin_amd64_client.tar.gz npc
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
tar -czvf darwin_arm64_client.tar.gz npc
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
CGO_ENABLED=0 GOOS=linux GOARCH=mips GOMIPS=softfloat 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
CGO_ENABLED=0 GOOS=linux GOARCH=mips64 GOMIPS64=softfloat 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
CGO_ENABLED=0 GOOS=linux GOARCH=mips64le GOMIPS64=softfloat 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
CGO_ENABLED=0 GOOS=linux GOARCH=mipsle GOMIPS=softfloat 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
+26 -26
View File
@@ -1,5 +1,5 @@
#/bash/sh
export VERSION=0.26.30
export VERSION=0.26.33
export GOPROXY=direct
sudo apt-get update
@@ -13,71 +13,71 @@ tar -xvf upx-3.95-amd64_linux.tar.xz
cp upx-3.95-amd64_linux/upx ./
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
tar -czvf linux_amd64_client.tar.gz npc
tar -czvf linux_amd64_client.tar.gz npc
CGO_ENABLED=0 GOOS=linux GOARCH=386 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
tar -czvf linux_386_client.tar.gz npc
tar -czvf linux_386_client.tar.gz npc
CGO_ENABLED=0 GOOS=freebsd GOARCH=386 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
tar -czvf freebsd_386_client.tar.gz npc
tar -czvf freebsd_386_client.tar.gz npc
CGO_ENABLED=0 GOOS=freebsd GOARCH=amd64 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
tar -czvf freebsd_amd64_client.tar.gz npc
tar -czvf freebsd_amd64_client.tar.gz npc
CGO_ENABLED=0 GOOS=freebsd GOARCH=arm go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
tar -czvf freebsd_arm_client.tar.gz npc
tar -czvf freebsd_arm_client.tar.gz npc
CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=7 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
tar -czvf linux_arm_v7_client.tar.gz npc
tar -czvf linux_arm_v7_client.tar.gz npc
CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=6 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
tar -czvf linux_arm_v6_client.tar.gz npc
tar -czvf linux_arm_v6_client.tar.gz npc
CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=5 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
tar -czvf linux_arm_v5_client.tar.gz npc
tar -czvf linux_arm_v5_client.tar.gz npc
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
tar -czvf linux_arm64_client.tar.gz npc
tar -czvf linux_arm64_client.tar.gz npc
CGO_ENABLED=0 GOOS=linux GOARCH=mips64 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
tar -czvf linux_mips64_client.tar.gz npc
CGO_ENABLED=0 GOOS=linux GOARCH=mips64 GOMIPS64=softfloat go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
tar -czvf linux_mips64_client.tar.gz npc
CGO_ENABLED=0 GOOS=linux GOARCH=mips64le go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
tar -czvf linux_mips64le_client.tar.gz npc
CGO_ENABLED=0 GOOS=linux GOARCH=mips64le GOMIPS64=softfloat go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
tar -czvf linux_mips64le_client.tar.gz npc
CGO_ENABLED=0 GOOS=linux GOARCH=mipsle go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
tar -czvf linux_mipsle_client.tar.gz npc
CGO_ENABLED=0 GOOS=linux GOARCH=mipsle GOMIPS=softfloat go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
tar -czvf linux_mipsle_client.tar.gz npc
CGO_ENABLED=0 GOOS=linux GOARCH=mips go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
tar -czvf linux_mips_client.tar.gz npc
CGO_ENABLED=0 GOOS=linux GOARCH=mips GOMIPS=softfloat go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
tar -czvf linux_mips_client.tar.gz npc
CGO_ENABLED=0 GOOS=windows GOARCH=386 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
tar -czvf windows_386_client.tar.gz npc.exe
tar -czvf windows_386_client.tar.gz npc.exe
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
tar -czvf windows_amd64_client.tar.gz npc.exe
tar -czvf windows_amd64_client.tar.gz npc.exe
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
tar -czvf darwin_amd64_client.tar.gz npc
tar -czvf darwin_amd64_client.tar.gz npc
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/npc/npc.go
tar -czvf darwin_arm64_client.tar.gz npc
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
@@ -116,19 +116,19 @@ CGO_ENABLED=0 GOOS=freebsd GOARCH=amd64 go build -ldflags "-s -w -extldflags -st
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
CGO_ENABLED=0 GOOS=linux GOARCH=mips go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/nps/nps.go
CGO_ENABLED=0 GOOS=linux GOARCH=mips GOMIPS=softfloat 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
CGO_ENABLED=0 GOOS=linux GOARCH=mips64 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/nps/nps.go
CGO_ENABLED=0 GOOS=linux GOARCH=mips64 GOMIPS64=softfloat 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
CGO_ENABLED=0 GOOS=linux GOARCH=mips64le go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/nps/nps.go
CGO_ENABLED=0 GOOS=linux GOARCH=mips64le GOMIPS64=softfloat 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
CGO_ENABLED=0 GOOS=linux GOARCH=mipsle go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/nps/nps.go
CGO_ENABLED=0 GOOS=linux GOARCH=mipsle GOMIPS=softfloat 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
+38 -14
View File
@@ -34,6 +34,7 @@ type TRPClient struct {
cnf *config.Config
disconnectTime int
once sync.Once
closeCh chan struct{} // closed when client is shutting down; stops ping
logger *logs.BeeLogger // 每个客户端独立的 logger
}
@@ -48,6 +49,7 @@ func NewRPClient(svraddr string, vKey string, bridgeConnType string, proxyUrl st
cnf: cnf,
disconnectTime: disconnectTime,
once: sync.Once{},
closeCh: make(chan struct{}),
logger: nil, // 默认使用全局 logger,可通过 SetLogger 设置
}
}
@@ -134,6 +136,7 @@ retry:
// handle main connection
func (s *TRPClient) handleMain() {
mainLoop:
for {
flags, err := s.signal.ReadFlag()
if err != nil {
@@ -141,11 +144,19 @@ func (s *TRPClient) handleMain() {
break
}
switch flags {
case common.REPORT_LOCAL_IP:
// server requests private/LAN IPs (new nps); ignore failures so main loop continues
localIPs := common.GetLocalIPs(s.signal.Conn)
if err := s.signal.WriteLenContent([]byte(localIPs)); err != nil {
s.logWarn("report local ip failed: %s", err.Error())
} else {
s.logInfo("reported local addr: %s", localIPs)
}
case common.NEW_UDP_CONN:
//read server udp addr and password
if lAddr, err := s.signal.GetShortLenContent(); err != nil {
s.logWarn(err.Error())
return
break mainLoop
} else if pwd, err := s.signal.GetShortLenContent(); err == nil {
var localAddr string
//The local port remains unchanged for a certain period of time
@@ -153,7 +164,7 @@ func (s *TRPClient) handleMain() {
tmpConn, err := common.GetLocalUdpAddr()
if err != nil {
s.logError(err.Error())
return
break mainLoop
}
localAddr = tmpConn.LocalAddr().String()
} else {
@@ -203,7 +214,10 @@ func (s *TRPClient) newUdpConn(localAddr, rAddr string, md5Password string) {
func (s *TRPClient) newChan() {
tunnel, err := NewConn(s.bridgeConnType, s.vKey, s.svrAddr, common.WORK_CHAN, s.proxyUrl)
if err != nil {
s.logError("connect to %s error: %v", s.svrAddr, err)
// WORK_MAIN may already be up; without Close the client stays half-connected
// (handleMain blocks, outer reconnect loop never runs). See #115.
s.logError("connect to %s error: %v, client will reconnect", s.svrAddr, err)
s.Close()
return
}
s.tunnel = nps_mux.NewMux(tunnel.Conn, s.bridgeConnType, s.disconnectTime)
@@ -239,8 +253,9 @@ func (s *TRPClient) handleChan(src net.Conn) {
srcConn.Close()
targetConn.Close()
}()
br := bufio.NewReader(srcConn)
for {
if r, err := http.ReadRequest(bufio.NewReader(srcConn)); err != nil {
if r, err := http.ReadRequest(br); err != nil {
srcConn.Close()
targetConn.Close()
break
@@ -307,7 +322,7 @@ func (s *TRPClient) handleChan(src net.Conn) {
}
}
conn.CopyWaitGroup(src, targetConn, lk.Crypt, lk.Compress, nil, nil, false, nil, nil)
conn.CopyWaitGroup(src, targetConn, lk.Crypt, lk.Compress, nil, nil, false, nil, nil, nil)
}
}
@@ -324,20 +339,22 @@ func (s *TRPClient) handleUdp(serverConn net.Conn) {
defer serverConn.Close()
b := common.BufPoolUdp.Get().([]byte)
defer common.BufPoolUdp.Put(b)
var buf bytes.Buffer
for {
n, raddr, err := local.ReadFrom(b)
if err != nil {
s.logError("read data from remote server error %s", err.Error())
return
}
buf := bytes.Buffer{}
buf.Reset()
dgram := common.NewUDPDatagram(common.NewUDPHeader(0, 0, common.ToSocksAddr(raddr)), b[:n])
dgram.Write(&buf)
b, err := conn.GetLenBytes(buf.Bytes())
data, err := conn.GetLenBytes(buf.Bytes())
if err != nil {
s.logWarn("get len bytes error %s", err.Error())
continue
}
if _, err := serverConn.Write(b); err != nil {
if _, err := serverConn.Write(data); err != nil {
s.logError("write data to remote error %s", err.Error())
return
}
@@ -373,14 +390,18 @@ func (s *TRPClient) handleUdp(serverConn net.Conn) {
// Whether the monitor channel is closed
func (s *TRPClient) ping() {
s.ticker = time.NewTicker(time.Second * 5)
loop:
defer s.ticker.Stop()
for {
select {
case <-s.ticker.C:
if s.tunnel != nil && s.tunnel.IsClose {
// tunnel still nil: newChan failed or still connecting; if Close already ran, closeCh fires.
// tunnel established then closed: tear down so outer loop can reconnect.
if s.tunnel != nil && s.tunnel.IsClose() {
s.Close()
break loop
return
}
case <-s.closeCh:
return
}
}
}
@@ -392,13 +413,16 @@ func (s *TRPClient) Close() {
func (s *TRPClient) closing() {
CloseClient = true
NowStatus = 0
// unblock ping; safe: closing runs only once via once.Do
select {
case <-s.closeCh:
default:
close(s.closeCh)
}
if s.tunnel != nil {
_ = s.tunnel.Close()
}
if s.signal != nil {
_ = s.signal.Close()
}
if s.ticker != nil {
s.ticker.Stop()
}
}
+33 -30
View File
@@ -2,12 +2,12 @@ package client
import (
"bufio"
"context"
"crypto/tls"
"encoding/base64"
"encoding/binary"
"errors"
"fmt"
"io/ioutil"
"log"
"math"
"math/rand"
@@ -147,7 +147,7 @@ re:
}
vkey = string(b)
}
ioutil.WriteFile(filepath.Join(common.GetTmpPath(), "npc_vkey.txt"), []byte(vkey), 0600)
os.WriteFile(filepath.Join(common.GetTmpPath(), "npc_vkey.txt"), []byte(vkey), 0600)
//send hosts to server
for _, v := range cnf.Hosts {
@@ -343,6 +343,7 @@ func handleP2PUdp(localAddr, rAddr, md5Password, role string) (remoteAddress str
if err != nil {
return
}
defer localConn.Close()
err = getRemoteAddressFromServer(rAddr, localConn, md5Password, role, 0)
if err != nil {
logs.Error(err)
@@ -359,27 +360,32 @@ func handleP2PUdp(localAddr, rAddr, md5Password, role string) (remoteAddress str
return
}
var remoteAddr1, remoteAddr2, remoteAddr3 string
// 修复:添加超时,避免无限等待远端响应
localConn.SetReadDeadline(time.Now().Add(30 * time.Second))
buf := make([]byte, 1024)
for {
buf := make([]byte, 1024)
if n, addr, er := localConn.ReadFromUDP(buf); er != nil {
err = er
var n int
var addr *net.UDPAddr
n, addr, err = localConn.ReadFromUDP(buf)
if err != nil {
localConn.SetReadDeadline(time.Time{})
return
} else {
rAddr2, _ := getNextAddr(rAddr, 1)
rAddr3, _ := getNextAddr(rAddr, 2)
switch addr.String() {
case rAddr:
remoteAddr1 = string(buf[:n])
case rAddr2:
remoteAddr2 = string(buf[:n])
case rAddr3:
remoteAddr3 = string(buf[:n])
}
}
rAddr2, _ := getNextAddr(rAddr, 1)
rAddr3, _ := getNextAddr(rAddr, 2)
switch addr.String() {
case rAddr:
remoteAddr1 = string(buf[:n])
case rAddr2:
remoteAddr2 = string(buf[:n])
case rAddr3:
remoteAddr3 = string(buf[:n])
}
if remoteAddr1 != "" && remoteAddr2 != "" && remoteAddr3 != "" {
break
}
}
localConn.SetReadDeadline(time.Time{})
if remoteAddress, err = sendP2PTestMsg(localConn, remoteAddr1, remoteAddr2, remoteAddr3); err != nil {
return
}
@@ -389,9 +395,8 @@ func handleP2PUdp(localAddr, rAddr, md5Password, role string) (remoteAddress str
func sendP2PTestMsg(localConn *net.UDPConn, remoteAddr1, remoteAddr2, remoteAddr3 string) (string, error) {
logs.Trace(remoteAddr3, remoteAddr2, remoteAddr1)
defer localConn.Close()
isClose := false
defer func() { isClose = true }()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
interval, err := getAddrInterval(remoteAddr1, remoteAddr2, remoteAddr3)
if err != nil {
return "", err
@@ -410,10 +415,9 @@ func sendP2PTestMsg(localConn *net.UDPConn, remoteAddr1, remoteAddr2, remoteAddr
defer ticker.Stop()
for {
select {
case <-ctx.Done():
return
case <-ticker.C:
if isClose {
return
}
if _, err := localConn.WriteTo([]byte(common.WORK_P2P_CONNECT), remoteUdpAddr); err != nil {
return
}
@@ -436,10 +440,9 @@ func sendP2PTestMsg(localConn *net.UDPConn, remoteAddr1, remoteAddr2, remoteAddr
defer ticker.Stop()
for {
select {
case <-ctx.Done():
return
case <-ticker.C:
if isClose {
return
}
if _, err := localConn.WriteTo([]byte(common.WORK_P2P_CONNECT), remoteUdpAddr); err != nil {
return
}
@@ -552,13 +555,13 @@ func getRandomPortArr(min, max int) []int {
for i := min; i <= max; i++ {
addrAddr[max-i] = i
}
rand.Seed(time.Now().UnixNano())
var r, temp int
r := rand.New(rand.NewSource(time.Now().UnixNano()))
var ri, temp int
for i := max - min; i > 0; i-- {
r = rand.Int() % i
ri = r.Int() % i
temp = addrAddr[i]
addrAddr[i] = addrAddr[r]
addrAddr[r] = temp
addrAddr[i] = addrAddr[ri]
addrAddr[ri] = temp
}
return addrAddr
}
+2 -2
View File
@@ -161,7 +161,7 @@ func handleSecret(localTcpConn net.Conn, config *config.CommonConfig, l *config.
logs.Error("Local connection server failed ", err.Error())
return
}
conn.CopyWaitGroup(remoteConn.Conn, localTcpConn, false, false, nil, nil, false, nil, nil)
conn.CopyWaitGroup(remoteConn.Conn, localTcpConn, false, false, nil, nil, false, nil, nil, nil)
}
func handleP2PVisitor(localTcpConn net.Conn, config *config.CommonConfig, l *config.LocalServer) {
@@ -178,7 +178,7 @@ func handleP2PVisitor(localTcpConn net.Conn, config *config.CommonConfig, l *con
udpConnStatus = false
return
} else {
conn.CopyWaitGroup(target, localTcpConn, false, config.Client.Cnf.Compress, nil, nil, false, nil, nil)
conn.CopyWaitGroup(target, localTcpConn, false, config.Client.Cnf.Compress, nil, nil, false, nil, nil, nil)
}
}
+1 -1
View File
@@ -14,7 +14,7 @@
},
"info": {
"productName": "NPS Client",
"productVersion": "0.26.30",
"productVersion": "0.26.33",
"companyName": "NPS",
"copyright": "Copyright © 2026 NPS"
},
+18 -4
View File
@@ -213,6 +213,8 @@ func run() {
common.InitPProfFromArg(*pprofAddr)
//p2p or secret command
if *password != "" {
client.SetTlsEnable(*tlsEnable)
logs.Info("the version of client is %s, the core version of client is %s,tls enable is %t", version.VERSION, version.GetVersion(), client.GetTlsEnable())
commonConfig := new(config.CommonConfig)
commonConfig.Server = *serverAddr
commonConfig.VKey = *verifyKey
@@ -292,8 +294,10 @@ func printSlogan() {
fmt.Printf("\u001B[32m输入[3]\u001B[0m - 启动系统服务\n")
fmt.Printf("\u001B[32m输入[4]\u001B[0m - 停止系统服务\n")
fmt.Printf("---------------------\n")
fmt.Printf("\u001B[32m输入[5]\u001B[0m - 更新客户端\n")
fmt.Printf("\u001B[32m输入[0]\u001B[0m - 退出\n")
fmt.Printf("---------------------\n")
fmt.Printf("\u001B[32m当前版本:%s\u001B[0m\n", version.VERSION)
fmt.Printf("直接输入[快捷启动命令]则是启动隧道,多个[快捷启动命令]用英文逗号拼接\n")
fmt.Printf("\n")
}
@@ -314,8 +318,8 @@ func inputCmd() {
flag := strings.Replace(flag, " ", "", -1)
// 如果输入不等于 1,2,3,4,则启动隧道
if flag != "1" && flag != "2" && flag != "3" && flag != "4" {
// 如果输入不等于 1,2,3,4,5,则启动隧道
if flag != "1" && flag != "2" && flag != "3" && flag != "4" && flag != "5" {
vkeys := strings.Split(flag, `,`)
var cmdArray []string
@@ -336,7 +340,12 @@ func inputCmd() {
}
} else {
systemService(flag)
if flag == "5" {
install.UpdateNpcNew()
inputCmd()
} else {
systemService(flag)
}
}
}
}
@@ -410,8 +419,13 @@ func systemService(flag string) {
for _, item := range cmdArray {
array := strings.Fields(item)
// tls
tls := "false"
if len(array) > 2 {
tls = array[2]
}
// tls
if tls == "-tls_enable=true" || tls == "true" {
systemPro(flag, array[0], array[1], true)
} else {
systemPro(flag, array[0], array[1], false)
+104 -4
View File
@@ -51,6 +51,7 @@ func main() {
return
}
if *serverCmd {
_ = logs.SetLogger(logs.AdapterConsole, `{"level":7,"color":true}`)
printSlogan()
inputCmd()
return
@@ -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())
}
@@ -211,7 +215,7 @@ func printSlogan() {
fmt.Printf("%s", green(""))
fmt.Printf("\033[32;0m欢迎使用 NPS 管理脚本 \n")
fmt.Printf("\033[32;0m欢迎使用 NPS 管理脚本,当前版本:v%s\n", version.VERSION)
fmt.Printf("\033[0m") // 重置颜色
fmt.Printf("\n")
@@ -266,7 +270,15 @@ func inputCmd() {
_ = service.Control(s, "uninstall")
binPath := install.InstallNpsToCurrentDir()
beego.LoadAppConfig("ini", filepath.Join(common.GetAppPath(), "conf", "nps.conf"))
// Ensure conf exists (same as normal startup), then load it for display.
// Previously LoadAppConfig error was ignored and web_port could be empty,
// printing "127.0.0.1:" with no port. See #317.
confDir := filepath.Join(common.GetAppPath(), "conf")
initConfig(confDir)
if err := beego.LoadAppConfig("ini", filepath.Join(confDir, "nps.conf")); err != nil {
fmt.Println("加载配置文件失败:", err)
break
}
logPath := filepath.Join(common.GetAppPath(), "nps.log")
if common.IsWindows() {
@@ -299,7 +311,16 @@ func inputCmd() {
if err != nil {
fmt.Println("启动NPS服务失败", err)
} else {
fmt.Println("NPS服务已启动,管理面板访问地址:127.0.0.1:" + beego.AppConfig.String("web_port"))
webPort := beego.AppConfig.String("web_port")
if webPort == "" {
fmt.Println("NPS服务已启动(未配置 web_port,管理面板已关闭)")
} else {
scheme := "http"
if beego.AppConfig.DefaultBool("web_open_ssl", false) {
scheme = "https"
}
fmt.Println("NPS服务已启动,管理面板访问地址:" + scheme + "://127.0.0.1:" + webPort)
}
}
break
@@ -328,7 +349,7 @@ func inputCmd() {
break
case "3":
install.UpdateNpsNew()
return
break
case "4":
// 查看状态
var statusMsg = ""
@@ -444,3 +465,82 @@ 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)
}
}
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
`
+3 -10
View File
@@ -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
-27
View File
@@ -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-----
-22
View File
@@ -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-----
+3
View File
@@ -0,0 +1,3 @@
@echo off
cd /d D:\yisi\github\nps\docs
yarn docs:dev > vuepress-dev.log 2> vuepress-dev.err.log
+15
View File
@@ -0,0 +1,15 @@
import { defineClientConfig } from 'vuepress/client'
import { watch } from 'vue'
import { usePageData, useRoute } from 'vuepress/client'
export default defineClientConfig({
setup() {
const page = usePageData()
const route = useRoute()
// eslint-disable-next-line no-console
watch(() => route.path, () => {
// eslint-disable-next-line no-console
console.log('[debug] route:', route.path, 'headers:', JSON.stringify(page.value.headers))
}, { immediate: true })
},
})
+143
View File
@@ -0,0 +1,143 @@
import type { SidebarConfig } from 'vuepress'
import { defineUserConfig } from 'vuepress'
import { viteBundler } from '@vuepress/bundler-vite'
import { defaultTheme } from '@vuepress/theme-default'
import { prismjsPlugin } from '@vuepress/plugin-prismjs'
import { searchPlugin } from '@vuepress/plugin-search'
const serverSidebar: SidebarConfig = [
{ text: '服务端', children: [
{ text: '使用说明', link: '/server/nps_use.html' },
{ text: '配置文件', link: '/server/server_config.html' },
{ text: '增强功能', link: '/server/nps_extend.html' },
]},
]
const clientSidebar: SidebarConfig = [
{ text: '客户端', children: [
{ text: '使用说明', link: '/client/use.html' },
{ text: '增强功能', link: '/client/npc_extend.html' },
{ text: 'SDK', link: '/client/npc_sdk.html' },
]},
]
const extendSidebar: SidebarConfig = [
{ text: '扩展', children: [
{ text: '更多功能', link: '/extend/feature.html' },
{ text: '配置示例', link: '/extend/example.html' },
{ text: 'API接入方式', link: '/extend/api.html' },
{ text: 'API 清单', link: '/extend/webapi.html' },
]},
]
export default defineUserConfig({
base: '/nps/',
bundler: viteBundler(),
lang: 'zh-CN',
title: 'NPS',
description: 'NPS 内网穿透文档 — 服务端、客户端、Web API、增强功能、更新日志',
head: [
['link', { rel: 'icon', href: '/logo.svg' }],
['meta', { name: 'theme-color', content: '#4f46e5' }],
],
plugins: [
prismjsPlugin({
lineNumbers: true,
}),
searchPlugin({}),
],
theme: defaultTheme({
logo: '/logo.svg',
repo: 'yisier/nps',
repoLabel: 'GitHub',
docsRepo: 'https://github.com/yisier/nps',
docsBranch: 'master',
docsDir: 'docs',
editLink: true,
editLinkText: '在 GitHub 上编辑此页',
lastUpdated: true,
lastUpdatedText: '最后更新',
contributors: false,
navbar: [
{ text: '首页', link: '/' },
{ text: '快速上手', link: '/install/' },
{
text: '服务端',
children: [
{ text: '使用说明', link: '/server/nps_use.html' },
{ text: '配置文件', link: '/server/server_config.html' },
{ text: '增强功能', link: '/server/nps_extend.html' },
],
},
{
text: '客户端',
children: [
{ text: '使用说明', link: '/client/use.html' },
{ text: '增强功能', link: '/client/npc_extend.html' },
{ text: 'SDK', link: '/client/npc_sdk.html' },
],
},
{
text: '扩展',
children: [
{ text: '更多功能', link: '/extend/feature.html' },
{ text: '配置示例', link: '/extend/example.html' },
{ text: 'API接入方式', link: '/extend/api.html' },
{ text: 'API 清单', link: '/extend/webapi.html' },
],
},
{ text: '更新日志', link: '/changelog/' },
],
sidebar: {
'/install/': [
{ text: '快速上手', link: '/install/' },
],
'/server/introduction.html': serverSidebar,
'/server/nps_use.html': serverSidebar,
'/server/server_config.html': serverSidebar,
'/server/nps_extend.html': serverSidebar,
'/client/use.html': clientSidebar,
'/client/npc_extend.html': clientSidebar,
'/client/npc_sdk.html': clientSidebar,
'/extend/feature.html': extendSidebar,
'/extend/example.html': extendSidebar,
'/extend/api.html': extendSidebar,
'/extend/webapi.html': extendSidebar,
'/': [
{ text: '首页', link: '/' },
{ text: '快速上手', link: '/install/' },
{
text: '服务端',
children: [
{ text: '使用说明', link: '/server/nps_use.html' },
{ text: '配置文件', link: '/server/server_config.html' },
{ text: '增强功能', link: '/server/nps_extend.html' },
],
},
{
text: '客户端',
children: [
{ text: '使用说明', link: '/client/use.html' },
{ text: '增强功能', link: '/client/npc_extend.html' },
{ text: 'SDK', link: '/client/npc_sdk.html' },
],
},
{
text: '扩展',
children: [
{ text: '功能', link: '/extend/feature.html' },
{ text: '配置示例', link: '/extend/example.html' },
{ text: 'API接入方式', link: '/extend/api.html' },
{ text: 'Web API 详细', link: '/extend/webapi.html' },
],
},
{ text: '更新日志', link: '/changelog/' },
],
},
sidebarDepth: 2,
}),
})

Before

Width:  |  Height:  |  Size: 156 KiB

After

Width:  |  Height:  |  Size: 156 KiB

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Before

Width:  |  Height:  |  Size: 72 KiB

After

Width:  |  Height:  |  Size: 72 KiB

Before

Width:  |  Height:  |  Size: 119 KiB

After

Width:  |  Height:  |  Size: 119 KiB

Before

Width:  |  Height:  |  Size: 276 KiB

After

Width:  |  Height:  |  Size: 276 KiB

Before

Width:  |  Height:  |  Size: 276 KiB

After

Width:  |  Height:  |  Size: 276 KiB

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 26 KiB

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 34 KiB

Before

Width:  |  Height:  |  Size: 110 KiB

After

Width:  |  Height:  |  Size: 110 KiB

Before

Width:  |  Height:  |  Size: 95 KiB

After

Width:  |  Height:  |  Size: 95 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 186 KiB

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 32 KiB

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 34 KiB

Before

Width:  |  Height:  |  Size: 42 KiB

After

Width:  |  Height:  |  Size: 42 KiB

Before

Width:  |  Height:  |  Size: 166 KiB

After

Width:  |  Height:  |  Size: 166 KiB

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Before

Width:  |  Height:  |  Size: 61 KiB

After

Width:  |  Height:  |  Size: 61 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 73 KiB

Before

Width:  |  Height:  |  Size: 712 KiB

After

Width:  |  Height:  |  Size: 712 KiB

Before

Width:  |  Height:  |  Size: 97 KiB

After

Width:  |  Height:  |  Size: 97 KiB

Before

Width:  |  Height:  |  Size: 690 KiB

After

Width:  |  Height:  |  Size: 690 KiB

Before

Width:  |  Height:  |  Size: 49 KiB

After

Width:  |  Height:  |  Size: 49 KiB

Before

Width:  |  Height:  |  Size: 76 KiB

After

Width:  |  Height:  |  Size: 76 KiB

Before

Width:  |  Height:  |  Size: 290 KiB

After

Width:  |  Height:  |  Size: 290 KiB

Before

Width:  |  Height:  |  Size: 232 KiB

After

Width:  |  Height:  |  Size: 232 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 95 KiB

Before

Width:  |  Height:  |  Size: 58 KiB

After

Width:  |  Height:  |  Size: 58 KiB

Before

Width:  |  Height:  |  Size: 3.3 KiB

After

Width:  |  Height:  |  Size: 3.3 KiB

+30 -19
View File
@@ -1,21 +1,32 @@
# nps
![](https://img.shields.io/github/stars/cnlh/nps.svg) ![](https://img.shields.io/github/forks/cnlh/nps.svg)
[![Gitter](https://badges.gitter.im/cnlh-nps/community.svg)](https://gitter.im/cnlh-nps/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
[![Build Status](https://travis-ci.org/ehang-io/nps.svg?branch=master)](https://travis-ci.org/cnlh/nps)
---
home: true
title: NPS 内网穿透
heroImage: /logo.svg
heroText: NPS
tagline: 一款轻量级、高性能、功能强大的内网穿透代理服务器
actions:
- text: 快速上手 →
link: /install/
type: primary
- text: 简介
link: /server/nps_use.html
type: secondary
features:
- title: 全协议支持
details: TCP、UDP、HTTP、HTTPS、SOCKS5、P2P 全覆盖,几乎所有场景一次满足
- title: Web 管理界面
details: 简洁但功能强大的服务端面板,无需配置文件,开箱即用
- title: 全平台兼容
details: Linux / macOS / Windows / Android,一键注册系统服务,桌面 GUI 客户端
- title: TLS 桥接加密
details: 防止流量被防火墙识别拦截,与 KCP / 普通 TCP 三种连接方式自由切换
- title: 进阶能力
details: 流量统计、限速、IP 黑白名单、Proxy Protocol、负载均衡、健康检查
- title: 强大的 API
details: 完整的 REST API,支持 MD5 签名鉴权,方便自动化运维与二次开发
footer: GPL-3.0 License · 基于 ehang-io/nps 0.26.10 二次开发
---
nps是一款轻量级、高性能、功能强大的**内网穿透**代理服务器。目前支持**tcp、udp流量转发**,可支持任何**tcp、udp**上层协议(访问内网网站、本地支付接口调试、ssh访问、远程桌面,内网dns解析等等……),此外还**支持内网http代理、内网socks5代理**、**p2p等**,并带有功能强大的web管理端。
## 加入交流
## 背景
![image](https://github.com/ehang-io/nps/blob/master/image/web.png?raw=true)
1. 做微信公众号开发、小程序开发等----> 域名代理模式
2. 想在外网通过ssh连接内网的机器,做云服务器到内网服务器端口的映射,----> tcp代理模式
3. 在非内网环境下使用内网dns,或者需要通过udp访问内网机器等----> udp代理模式
4. 在外网使用HTTP代理访问内网站点----> http代理模式
5. 搭建一个内网穿透ss,在外网如同使用内网vpn一样访问内网资源或者设备----> socks5代理模式
聊天灌水 QQ 群:**619833483**,热心群主可提供免费远程协助。
-16
View File
@@ -1,16 +0,0 @@
![logo](logo.svg)
# NPS <small>0.26.10</small>
> 一款轻量级、高性能、功能强大的内网穿透代理服务器
- 几乎支持所有协议
- 支持内网http代理、内网socks5代理、p2p等
- 简洁但功能强大的WEB管理界面
- 支持服务端、客户端同时控制
- 扩展功能强大
- 全平台兼容,一键注册为服务
[GitHub](https://github.com/ehang-io/nps/)
[开始使用](#nps)
-3
View File
@@ -1,3 +0,0 @@
* [![GitHub stars](https://img.shields.io/github/stars/ehang-io/nps?style=social)](https://github.com/ehang-io/nps/stargazers)
* [![GitHub forks](https://img.shields.io/github/forks/ehang-io/nps?style=social)](https://github.com/ehang-io/nps/network)
-29
View File
@@ -1,29 +0,0 @@
* 入门
* [安装](install.md)
* [启动](run.md)
* [使用示例](example.md)
* 服务端
* [介绍](introduction.md)
* [使用](nps_use.md)
* [配置文件](server_config.md)
* [增强功能](nps_extend.md)
* 客户端
* [基本使用](use.md)
* [增强功能](npc_extend.md)
* 扩展
* [功能](feature.md)
* [说明](description.md)
* [web api](api.md)
* [sdk](npc_sdk.md)
* 其他
* [FAQ](faq.md)
* [贡献](contribute.md)
* [捐助](donate.md)
* [致谢](thanks.md)
* [交流](discuss.md)
-45
View File
@@ -1,45 +0,0 @@
# web api
需要开启请先去掉`nps.conf`中`auth_key`的注释并配置一个合适的密钥
## webAPI验证说明
- 采用auth_key的验证方式
- 在提交的每个请求后面附带两个参数,`auth_key` 和`timestamp`
```
auth_key的生成方式为:md5(配置文件中的auth_key+当前时间戳)
```
```
timestamp为当前时间戳
```
```
curl --request POST \
--url http://127.0.0.1:8080/client/list \
--data 'auth_key=2a0000d9229e7dbcf79dd0f5e04bb084&timestamp=1553045344&start=0&limit=10'
```
**注意:** 为保证安全,时间戳的有效范围为20秒内,所以每次提交请求必须重新生成。
## 获取服务端时间
由于服务端与api请求的客户端时间差异不能太大,所以提供了一个可以获取服务端时间的接口
```
POST /auth/gettime
```
## 获取服务端authKey
如果想获取authKey,服务端提供获取authKey的接口
```
POST /auth/getauthkey
```
将返回加密后的authKey,采用aes cbc加密,请使用与服务端配置文件中cryptKey相同的密钥进行解密
**注意:** nps配置文件中`auth_crypt_key`需为16位
- 解密密钥长度128
- 偏移量与密钥相同
- 补码方式pkcs5padding
- 解密串编码方式 十六进制
## 详细文档
- **[详见](webapi.md)** (感谢@avengexyz)
+2
View File
@@ -0,0 +1,2 @@
cd ..
yarn add -D vuepress
+2
View File
@@ -0,0 +1,2 @@
cd ..
yarn docs:dev
-42
View File
@@ -1,42 +0,0 @@
# 🐳 宝塔面板 (一键部署)
> 安装宝塔面板,前往宝塔面板官网,选择对应的脚本下载安装,推荐宝塔版本 9.2.0+
![logo](../image/bt/bt1.jpg)
# 安装宝塔面板
1. 安装宝塔面板,前往 [宝塔面板官网](https://www.bt.cn/new/download.html) 进行安装,选择正式版脚本安装。
2. 登录面板,点击左侧 **Docker** 进入 `Docker 管理`。
3. 如提示未安装 Docker / Docker Compose, 可根据上方引导安装。
# 安装NPS服务端
1. 在宝塔面板左侧` Docker 菜单`,进入 **应用商城**,搜索 `NPS`,找到 `NPS 服务端` 并点击 **安装**。
2. 配置NPS,进入安装目录,修改 `conf/nps.conf` 即可(修改后记得重启容器),服务端参数配置详见 [配置文件说明](https://ehang-io.github.io/nps/#/server_config)
![logo](../image/bt/bt2.png)
**注意**:NPS 默认的`WEB端口`为`80,443`, 如果端口被占用,请修改 `nps.conf` 中的 `http_proxy_port`,`https_proxy_port` 为其他端口。
web管理端口默认为`8081`,服务端启动后,输入:`ip:8081` 即可访问。
# 安装NPS客户端
1. 在宝塔面板左侧` Docker 菜单`,进入 **应用商城**,搜索 `NPS`,找到 `NPS 客户端` 并点击 **安装**。
2. 客户端配置有两种方式,1. [无配置文件模式](https://ehang-io.github.io/nps/#/use?id=%e6%97%a0%e9%85%8d%e7%bd%ae%e6%96%87%e4%bb%b6%e6%a8%a1%e5%bc%8f)(推荐),2. [配置文件模式](https://ehang-io.github.io/nps/#/use?id=%e9%85%8d%e7%bd%ae%e6%96%87%e4%bb%b6%e6%a8%a1%e5%bc%8f)。
- **无配置文件模式**:点击安装后,输入`服务地址`、`连接密钥`,即可启动客户端。`连接方式`和`开启TLS`参数,为了避免意外错误,不建议修改。如果需要配置多个客户端,直接安装多个即可(注意名字不要重复)。
- **配置文件模式**: `服务地址`、`连接密钥`不需要填写,直接点击 **安装** ,然后在`安装目录`下找到 `conf/npc.conf`,修改配置文件,再重启容器即可。客户端参数配置详见 [配置文件说明](https://ehang-io.github.io/nps/#/use?id=%e9%85%8d%e7%bd%ae%e6%96%87%e4%bb%b6%e6%a8%a1%e5%bc%8f)。
**注意**:强烈推荐使用无配置文件模式,所有数据应该在服务端保存和配置,而客户端只做连接转发。客户端配置文件对小白极不友好,配置繁琐,容易出错。
![logo](../image/bt/bt3.png)
+231
View File
@@ -0,0 +1,231 @@
# 更新日志
- 2026-07-12 v0.26.36
- 新增:
- 新增客户端内网地址上报功能,客户端列表展示 npc 内网地址 [#333](https://github.com/yisier/nps/issues/333)
- Web 管理端客户端/隧道/域名列表业务字段支持服务端排序(备注、状态、在线等)[#254](https://github.com/yisier/nps/issues/254)
- 优化:
- 不再依赖外部 `web` 目录的静态文件
- 修复:
- 客户端/服务端在线更新失败 BUG
- `nps -server` 安装成功后 `web_port` 未正常显示BUG [#317](https://github.com/yisier/nps/issues/317)
- Bridge 握手增加 10s 读超时,校验失败/读失败立即关闭连接,减轻端口扫描导致的连接与 goroutine 堆积 [#281](https://github.com/yisier/nps/issues/281)
- 解决私密代理和P2P连接的TLS启用问题 [#143](https://github.com/yisier/nps/issues/143)
- HTTP 正向代理 Basic 认证 BUG[#133](https://github.com/yisier/nps/issues/133)
- SOCKS5 用户名密码认证 BUG [#133](https://github.com/yisier/nps/issues/133)
- 客户端建连失败后半连接假死、需手动重启 npc BUG [#115](https://github.com/yisier/nps/issues/115)
- 2026-07-04 v0.26.35
- 新增:
- 客户端列表、隧道列表、域名解析列表支持多选批量删除 [#287](https://github.com/yisier/nps/issues/287)
- 修复:
- HTTP 代理在 SVN 客户端无法正常检出 [#336](https://github.com/yisier/nps/issues/336)
- 新增/编辑隧道时无提示且不跳转,重复点击会产生多条记录 [#334](https://github.com/yisier/nps/issues/334)
- mips/mipsle 架构运行出现 Illegal instruction 错误 [#331](https://github.com/yisier/nps/issues/331)
- 优化:
- 隧道、域名解析编辑页的客户端 ID 改为下拉选择 [#334](https://github.com/yisier/nps/issues/334)
- 2026-06-04 v0.26.34
- 新增:
- `nps -server` 管理脚本欢迎语显示当前版本号,更新版本时比对版本,已是最新则直接退出,避免无谓覆盖 [#328](https://github.com/yisier/nps/issues/328)
- `npc` 管理脚本欢迎语显示当前版本号,新增 `[5] 更新客户端` 选项,更新并替换 npc 二进制
- 客户端新增到期时间字段,创建/修改客户端时可选填写,到期后自动暂停客户端 [#322](https://github.com/yisier/nps/issues/322)
- 修复:
- Dashboard IO 速率采集阻塞请求 500ms,改为后台采集缓存,消除 Sleep 等待
- ServerStatus 切片并发读写不安全,添加 RWMutex 保护
- flowSession goroutine 泄漏,改为仅在 StartNewServer 启动一次
- GetTunnel 双重遍历 sync.Map 性能问题,合并为单次 Range
- Bridge Client 字段并发读写不安全,添加 Mutex 保护
- TLS ClientHello recordLen 无上限,添加 16KB 限制防止内存耗尽
- SOCKS5 地址解析未检查 Read 返回值,改用 io.ReadFull
- 文件存储 panic 改为错误日志,defer 清理临时文件防止泄漏
- GenerateServerPort 可能无限循环,限制 1000 次重试
- P2P UDP 无超时永久阻塞,添加 30s ReadDeadline
- P2P goroutine 退出控制改用 context,修复潜在泄漏
- 客户端 UDP ReadFrom 错误后未退出,修复无效数据继续处理
- [#324](https://github.com/yisier/nps/issues/324) 隧道/域名解析/UDP 流量始终为 0
- muxPackager buffer pool 泄漏:UnPack() 错误路径未归还 windowBuff 导致内存持续增长
- bridge 客户端重连时旧 WORK_CHAN/WORK_FILE mux 未关闭,底层连接和 goroutine 永不释放
- pmux 连接超时泄漏:process() channel 发送超时后连接未关闭,且 ACCEPT_TIME_OUT 单位错误(10ns 应为 10s)
- pmux 关闭流程 panic:加 done channel + WaitGroup 保证 Close() 等所有 process() 退出后再 close conn channel;process() 入口设 ReadDeadline 防止阻塞读导致 wg.Wait() 死锁;PortListener 加 done channel 唤醒 Accept()
- 优化:ioutil.WriteFile → os.WriteFile、rand.Seed → rand.New 本地随机源
- 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)
- 修复https反向代理bug,感谢[okawao](https://github.com/okawao) 的 PR
- 2026-03-23 v0.26.31
- 新增:
- 域名解析记录开关功能 [#314](https://github.com/yisier/nps/issues/314)
- TCP隧道增加Basic认证 [306](https://github.com/yisier/nps/issues/306)
- 修复:
- 新增隧道出现secret mode keys must be unique [301](https://github.com/yisier/nps/issues/301)
- 2026-03-12 v0.26.30
- 修复:
- http 协议 websocket 错误,感谢[xiaozonglong](https://github.com/xiaozonglong) 提供的 home assistant 环境 ,[#268](https://github.com/yisier/nps/issues/268),[#296](https://github.com/yisier/nps/issues/296)
- 域名解析中,主机url点击无法跳转非80端口 [311](https://github.com/yisier/nps/issues/311)
- 新增的主机配置页面,客户端ID异常 [#310](https://github.com/yisier/nps/issues/310)
- 自动 HTTPS(301) 按照 `https_proxy_port` 配置的端口号跳转
- 2026-01-24 v0.26.29
- 新增:
- GUI 客户端,基于 Wails 开发,[点击查看了解更多](https://github.com/yisier/nps/blob/master/cmd/npc/npc-gui/README.md),需要 WebView2 运行时,可通过两种方式添加客户端。
- 方式1:直接输入快捷启动命令即可
- 方式2:手动添加客户端,输入-server -vkey等参数
![img.png](/image/new/gui.png)
- 修复:
- Android 包未构建到 Release [72](https://github.com/yisier/nps/issues/72)
- 2025-12-06 v0.26.28
- 【全局参数】页面新增`服务地址`配置项,用于客户端命令地址显示、隧道访问地址显示 [293](https://github.com/yisier/nps/issues/293)
- 【IP授权功能优化】,通过穿透的端口去提交 IP 认证,感谢 [Aqamoe](https://github.com/Aqamoe) 的建议 [291](https://github.com/yisier/nps/issues/291)
- 【重构限速器实现】提升性能和准确性
- 2025-11-05 v0.26.27
- 新增:
- 客户端新增【IP白名单】,可通过两种方式添加IP:
- 方式1️⃣:在【客户端】新建/修改页面,配置IP授权密码,不在IP白名单的外网访问将被跳转到 IP 授权页面,输入正确的授权密码,即可完成添加 IP。
- 方式2️⃣:在【客户端】新建/修改页面,直接添加IP到白名单中。
![img.png](/image/new/ip.png)
- 客户端配置移除【压缩】和【加密】功能,此功能会显著提高内存和CPU占用率,"利大于弊"。
- 客户端默认不再提供配置文件,***强烈推荐使用无配置文件模式启动客户端***
- 2025-08-15 v0.26.26
- 修复:
- windows注册服务 使用tls无法连接 [269](https://github.com/yisier/nps/issues/269)
- 域名解析自动HTTPS逻辑bug [273](https://github.com/yisier/nps/issues/273)
- 2025-05-28 v0.26.25
- 新增:
- nps增加`nps(.exe) -server` 命令,用于管理NPS服务,安装和卸载服务在 Linux 下需要有 sudo 权限,Windows 下需要有管理员权限。
![img.png](/image/new/server.png)
- 增加【TLS快捷启动命令】,可用于在tls模式下,快速启动客户端。 [257](https://github.com/yisier/nps/issues/257)
- 2025-04-16 v0.26.24
- 新增:
- 隧道支持复制功能,在隧道页面增加复制按钮,除了端口号为随机生成外,其他参数全部拷贝。[251](https://github.com/yisier/nps/issues/251)
- 修复:
- 私密代理连接时服务端会报错退出,[250](https://github.com/yisier/nps/issues/250)
- 2025-04-11 v0.26.23
- 新增:
- TCP 隧道支持 Proxy Protocol 协议来传递经过请求的真实 IP。
![img.png](/image/new/protocol.png)
- 修复:
- 客户端较多时,协程增长过快,感谢 [@huanglei288766](https://github.com/yisier/nps/pull/244) 的PR
- 2025-01-23 v0.26.22
- 优化:
- 客户端注册系统服务时,(新版客户端注册方式,非 install 命令) 将按照 `npc-[vkey].log` 格式保存日志,每个客户端VKEY单独一个日志文件,windows 日志位于 `npc.exe` 同级目录下,linux 位于 `/var/log/`目录。
- 域名模式,HTTPS证书支持上传文件和文件路径,系统将自动识别路径还是证书内容。 [#175](https://github.com/yisier/nps/issues/175)
- 修复:
- ipv6地址显示不全 [#237](https://github.com/yisier/nps/issues/237)
- 2025-01-07 v0.26.21
- 新增:
- 客户端列表页面新增【快捷启动命令】,此命令为连接地址+链接秘钥的base64编码,方便一键启动、一键安装客户端。
- 域名解析和隧道列表增加访问地址,可以点击隧道链接,直接网页打开。 [#234](https://github.com/yisier/nps/issues/234)
- 优化:
- 修改vkey生成方式,由16位缩短至10位,截取uuid前10位,避免重复。
- 优化客户端启动方式,当npc文件目录下无配置文件时,可直接双击运行客户端,输入命令完成启动、安装、卸载客户端,直接启动和安装服务时需要输入【快捷启动命令】,卸载服务、启动服务、停止服务时,只需输入隧道秘钥【vkey】即可。安装服务以 nps-client-vkey 方式命名 ,实现注册多个服务。
![image](/image/new/cmd.png)
> **注意**:强烈推荐使用无配置文件模式启动客户端,所有数据应该在服务端保存和配置,而客户端只做连接转发。客户端配置文件对小白极不友好,配置繁琐,容易出错。
- 2024-11-07 v0.26.20
- 新增:
- 客户端增加创建时间
- 修复:
- 客户端限速单位不统一 [#185](https://github.com/yisier/nps/issues/185)
- 增加从下拉选择客户端,隧道列表排序,新增编辑后不会刷新界面 [#183](https://github.com/yisier/nps/issues/183)
- 隧道数量限制无法统计域名映射 [#209](https://github.com/yisier/nps/issues/209)
- 2024-06-01 v0.26.19
- golang 版本升级到 1.22。
- 增加自动https,自动将http 重定向(301)到 https。
- 客户端命令行方式启动支持多个隧道ID,使用逗号拼接,示例:`npc -server=xxx:8024 -vkey=ytkpyr0er676m0r7,iwnbjfbvygvzyzzt`。
- 移除 nps.conf 参数 `https_just_proxy` ,调整 https 处理逻辑,如果上传了 https 证书,则由nps负责SSL(此方式可以获取真实IP),否则走端口转发模式(使用本地证书,nps 获取不到真实IP),如下图所示。
![image](/image/new/https.png)
- 2024-02-27 v0.26.18
- ***新增***:nps.conf 新增 `tls_bridge_port=8025` 参数,当 `tls_enable=true` 时,nps 会监听8025端口,作为 tls 的连接端口。客户端可以选择连接 tls 端口或者非 tls 端口:`npc.exe -server=xxx:8024 -vkey=xxx` 或 `npc.exe -server=xxx:8025 -vkey=xxx -tls_enable=true`
- 2024-01-31 v0.26.17
- ***说明***:考虑到 npc 历史版本客户端众多,版本号不同旧版本客户端无法连接,为了兼容,仓库版本号将继续沿用 0.26.xx
- 2024-01-02 v0.27.01 (已作废,功能移动到 v0.26.17 版本)
- ***新增***:tls 流量加密,(客户端忽略证书校验,谨慎使用,客户端与服务端需要同时开启,或同时关闭),使用方式:
- 服务端:nps.conf `tls_enable=true`;
- 客户端:npc.conf `tls_enable=true` 或者 `npc.exe -server=xxx -vkey=xxx -tls_enable=true`
- 2023-06-01 v0.26.16
- ***修复***:https 流量不统计 Bug 修复。
- ***新增***:新增全局黑名单IP,用于防止被肉鸡扫描端口或被恶意攻击。
- ***新增***:新增客户端上次在线时间。
- 2023-02-24 v0.26.15
- ***修复***:更新程序 url 更改到当前仓库中
- ***修复***:nps 在外部路径启动时找不到配置文件
- ***新增***:增加 nps 启动参数,`-conf_path=D:\test\nps`,可用于加载指定nps配置文件和web文件目录。
- ***window 使用示例:***
- 直接启动:`nps.exe -conf_path=D:\test\nps`
- 安装:`nps.exe install -conf_path=D:\test\nps`
- 安装启动:`nps.exe start`
- ***linux 使用示例:***
- 直接启动:`./nps -conf_path=/app/nps`
- 安装:`./nps install -conf_path=/app/nps`
- 安装启动:`nps start -conf_path=/app/nps`
- 2022-12-30 v0.26.14
- ***修复***:API 鉴权漏洞修复
- 2022-12-19
- ***修复***:某些场景下丢包导致服务端意外退出
- ***优化***:新增隧道时,不指定服务端口时,将自动生成端口号
- ***优化***:API返回ID,`/client/add/`, `/index/addhost/`, `/index/add/`
- ***优化***:域名解析、隧道页面,增加[唯一验证密钥],方便搜查
- 2022-10-30
- ***新增***:在管理面板中新增客户端时,可以配置多个黑名单IP,用于防止被肉鸡扫描端口或被恶意攻击。
- ***优化***:0.26.12 版本还原了注册系统功能,使用方式和以前一样。无论是否注册了系统服务,直接执行 nps 时只会读取当前目录下的配置文件。
- 2022-10-27
- ***新增***:在管理面板登录时开启验证码校验,开启方式:nps.conf `open_captcha=true`,感谢 [@dongFangTuring](https://github.com/dongFangTuring) 提供的PR
- 2022-10-24
- ***修复***:HTTP协议支持WebSocket(稳定性待测试)
- 2022-10-21
- ***修复***:HTTP协议下实时统计流量,能够精准的限制住流量(上下行对等)
- ***优化***:删除HTTP隧道时,客户端已用流量不再清空
- 2022-10-19
- ***BUG***:在TCP协议下,流量统计有问题,只有当连接断开时才会统计流量。例如,限制客户端流量20m,当传输100m的文件时,也能传输成功。
- ***修复***:TCP协议下实时统计流量,能够精准的限制住流量(上下行对等)
- ***优化***:删除TCP隧道时,客户端已用流量不再清空
![image](/image/new/tcp_limit.png)
- 2022-09-14
- 修改NPS工作目录为当前可执行文件目录(即配置文件和nps可执行文件放在同一目录下,直接执行nps文件即可),去除注册系统服务,启动、停止、升级等命令
@@ -8,21 +8,11 @@
```
./npc status -config=npc配置文件路径
```
## 重载配置文件
```
./npc restart -config=npc配置文件路径
```
## 通过代理连接nps
有时候运行npc的内网机器无法直接访问外网,此时可以可以通过socks5代理连接nps
对于配置文件方式启动,设置
```ini
[common]
proxy_url=socks5://111:222@127.0.0.1:8024
```
对于无配置文件模式,加上参数
```
-proxy=socks5://111:222@127.0.0.1:8024
```
@@ -33,4 +23,5 @@ proxy_url=socks5://111:222@127.0.0.1:8024
或http://username:password@ip:port
## 群晖支持
可在releases中下载spk群晖套件,例如`npc_x64-6.1_0.19.0-1.spk`
添加 `我不是矿神` 套件地址 : https://spk7.imnks.com/,下载npc套件安装后,按照提示输入服务地址和连接密钥即可。
+72
View File
@@ -0,0 +1,72 @@
## 直接运行
直接双击 `npc`/`npc.exe`,无任何参数,按提示输入即可:
| 菜单项 | 输入内容 |
| --- | --- |
| 注册系统服务 | 【快捷启动命令】或【TLS 快捷启动命令】|
| 卸载系统服务 | 隧道密钥 `vkey` |
| 启动 | 隧道密钥 `vkey` |
| 停止 | 隧道密钥 `vkey` |
| 更新客户端 | — |
【快捷启动命令】在 web 后台 → 客户端列表 → 客户端前的小图标里复制,本质是 `服务端地址 + vkey` 的 base64 编码。TLS 模式有独立的【TLS 快捷启动命令】。
服务以 `nps-client-<vkey>` 命名注册,可在同一台机器并存多个客户端实例。
![image](/image/new/cmd.png)
## 直接命令行
```shell
./npc -server=ip:port -vkey=web界面中显示的密钥 # 标准
./npc -server=ip:8025 -vkey=xxx -tls_enable=true # TLS 桥接
./npc -server=ip:8024 -vkey=ytkpyr0er676m0r7,iwnbjfbvygvzyzzt # 同时拉起多个隧道 ID(逗号拼接)
```
## GUI 客户端
> 基于 Wails 开发的桌面 GUI,体积只有 5M,免安装,解压即用。
支持两种添加客户端方式:
1. 粘贴 web 后台的【快捷启动命令】
2. 手动填写 `-server`、`-vkey` 等参数
详细说明请参考 [GUI 客户端 README](https://github.com/yisier/nps/blob/master/cmd/npc/npc-gui/README.md)。
![img](/image/new/gui.png)
## 注册到系统服务
> 实现开机启动、守护进程
```shell
./npc # linux/darwin(需 sudo)
npc.exe # windows(管理员 cmd)
```
按菜单选「注册系统服务」并粘贴【快捷启动命令】或【TLS 快捷启动命令】即可,服务名为 `nps-client-<vkey>`。
> Windows 如果需要当客户端退出时自动重启客户端,请按照如图所示配置
![img](/image/windows_client_service_configuration.png)
## 系统服务日志
注册系统服务后日志按 **每个 vkey 一个文件** 保存,命名为 `npc-<vkey>.log`:
- windows:与 `npc.exe` 同级目录
- linux / darwin:`/var/log/`
## 客户端更新
> 运行客户端,会显示当前客户端版本号。
```shell
./npc # 选择菜单 [5] 更新客户端
```
自动下载并替换 `npc` 二进制。
如果无法成功更新,可以直接下载 releases 压缩包覆盖原有的 `npc` 二进制。
-6
View File
@@ -1,6 +0,0 @@
# 贡献
- 如果遇到bug可以直接提交至dev分支
- 使用遇到问题可以通过issues反馈
- 项目处于开发阶段,还有很多待完善的地方,如果可以贡献代码,请提交 PR 至 dev 分支
- 如果有新的功能特性反馈,可以通过issues或者qq群反馈
-30
View File
@@ -1,30 +0,0 @@
# 说明
## 获取用户真实ip
如需使用需要在`nps.conf`中设置`http_add_origin_header=true`
在域名代理模式中,可以通过request请求 header 中的 X-Forwarded-For 和 X-Real-IP 来获取用户真实 IP。
**本代理前会在每一个http(s)请求中添加了这两个 header。**
## 热更新支持
对于绝大多数配置,在web管理中的修改将实时使用,无需重启客户端或者服务端
## 客户端地址显示
在web管理中将显示客户端的连接地址
## 流量统计
可统计显示每个代理使用的流量,由于压缩和加密等原因,会和实际环境中的略有差异
## 当前客户端带宽
可统计每个客户端当前的带宽,可能和实际有一定差异,仅供参考。
## 客户端与服务端版本对比
为了程序正常运行,客户端与服务端的核心版本必须一致,否则将导致客户端无法成功连接致服务端。
## Linux系统限制
默认情况下linux对连接数量有限制,对于性能好的机器完全可以调整内核参数以处理更多的连接。
`tcp_max_syn_backlog` `somaxconn`
酌情调整参数,增强网络性能
## web管理保护
当一个ip连续登陆失败次数超过10次,将在一分钟内禁止该ip再次尝试。
-3
View File
@@ -1,3 +0,0 @@
# 交流群
![二维码.jpeg](https://i.loli.net/2019/02/15/5c66c32a42074.jpeg)
-7
View File
@@ -1,7 +0,0 @@
# 捐助
如果您觉得nps对你有帮助,欢迎给予我们一定捐助,也是帮助nps更好的发展。
## 支付宝
![image](https://github.com/ehang-io/nps/blob/master/image/donation_zfb.png?raw=true)
## 微信
![image](https://github.com/ehang-io/nps/blob/master/image/donation_wx.png?raw=true)
+115
View File
@@ -0,0 +1,115 @@
# Web API 鉴权
在 `nps.conf` 中配置 `auth_key` 即可启用 API 鉴权(首次启动自动生成)。
## 鉴权方式
每个请求需附带两个参数:
| 参数 | 说明 |
| --- | --- |
| `auth_key` | `md5(配置文件中的 auth_key + 当前时间戳)` |
| `timestamp` | 当前 unix 时间戳(秒) |
时间戳有效范围为 **20 秒**,每次请求须重新生成。
## 获取服务端时间戳
由于客户端与服务端时间可能不一致,可先获取服务端时间:
```
GET /auth/gettime/
```
返回:
```json
{"time": 1717654321}
```
> 此接口无需鉴权。
## 获取服务端 auth_key(加密)
```
GET /auth/getauthkey/
```
返回经 AES-CBC 加密后的 `auth_key`(hex 编码)。
> 此接口无需鉴权。需确保 `nps.conf` 中 `auth_crypt_key` 为 **16 位**。
解密参数:
- 算法:AES-128-CBC
- 密钥:`auth_crypt_key`(16 字节)
- IV:与密钥相同
- 填充:PKCS5Padding
- 密文编码:hex
---
## 接入示例
::: tabs
@tab curl
```bash
# 1. 获取服务端时间戳
ts=$(curl -s http://127.0.0.1:8080/auth/gettime/ | sed 's/.*"time":\([0-9]*\).*/\1/')
# 2. 计算签名(Linux)
sign=$(echo -n "your_auth_key${ts}" | md5sum | awk '{print $1}')
# 或 macOS:
# sign=$(echo -n "your_auth_key${ts}" | md5)
# 3. 调用接口
curl -s -X POST "http://127.0.0.1:8080/client/list/" \
-d "auth_key=${sign}&timestamp=${ts}&search=&order=asc&offset=0&limit=10"
```
@tab Python
```python
import hashlib, requests
host = "http://127.0.0.1:8080"
auth_key = "your_auth_key"
ts = requests.get(f"{host}/auth/gettime/").json()["time"]
sign = hashlib.md5(f"{auth_key}{ts}".encode()).hexdigest()
r = requests.post(f"{host}/client/list/", data={
"auth_key": sign, "timestamp": ts,
"search": "", "order": "asc", "offset": 0, "limit": 10
})
print(r.json())
```
@tab JavaScript
```javascript
const crypto = require("crypto");
const host = "http://127.0.0.1:8080";
const authKey = "your_auth_key";
(async () => {
const ts = (await (await fetch(`${host}/auth/gettime/`)).json()).time;
const sign = crypto.createHash("md5").update(`${authKey}${ts}`).digest("hex");
const r = await fetch(`${host}/client/list/`, {
method: "POST",
headers: { "Content-Type": "application/x-www-form-urlencoded" },
body: new URLSearchParams({ auth_key: sign, timestamp: ts, search: "", order: "asc", offset: 0, limit: 10 }).toString(),
});
console.log(await r.json());
})();
```
:::
---
## 详细接口清单
- [Web API 接口文档](webapi.html)
+3 -3
View File
@@ -1,5 +1,5 @@
# 使用示例
## 统一准备工作(必做)
## 统一准备工作
- 开启服务端,假设公网服务器ip为1.1.1.1,配置文件中`bridge_port`为8024,配置文件中`web_port`为8080
- 访问1.1.1.1:8080
- 在客户端管理中创建一个客户端,记录下验证密钥
@@ -27,7 +27,7 @@
现在访问(http|https://)`a.proxy.com`,`b.proxy.com`即可成功
**https:** 如需使用https请进行相关配置,详见 [使用https](/nps_extend?id=使用https)
**https:** 如需使用https请进行相关配置,详见 [使用https](/server/nps_extend.html#使用-https)
## tcp隧道
@@ -104,7 +104,7 @@
## p2p服务
**适用范围:** 大流量传输场景,流量不经过公网服务器,但是由于p2p穿透和nat类型关系较大,不保证100%成功,支持大部分nat类型。[nat类型检测](/npc_extend?id=nat类型检测)
**适用范围:** 大流量传输场景,流量不经过公网服务器,但是由于p2p穿透和nat类型关系较大,不保证100%成功,支持大部分nat类型。[nat类型检测](/client/npc_extend.html#nat类型检测)
**假设场景:**
+50 -118
View File
@@ -1,23 +1,47 @@
# 扩展功能
## 获取用户真实ip
如需使用需要在`nps.conf`中设置`http_add_origin_header=true`
在域名代理模式中,可以通过request请求 header 中的 X-Forwarded-For 和 X-Real-IP 来获取用户真实 IP。
**本代理前会在每一个http(s)请求中添加了这两个 header。**
## 热更新支持
对于绝大多数配置,在web管理中的修改将实时使用,无需重启客户端或者服务端
## 客户端地址显示
在web管理中将显示客户端的连接地址
## 流量统计
可统计显示每个代理使用的流量,由于压缩和加密等原因,会和实际环境中的略有差异
## 当前客户端带宽
可统计每个客户端当前的带宽,可能和实际有一定差异,仅供参考。
## 客户端与服务端版本对比
为了程序正常运行,客户端与服务端的核心版本必须一致,否则将导致客户端无法成功连接致服务端。
## Linux系统限制
默认情况下linux对连接数量有限制,对于性能好的机器完全可以调整内核参数以处理更多的连接。
`tcp_max_syn_backlog` `somaxconn`
酌情调整参数,增强网络性能
## web管理保护
当一个 ip 连续登陆失败次数超过 10 次,将在一分钟内禁止该 ip 再次尝试。
可在 `nps.conf` 设置 `open_captcha=true` 进一步开启图形验证码
## 缓存支持
对于web站点来说,一些静态文件往往消耗更大的流量,且在内网穿透中,静态文件还需到客户端获取一次,这将导致更大的流量消耗。nps在域名解析代理中支持对静态文件进行缓存。
即假设一个站点有a.css,nps将只需从npc客户端读取一次该文件,然后把该文件的内容放在内存中,下一次将不再对npc客户端进行请求而直接返回内存中的对应内容。该功能默认是关闭的,如需开启请在`nps.conf`中设置`http_cache=true`,并设置`http_cache_length`(缓存文件的个数,消耗内存,不宜过大,0表示不限制个数)
## 数据压缩支持
由于是内网穿透,内网客户端与服务端之间的隧道存在大量的数据交换,为节省流量,加快传输速度,由此本程序支持SNNAPY形式的压缩。
- 所有模式均支持数据压缩
- 在web管理或客户端配置文件中设置
## 加密传输
如果公司内网防火墙对外网访问进行了流量识别与屏蔽,例如禁止了ssh协议等,通过设置 配置文件,将服务端与客户端之间的通信内容加密传输,将会有效防止流量被拦截。
- nps现在默认每次启动时随机生成tls证书,用于加密传输
> 链路加密的新方式:在 `nps.conf` 设置 `tls_enable=true`,客户端连接 `tls_bridge_port`(默认 `8025`)并加 `-tls_enable=true` 参数。详见 [TLS 桥接加密](/server/nps_extend.html#tls-桥接加密v02617)。
> nps 仍会在每次启动时随机生成 TLS 证书用于桥接通道。
## 站点保护
@@ -51,6 +75,18 @@
## 负载均衡
本代理支持域名解析模式和tcp代理的负载均衡,在web域名添加或者编辑中内网目标分行填写多个目标即可实现轮训级别的负载均衡
## 隧道端口自动生成
在 web 后台新增隧道时,**服务端端口留空即可自动生成**未被占用的端口号。
## 隧道复制
隧道列表页提供「复制」按钮:除了服务端端口随机生成,其他参数全部一键拷贝,方便创建多条相似隧道。
## TCP 隧道获取真实 IP
两种方式选一:
1. **[Proxy Protocol](/server/nps_extend.html#tcp-隧道-proxy-protocolv02623)**:在 web 上勾选开关,后端以 PROXY v1/v2 协议解析。
2. **HTTP 域名解析**:使用域名代理模式,配合 `http_add_origin_header=true` 通过 `X-Forwarded-For` / `X-Real-IP` 获取(见 [说明](/extend/description.html#获取用户真实ip))。
## 端口白名单
为了防止服务端上的端口被滥用,可在nps.conf中配置allow_ports限制可开启的端口,忽略或者不填表示端口不受限制,格式:
@@ -90,41 +126,10 @@ target_ip=10.1.50.2
支持域名泛解析,例如将host设置为*.proxy.com,a.proxy.com、b.proxy.com等都将解析到同一目标,在web管理中或客户端配置文件中将host设置为此格式即可。
## URL路由
本代理支持根据URL将同一域名转发到不同的内网服务器,可在web中或客户端配置文件中设置,此参数也可忽略,例如在客户端配置文件中
```ini
[web1]
host=a.proxy.com
target_addr=127.0.0.1:7001
location=/test
[web2]
host=a.proxy.com
target_addr=127.0.0.1:7002
location=/static
```
本代理支持根据URL将同一域名转发到不同的内网服务器,可在web中设置
对于`a.proxy.com/test`将转发到`web1`,对于`a.proxy.com/static`将转发到`web2`
## 限制ip访问
如果将一些危险性高的端口例如ssh端口暴露在公网上,可能会带来一些风险,本代理支持限制ip访问。
**使用方法:** 在配置文件nps.conf中设置`ip_limit`=true,设置后仅通过注册的ip方可访问。
**ip注册**:
**方式一:**
在需要访问的机器上,运行客户端
```
./npc register -server=ip:port -vkey=公钥或客户端密钥 time=2
```
time为有效小时数,例如time=2,在当前时间后的两小时内,本机公网ip都可以访问nps代理.
**方式二:**
此外nps的web登陆也可提供验证的功能,成功登陆nps web admin后将自动为登陆的ip注册两小时的允许访问权限。
**注意:** 本机公网ip并不是一成不变的,请自行注意有效期的设置,同时同一网络下,多人也可能是在公用同一个公网ip。
## 客户端最大连接数
为防止恶意大量长连接,影响服务端程序的稳定性,可以在web或客户端配置文件中为每个客户端设置最大连接数。该功能针对`socks5`、`http正向代理`、`域名代理`、`tcp代理`、`udp代理`、`私密代理`生效,使用该功能需要在`nps.conf`中设置`allow_connection_num_limit=true`,默认是关闭的。
@@ -164,79 +169,6 @@ export NPC_SERVER_VKEY=xxxxx
```
直接执行./npc即可运行
**在配置文件启动模式下:**
```ini
[common]
server_addr={{.NPC_SERVER_ADDR}}
conn_type=tcp
vkey={{.NPC_SERVER_VKEY}}
auto_reconnection=true
[web]
host={{.NPC_WEB_HOST}}
target_addr={{.NPC_WEB_TARGET}}
```
在配置文件中填入相应的环境变量名称,npc将自动进行渲染配置文件替换环境变量
## 健康检查
当客户端以配置文件模式启动时,支持多节点的健康检查。配置示例如下
```ini
[health_check_test1]
health_check_timeout=1
health_check_max_failed=3
health_check_interval=1
health_http_url=/
health_check_type=http
health_check_target=127.0.0.1:8083,127.0.0.1:8082
[health_check_test2]
health_check_timeout=1
health_check_max_failed=3
health_check_interval=1
health_check_type=tcp
health_check_target=127.0.0.1:8083,127.0.0.1:8082
```
**health关键词必须在开头存在**
第一种是http模式,也就是以get的方式请求目标+url,返回状态码为200表示成功
第一种是tcp模式,也就是以tcp的方式与目标建立连接,能成功建立连接表示成功
如果失败次数超过`health_check_max_failed`,nps则会移除该npc下的所有该目标,如果失败后目标重新上线,nps将自动将目标重新加入。
项 | 含义
---|---
health_check_timeout | 健康检查超时时间
health_check_max_failed | 健康检查允许失败次数
health_check_interval | 健康检查间隔
health_check_type | 健康检查类型
health_check_target | 健康检查目标,多个以逗号(,)分隔
health_check_type | 健康检查类型
health_http_url | 健康检查url,仅http模式适用
## 日志输出
日志输出级别
**对于npc:**
```
-log_level=0~7 -log_path=npc.log
```
```
LevelEmergency->0 LevelAlert->1
LevelCritical->2 LevelError->3
LevelWarning->4 LevelNotice->5
LevelInformational->6 LevelDebug->7
```
默认为全输出,级别为0到7
**对于nps:**
在`nps.conf`中设置相关配置即可
## pprof性能分析与调试
+396
View File
@@ -0,0 +1,396 @@
# Web API
> 除 `AuthController` 和 `LoginController` 外,所有接口均需通过鉴权,详见 [API 鉴权说明](api.html)。
## 通用响应格式
| 响应类型 | 格式 |
| --- | --- |
| 成功 | `{"status": 1, "msg": "success"}` |
| 成功(含 id) | `{"status": 1, "msg": "success", "id": 123}` |
| 失败 | `{"status": 0, "msg": "error message"}` |
| 列表 | `{"rows": [...], "total": 100}` |
> 单个查询接口(`GetClient`、`GetOneTunnel`、`GetHost`)返回 `{"code": 1, "data": {...}}` 或 `{"code": 0}`。
---
## Client 客户端管理
### 客户端列表
```
POST /client/list/
```
| 参数 | 含义 |
| --- | --- |
| search | 搜索关键词 |
| sort | 排序字段 |
| order | asc 正序 / desc 倒序 |
| offset | 分页起始 |
| limit | 每页条数 |
返回 `AjaxTable` 格式,额外含 `ip`、`bridgeType`、`bridgePort` 字段。
---
### 获取单个客户端
```
POST /client/getclient/
```
| 参数 | 含义 |
| --- | --- |
| id | 客户端 id |
---
### 添加客户端
```
POST /client/add/
```
| 参数 | 含义 |
| --- | --- |
| remark | 备注 |
| vkey | 客户端验证密钥 |
| u | basic 权限认证用户名 |
| p | basic 权限认证密码 |
| compress | 是否压缩传输,`true` / `false` |
| crypt | 是否加密传输,`true` / `false` |
| config_conn_allow | 是否允许客户端以配置文件模式连接,`true` / `false` |
| rate_limit | 带宽限制,单位 KB/s,留空不限制 |
| flow_limit | 流量限制,单位 M,留空不限制 |
| max_conn | 最大连接数,留空不限制 |
| max_tunnel | 最大隧道数,留空不限制 |
| web_username | web 用户登录用户名 |
| web_password | web 用户登录密码 |
| blackiplist | 黑名单 IP 列表,`\r\n` 分隔 |
| ipwhite | 是否开启 IP 白名单,`true` / `false` |
| ipwhitepass | IP 白名单授权密码 |
| ipwhitelist | 白名单 IP 列表,`\r\n` 分隔 |
| expire_time | 到期时间,留空表示永不过期。支持格式:`2006-01-02 15:04:05`、`2006-01-02 15:04`、`2006-01-02T15:04:05`、`2006-01-02T15:04`、`2006-01-02` |
---
### 修改客户端
```
POST /client/edit/
```
| 参数 | 含义 |
| --- | --- |
| id | 要修改的客户端 id |
| remark | 备注 |
| vkey | 客户端验证密钥(仅管理员可修改) |
| u | basic 权限认证用户名 |
| p | basic 权限认证密码 |
| compress | 是否压缩传输,`true` / `false` |
| crypt | 是否加密传输,`true` / `false` |
| config_conn_allow | 是否允许客户端以配置文件模式连接,`true` / `false` |
| rate_limit | 带宽限制,单位 KB/s(仅管理员可修改) |
| flow_limit | 流量限制,单位 M(仅管理员可修改) |
| max_conn | 最大连接数(仅管理员可修改) |
| max_tunnel | 最大隧道数(仅管理员可修改) |
| web_username | web 用户登录用户名 |
| web_password | web 用户登录密码 |
| blackiplist | 黑名单 IP 列表,`\r\n` 分隔 |
| ipwhite | 是否开启 IP 白名单,`true` / `false` |
| ipwhitepass | IP 白名单授权密码 |
| ipwhitelist | 白名单 IP 列表,`\r\n` 分隔 |
| expire_time | 到期时间,格式同新增接口 |
---
### 更改客户端状态
```
POST /client/changestatus/
```
| 参数 | 含义 |
| --- | --- |
| id | 客户端 id |
| status | `true` 启用 / `false` 禁用 |
---
### 删除客户端
```
POST /client/del/
```
| 参数 | 含义 |
| --- | --- |
| id | 要删除的客户端 id |
---
## Index 隧道管理
### 隧道列表
```
POST /index/gettunnel/
```
| 参数 | 含义 |
| --- | --- |
| client_id | 客户端 id |
| type | 隧道类型:`tcp`、`udp`、`httpProxy`、`socks5`、`secret`、`p2p`、`file` |
| search | 搜索关键词 |
| sort | 排序字段 |
| order | asc 正序 / desc 倒序 |
| offset | 分页起始 |
| limit | 每页条数 |
---
### 获取单条隧道
```
POST /index/getonetunnel/
```
| 参数 | 含义 |
| --- | --- |
| id | 隧道 id |
---
### 添加隧道
```
POST /index/add/
```
| 参数 | 含义 |
| --- | --- |
| client_id | 客户端 id |
| type | 隧道类型:`tcp`、`udp`、`httpProxy`、`socks5`、`secret`、`p2p`、`file` |
| remark | 备注 |
| port | 服务端端口(端口为 0 或留空时自动分配) |
| server_ip | 绑定的服务端 IP(多 IP 场景) |
| target | 内网目标,格式 `ip:端口` |
| local_proxy | 是否转发到 nps 服务器本地,`true` / `false` |
| password | 隧道密码(secret 模式) |
| local_path | 本地文件路径(file 模式) |
| strip_pre | URL 前缀去除(httpProxy 模式) |
| proto_version | 协议版本 |
---
### 复制隧道
```
POST /index/copy/
```
| 参数 | 含义 |
| --- | --- |
| id | 要复制的源隧道 id |
复制后自动分配新端口和新 id,其他配置沿用源隧道。
---
### 修改隧道
```
POST /index/edit/
```
| 参数 | 含义 |
| --- | --- |
| id | 隧道 id |
| client_id | 客户端 id |
| type | 隧道类型 |
| port | 服务端端口 |
| server_ip | 绑定的服务端 IP |
| target | 内网目标 |
| local_proxy | 是否转发到 nps 服务器本地 |
| remark | 备注 |
| password | 隧道密码 |
| local_path | 本地文件路径 |
| strip_pre | URL 前缀去除 |
| proto_version | 协议版本 |
---
### 停止隧道
```
POST /index/stop/
```
| 参数 | 含义 |
| --- | --- |
| id | 隧道 id |
---
### 启动隧道
```
POST /index/start/
```
| 参数 | 含义 |
| --- | --- |
| id | 隧道 id |
---
### 删除隧道
```
POST /index/del/
```
| 参数 | 含义 |
| --- | --- |
| id | 隧道 id |
---
## Host 域名解析管理
### 域名列表
```
POST /index/hostlist/
```
| 参数 | 含义 |
| --- | --- |
| client_id | 客户端 id |
| search | 搜索关键词(域名/备注) |
| offset | 分页起始 |
| limit | 每页条数 |
---
### 获取单条域名解析
```
POST /index/gethost/
```
| 参数 | 含义 |
| --- | --- |
| id | 域名解析 id |
---
### 添加域名解析
```
POST /index/addhost/
```
| 参数 | 含义 |
| --- | --- |
| client_id | 客户端 id |
| remark | 备注 |
| host | 域名 |
| scheme | 协议类型:`all`、`http`、`https` |
| location | URL 路由,留空不限制 |
| target | 内网目标,格式 `ip:端口` |
| local_proxy | 是否转发到 nps 服务器本地,`true` / `false` |
| header | 自定义 request header |
| hostchange | 修改 request host |
| key_file_path | HTTPS 证书私钥文本或路径 |
| cert_file_path | HTTPS 证书文件文本或路径 |
| AutoHttps | 是否自动 HTTPS(仅 scheme 非 `http` 时生效) |
---
### 修改域名解析
```
POST /index/edithost/
```
| 参数 | 含义 |
| --- | --- |
| id | 域名解析 id |
| client_id | 客户端 id |
| remark | 备注 |
| host | 域名 |
| scheme | 协议类型 |
| location | URL 路由 |
| target | 内网目标 |
| local_proxy | 是否转发到 nps 服务器本地 |
| header | 自定义 request header |
| hostchange | 修改 request host |
| key_file_path | HTTPS 证书私钥文本或路径 |
| cert_file_path | HTTPS 证书文件文本或路径 |
| AutoHttps | 是否自动 HTTPS |
---
### 停止域名解析
```
POST /index/hoststop/
```
| 参数 | 含义 |
| --- | --- |
| id | 域名解析 id |
---
### 启动域名解析
```
POST /index/hoststart/
```
| 参数 | 含义 |
| --- | --- |
| id | 域名解析 id |
---
### 删除域名解析
```
POST /index/delhost/
```
| 参数 | 含义 |
| --- | --- |
| id | 域名解析 id |
---
## Global 全局设置
### 查看全局设置
```
GET /global/index/
```
返回全局黑名单 IP 列表和服务端 URL。
---
### 保存全局设置
```
POST /global/save/
```
| 参数 | 含义 |
| --- | --- |
| globalBlackIpList | 全局黑名单 IP 列表,`\r\n` 分隔 |
| serverUrl | 服务端访问地址(用于更正显示 IP) |
---
-20
View File
@@ -1,20 +0,0 @@
# FAQ
- 服务端无法启动
```
服务端默认配置启用了8024,8080,80,443端口,端口冲突无法启动,请修改配置
```
- 客户端无法连接服务端
```
请检查配置文件中的所有端口是否在安全组,防火墙放行
请检查vkey是否对应
请检查版本是否对应
```
- 服务端配置文件修改无效
```
install 之后,Linux 配置文件在 /etc/nps
```
- p2p穿透失败 [p2p服务](https://ehang-io.github.io/nps/#/example?id=p2p%e6%9c%8d%e5%8a%a1)
```
双方nat类型都是Symmetric Nat一定不成功,建议先查看nat类型。请按照文档操作(标题上有超链接)
```
-43
View File
@@ -1,43 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
<meta name="description" content="Description">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<link rel="stylesheet" href="//unpkg.com/docsify/lib/themes/vue.css">
</head>
<body>
<div id="app"></div>
<script src="//unpkg.com/docsify-edit-on-github/index.js"></script>
<script>
window.$docsify = {
name: '',
repo: '',
loadSidebar: true,
coverpage: true,
loadNavbar: true,
subMaxLevel: 2,
maxLevel: 4,
search: {
noData: "没有结果",
paths: 'auto',
placeholder: "搜索",
hideOtherSidebarContent: true, // whether or not to hide other sidebar content
},
plugins: [
EditOnGithubPlugin.create("https://github.com/ehang-io/nps/tree/master/docs/", "", "在github上编辑"),
]
}
</script>
<script src="//unpkg.com/docsify/lib/docsify.min.js"></script>
<script src="//unpkg.com/docsify/lib/plugins/search.min.js"></script>
<script src="//unpkg.com/docsify-copy-code"></script>
</body>
</html>
-18
View File
@@ -1,18 +0,0 @@
# 安装
## 安装包安装
[releases](https://github.com/ehang-io/nps/releases)
下载对应的系统版本即可,服务端和客户端是单独的
## 源码安装
- 安装源码
```go get -u ehang.io/nps```
- 编译
服务端```go build cmd/nps/nps.go```
客户端```go build cmd/npc/npc.go```
## docker安装
> [server](https://hub.docker.com/r/ffdfgdfg/nps)
> [client](https://hub.docker.com/r/ffdfgdfg/npc)
+125
View File
@@ -0,0 +1,125 @@
## 程序安装
从 [releases](https://github.com/yisier/nps/releases) 下载对应系统版本,服务端 (`nps`) 和客户端 (`npc`) 是单独的压缩包。
::: tabs
@tab 服务端
> 首次启动时 `nps` 会在可执行文件同级目录自动生成 `conf/nps.conf`,并随机生成 `web_password`、`auth_key`、`auth_crypt_key`,web 管理界面的访问密码请在conf/nps.conf文件中或启动日志中查看。
`./npc(.exe) -server`
![img.png](/image/new/server.png)
@tab 客户端
> 客户端可直接双击运行,通过交互菜单完成安装、卸载、启动等操作。
`./npc(.exe)`
![image](/image/new/cmd.png)
@tab 客户端(GUI)
> 通过Web 后台的【快捷启动命令】或 手动填写 `-server`、`-vkey` 等参数配置客户端
![img](/image/new/gui.png)
:::
## Docker 安装
::: tabs
@tab 服务端
先拉取镜像:
```shell
docker pull yisier1/nps
```
启动容器,请把 `<本机conf目录>` 替换为实际路径(例如 `/root/nps/conf`):
```shell
docker run -d \
--restart=always \
--name nps \
--net=host \
-v <本机conf目录>:/conf \
-v /etc/localtime:/etc/localtime:ro \
yisier1/nps
```
@tab 客户端
先拉取镜像:
```shell
docker pull yisier1/npc
```
启动容器,请把 `<>` 内的值替换为实际配置:
```shell
docker run -d \
--restart=always \
--name <自定义名称> \
--net=host \
yisier1/npc \
-server=<服务器IP:端口> \
-vkey=<密钥>
```
:::
镜像主页:[NPS](https://hub.docker.com/r/yisier1/nps) | [NPC](https://hub.docker.com/r/yisier1/npc)。
## 宝塔面板(一键部署)
> 推荐宝塔版本 9.2.0+,前往 [宝塔面板官网](https://www.bt.cn/new/download.html) 安装。
![宝塔面板](/image/bt/bt1.jpg)
### 安装宝塔面板
1. 前往 [宝塔面板官网](https://www.bt.cn/new/download.html),选择正式版脚本安装。
2. 登录面板,点击左侧 **Docker** 进入 Docker 管理。
3. 如提示未安装 Docker / Docker Compose,可根据上方引导安装。
### 安装 NPS 服务端
1. 在宝塔面板 Docker 菜单进入 **应用商城**,搜索 `NPS`,找到 **NPS 服务端** 并点击安装。
2. 进入安装目录,修改 `conf/nps.conf` 即可(修改后重启容器)。参数说明详见 [配置文件](/server/server_config.html)。
![配置截图](/image/bt/bt2.png)
> **注意**:NPS 默认占用的端口为 `80`、`443`,如被占用请修改 `nps.conf` 中的 `http_proxy_port` 和 `https_proxy_port`。Web 管理默认端口 `8081`,启动后访问 `http://<IP>:8081`。
### 安装 NPS 客户端
1. 在宝塔面板 Docker 菜单进入 **应用商城**,搜索 `NPS`,找到 **NPS 客户端** 并点击安装。
2. 客户端支持两种配置方式:
- **无配置文件模式(推荐)**:输入 `服务地址`、`连接密钥` 即可启动。如需多个客户端,安装多个即可(名称不要重复)。
- **配置文件模式**:`服务地址`、`连接密钥` 留空直接安装,然后在安装目录下找到 `conf/npc.conf` 修改配置并重启容器。详见 [配置文件说明](/client/use.html#配置文件模式)。
![客户端配置](/image/bt/bt3.png)
> **推荐使用无配置文件模式**,所有数据在服务端保存和配置,客户端只做连接转发。配置文件模式对新手不友好,容易出错。
## 源码安装
需要 Go 1.22 及以上(仓库 `go.mod` 中 `toolchain` 锁定为 `go1.24.9`)。
```shell
git clone https://github.com/yisier/nps.git
cd nps
go build -o nps cmd/nps/nps.go
go build -o npc cmd/npc/npc.go
```
-4
View File
@@ -1,4 +0,0 @@
![image](https://github.com/ehang-io/nps/blob/master/image/web2.png?raw=true)
# 介绍
可在网页上配置和管理各个tcp、udp隧道、内网站点代理,http、https解析等,功能强大,操作方便。
BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 614 KiB

-107
View File
@@ -1,107 +0,0 @@
# 增强功能
## 使用https
**方式一:** 类似于nginx实现https的处理
在配置文件中将https_proxy_port设置为443或者其他你想配置的端口,将`https_just_proxy`设置为false,nps 重启后,在web管理界面,域名新增或修改界面中修改域名证书和密钥。
**此外:** 可以在`nps.conf`中设置一个默认的https配置,当遇到未在web中设置https证书的域名解析时,将自动使用默认证书,另还有一种情况就是对于某些请求的clienthello不携带sni扩展信息,nps也将自动使用默认证书
**方式二:** 在内网对应服务器上设置https
在`nps.conf`中将`https_just_proxy`设置为true,并且打开`https_proxy_port`端口,然后nps将直接转发https请求到内网服务器上,由内网服务器进行https处理
## 与nginx配合
有时候我们还需要在云服务器上运行nginx来保证静态文件缓存等,本代理可和nginx配合使用,在配置文件中将httpProxyPort设置为非80端口,并在nginx中配置代理,例如httpProxyPort为8010时
```
server {
listen 80;
server_name *.proxy.com;
location / {
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:8010;
}
}
```
如需使用https也可在nginx监听443端口并配置ssl,并将本代理的httpsProxyPort设置为空关闭https即可,例如httpProxyPort为8020时
```
server {
listen 443;
server_name *.proxy.com;
ssl on;
ssl_certificate certificate.crt;
ssl_certificate_key private.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
location / {
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:8020;
}
}
```
## web管理使用https
如果web管理需要使用https,可以在配置文件`nps.conf`中设置`web_open_ssl=true`,并配置`web_cert_file`和`web_key_file`
## web使用Caddy代理
如果将web配置到Caddy代理,实现子路径访问nps,可以这样配置.
假设我们想通过 `http://caddy_ip:caddy_port/nps` 来访问后台, Caddyfile 这样配置:
```Caddyfile
caddy_ip:caddy_port/nps {
##server_ip 为 nps 服务器IP
##web_port 为 nps 后台端口
proxy / http://server_ip:web_port/nps {
transparent
}
}
```
nps.conf 修改 `web_base_url` 为 `/nps` 即可
```
web_base_url=/nps
```
## 关闭代理
如需关闭http代理可在配置文件中将http_proxy_port设置为空,如需关闭https代理可在配置文件中将https_proxy_port设置为空。
## 流量数据持久化
服务端支持将流量数据持久化,默认情况下是关闭的,如果有需求可以设置`nps.conf`中的`flow_store_interval`参数,单位为分钟
**注意:** nps不会持久化通过公钥连接的客户端
## 系统信息显示
nps服务端支持在web上显示和统计服务器的相关信息,但默认一些统计图表是关闭的,如需开启请在`nps.conf`中设置`system_info_display=true`
## 自定义客户端连接密钥
web上可以自定义客户端连接的密钥,但是必须具有唯一性
## 关闭公钥访问
可以将`nps.conf`中的`public_vkey`设置为空或者删除
## 关闭web管理
可以将`nps.conf`中的`web_port`设置为空或者删除
## 服务端多用户登陆
如果将`nps.conf`中的`allow_user_login`设置为true,服务端web将支持多用户登陆,登陆用户名为user,默认密码为每个客户端的验证密钥,登陆后可以进入客户端编辑修改web登陆的用户名和密码,默认该功能是关闭的。
## 用户注册功能
nps服务端支持用户注册功能,可将`nps.conf`中的`allow_user_register`设置为true,开启后登陆页将会有有注册功能,
## 监听指定ip
nps支持每个隧道监听不同的服务端端口,在`nps.conf`中设置`allow_multi_ip=true`后,可在web中控制,或者npc配置文件中(可忽略,默认为0.0.0.0)
```ini
server_ip=xxx
```
## 代理到服务端本地
在使用nps监听80或者443端口时,默认是将所有的请求都会转发到内网上,但有时候我们的nps服务器的上一些服务也需要使用这两个端口,nps提供类似于`nginx` `proxy_pass` 的功能,支持将代理到服务器本地,该功能支持域名解析,tcp、udp隧道,默认关闭。
**即:** 假设在nps的vps服务器上有一个服务使用5000端口,这时候nps占用了80端口和443,我们想能使用一个域名通过http(s)访问到5000的服务。
**使用方式:** 在`nps.conf`中设置`allow_local_proxy=true`,然后在web上设置想转发的隧道或者域名然后选择转发到本地选项即可成功。
-47
View File
@@ -1,47 +0,0 @@
# 使用
**提示:使用web模式时,服务端执行文件必须在项目根目录,否则无法正确加载配置文件**
## web管理
进入web界面,公网ip:web界面端口(默认8080),密码默认为123
进入web管理界面,有详细的说明
## 服务端配置文件重载
对于linux、darwin
```shell
sudo nps reload
```
对于windows
```shell
nps.exe reload
```
**说明:** 仅支持部分配置重载,例如`allow_user_login` `auth_crypt_key` `auth_key` `web_username` `web_password` 等,未来将支持更多
## 服务端停止或重启
对于linux、darwin
```shell
sudo nps stop|restart
```
对于windows
```shell
nps.exe stop|restart
```
## 服务端更新
请首先执行 `sudo nps stop` 或者 `nps.exe stop` 停止运行,然后
对于linux
```shell
sudo nps-update update
```
对于windows
```shell
nps-update.exe update
```
更新完成后,执行执行 `sudo nps start` 或者 `nps.exe start` 重新运行即可完成升级
如果无法更新成功,可以直接自行下载releases压缩包然后覆盖原有的nps二进制文件和web目录
注意:`nps install` 之后的 nps 不在原位置,请使用 `whereis nps` 查找具体目录覆盖 nps 二进制文件
+24
View File
@@ -0,0 +1,24 @@
{
"name": "nps-docs",
"version": "1.0.0",
"description": "NPS 内网穿透文档站点 (VuePress 2)",
"private": true,
"scripts": {
"docs:dev": "vuepress dev .",
"docs:build": "vuepress build .",
"docs:clean": "vuepress clean ."
},
"devDependencies": {
"@vuepress/bundler-vite": "2.0.0-rc.30",
"@vuepress/plugin-search": "2.0.0-rc.130",
"@vuepress/plugin-shiki": "2.0.0-rc.130",
"@vuepress/theme-default": "2.0.0-rc.130",
"sass": "1.77.8",
"vite": "^8.0.16",
"vue": "^3.5.34",
"vuepress": "2.0.0-rc.30"
},
"resolutions": {
"@vuepress/plugin-palette": "2.0.0-rc.130"
}
}
-42
View File
@@ -1,42 +0,0 @@
# 启动
## 服务端
下载完服务器压缩包后,解压,然后进入解压后的文件夹
- 执行安装命令
对于linux|darwin ```sudo ./nps install```
对于windows,管理员身份运行cmd,进入安装目录 ```nps.exe install```
- 启动
对于linux|darwin ```sudo nps start```
对于windows,管理员身份运行cmd,进入程序目录 ```nps.exe start```
```安装后windows配置文件位于 C:\Program Files\nps,linux和darwin位于/etc/nps```
停止和重启可用,stop和restart
**如果发现没有启动成功,可以使用`nps(.exe) stop`,然后运行`nps.(exe)`运行调试,或查看日志**(Windows日志文件位于当前运行目录下,linux和darwin位于/var/log/nps.log)
- 访问服务端ip:web服务端口(默认为8080)
- 使用用户名和密码登陆(默认admin/123,正式使用一定要更改)
- 创建客户端
## 客户端
- 下载客户端安装包并解压,进入到解压目录
- 点击web管理中客户端前的+号,复制启动命令
- 执行启动命令,linux直接执行即可,windows将./npc换成npc.exe用**cmd执行**
如果使用`powershell`运行,**请将ip括起来!**
如果需要注册到系统服务可查看[注册到系统服务](/use?id=注册到系统服务)
## 版本检查
- 对客户端以及服务的均可以使用参数`-version`打印版本
- `nps -version`或`./nps -version`
- `npc -version`或`./npc -version`
## 配置
- 客户端连接后,在web中配置对应穿透服务即可
- 可以查看[使用示例](/example)
+195
View File
@@ -0,0 +1,195 @@
# 增强功能
## 使用 https
> nps 会根据域名是否上传了证书自动选择处理方式:
| 是否在 web 上传证书 | 行为 | 真实 IP |
| --- | --- | --- |
| 是 | nps 直接接管 SSL 终结,再转发到内网 | ✅ 可拿到 |
| 否 | nps 透传 TLS(端口转发),由内网服务器自行解密 | ❌ 拿不到 |
![image](/image/new/https.png)
## 自动 HTTPS
在 web 域名编辑页勾选「自动 HTTPS」后,nps 会把对应域名的 http 请求 301 重定向到 https。
重定向会按 `https_proxy_port` 配置的端口跳转(例如 `https_proxy_port=8443` 时会跳到 `https://<host>:8443/...`),方便非标准端口部署。
## HTTPS 证书来源
web 域名编辑页的「证书」/「私钥」字段同时支持:
- **直接粘贴证书 / 私钥内容**
- **填写服务器上的文件路径**(例如 `/etc/letsencrypt/live/proxy.com/fullchain.pem`)
nps 会自动识别是文件路径还是内容。文件路径方式便于配合 acme.sh / certbot 自动续期,无需每次手工拷贝。
## TLS 桥接加密
为防止客户端到服务端的桥接流量被防火墙识别和拦截,可启用 TLS:
```ini
# nps.conf
tls_enable=true
tls_bridge_port=8025 # v0.26.18 引入,与 bridge_port 并存
```
客户端任选一种方式接入:
```shell
npc.exe -server=1.1.1.1:8024 -vkey=xxx # 明文桥接(bridge_port)
npc.exe -server=1.1.1.1:8025 -vkey=xxx -tls_enable=true # TLS 桥接(tls_bridge_port)
```
> 客户端忽略证书校验,请勿暴露在不可信网络里。
## 全局参数
> 未来会在此页面继续扩展更多功能,欢迎提需求。
web 后台 → 全局参数 页面(对应 `conf/global.json`):
| 字段 | 含义 |
| --- | --- |
| 全局 IP 黑名单 | 一行一个 IPv4,不支持范围匹配。命中后所有 TCP/HTTP/HTTPS/UDP 入口请求都会被直接关闭。用于防止扫描和暴力破解 |
| 服务地址 |用于在 web 上生成 [客户端快捷启动命令]、隧道访问 URL 时拼接的服务端地址。留空则使用浏览器当前访问地址 |
## 客户端黑名单
在客户端编辑页可填写多个 IP,命中后该客户端下所有隧道都会拒绝服务,用于针对单个客户端阻断。
## 客户端白名单 + IP 授权
在客户端编辑页:
1. 直接添加 IP 到白名单
2. 或填写「IP 授权密码」。当外网 IP 不在白名单时,会被重定向到 IP 授权页面,输入正确密码即可把该 IP 自动加入白名单。
![img](/image/new/ip.png)
## Proxy Protocol
在 web 上 TCP 隧道编辑页开启「Proxy Protocol」开关,nps 会以 PROXY v1/v2 协议向后端转发原始来源 IP。后端服务(nginx、HAProxy 等)只需正常解析 PROXY 协议即可拿到真实客户端 IP。
![img](/image/new/protocol.png)
## WEB登录验证码
`nps.conf` 中:
```ini
open_captcha=true
```
开启后 web 登录页会要求图形验证码。结合「web 管理保护」(连续 10 次失败封禁 1 分钟,见 [说明](/extend/description.html#web管理保护)),可以有效缓解暴力破解。
## 关闭代理
如需关闭 http 代理,将 `http_proxy_port` 留空;如需关闭 https 代理,将 `https_proxy_port` 留空。
## 流量数据持久化
服务端支持将流量数据持久化,默认关闭。在 `nps.conf` 中设置 `flow_store_interval`(单位分钟)即可开启。
**注意:** nps 不会持久化通过公钥连接的客户端。
## 系统信息显示
nps 服务端支持在 web 上显示和统计服务器相关信息,但默认部分统计图表是关闭的。如需开启请在 `nps.conf` 中设置 `system_info_display=true`。
## 关闭 web 管理
将 `nps.conf` 中的 `web_port` 设置为空或删除。
## 服务端多用户登录
将 `allow_user_login=true`,登录用户名 `user`,密码为对应客户端的验证密钥。登录后可进入客户端编辑修改 web 登录用户名密码。默认关闭。
## 用户注册功能
将 `allow_user_register=true` 后登录页会出现注册入口。
## 监听指定 IP
nps 支持每个隧道监听不同的服务端 IP,`nps.conf` 中设置 `allow_multi_ip=true` 后,可在 web 中控制,或 npc 配置文件中指定:
```ini
server_ip=xxx
```
## 客户端到期时间
在创建 / 修改客户端时可填写「到期时间」(可留空表示永不过期)。到期后该客户端会被**自动暂停**,所有隧道停止服务,直到管理员手工延长或清空到期时间。
支持格式:`2006-01-02 15:04:05` / `2006-01-02 15:04` / `2006-01-02T15:04:05` / `2006-01-02T15:04` / `2006-01-02`。
## 首次启动随机凭据
为避免默认密码被恶意扫描,**首次启动时** `web_username`(默认 `admin`)、`web_password`、`auth_key`、`auth_crypt_key` 全部随机生成,并直接打印到终端:
```text
[INFO] generated random web_password: <xxxxxxxx>
[INFO] generated random auth_key: <xxxxxxxx>
[INFO] generated random auth_crypt_key: <xxxxxxxxxxxxxxxx>
```
请在第一次启动时妥善记录。后续可在 `nps.conf` 中手工修改。
## 与 nginx 配合
有时需要在云服务器上跑 nginx 做静态缓存或多服务复用 80/443。把 `http_proxy_port` 设为非 80 端口(例如 8010),由 nginx 反代:
```
server {
listen 80;
server_name *.proxy.com;
location / {
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:8010;
}
}
```
如需 https 也由 nginx 终结,将 `https_proxy_port` 留空关闭,由 nginx 监听 443:
```
server {
listen 443;
server_name *.proxy.com;
ssl on;
ssl_certificate certificate.crt;
ssl_certificate_key private.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
location / {
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:8020;
}
}
```
## web 管理使用 https
在 `nps.conf` 中设置 `web_open_ssl=true`,并配置 `web_cert_file` 与 `web_key_file`。
## web 使用 Caddy 代理
实现子路径访问 nps,假设想通过 `http://caddy_ip:caddy_port/nps` 访问后台:
```nginx
caddy_ip:caddy_port/nps {
##server_ip 为 nps 服务器IP
##web_port 为 nps 后台端口
proxy / http://server_ip:web_port/nps {
transparent
}
}
```
`nps.conf` 中设置:
```
web_base_url=/nps
```
+50
View File
@@ -0,0 +1,50 @@
## Web 管理
进入 web 界面:`公网IP:web 端口`(默认 `8081`)。
> **首次启动 `web_username`(默认 `admin`)、`web_password`、`auth_key`、`auth_crypt_key` 均为随机生成**,会打印到终端日志中,请第一时间复制保存。后续如需变更可直接修改 `conf/nps.conf` 后 `nps reload`。
进入 web 管理界面,有详细的说明。
## 服务端管理脚本
```shell
./nps -server # linux/darwin(操作系统服务时需 sudo)
nps.exe -server # windows(操作系统服务时需管理员)
```
交互菜单覆盖了安装、卸载、启停、重启、更新等全部场景。
![img.png](/image/new/server.png)
## 工作目录与配置文件位置
- nps安装系统服务后,配置文件默认在当前目录,目录结构为:
```
nps_dir/
├── conf/
│ └── nps.conf // nps主配置文件
│ └── client.json // 客户端列表配置文件
│ └── tasks.json // 隧道列表配置文件
│ └── hosts.json // 域名解析列表配置文件
│ └── global.json // 全局参数配置文件
├── nps // nps主程序
```
## 更新
```shell
./nps -server # 选择 “更新” 菜单项
```
更新只会替换 `nps` 二进制文件,对配置文件和用户数据无影响,更新完成后重新启动即可。
>如果无法成功更新,可直接下载 releases 压缩包覆盖原有的 `nps` 二进制文件。
## 数据迁移
数据迁移只需迁移 `conf` 目录,该目录包含配置文件以及用户数据(json格式文件),放到 nps(.exe) 的同级目录下,直接启动即可。
+89
View File
@@ -0,0 +1,89 @@
# 服务端配置文件
配置文件路径:`<nps 可执行文件目录>/conf/nps.conf`
> 首次启动时若 `conf/nps.conf` 不存在会**自动生成默认配置**,其中 `web_username`(默认 `admin`)、`web_password`、`auth_key`、`auth_crypt_key` **均为随机值**并打印到终端,请在启动日志或配置文件中查看。
## 通用配置
| 名称 | 含义 | 默认值 |
| --- | --- | --- |
| bridge_type | 客户端与服务端连接方式 `tcp` 或 `kcp` | `tcp` |
| bridge_ip | 桥接监听 IP | `0.0.0.0` |
| bridge_port | 服务端客户端通信端口 | `8024` |
| tls_enable | 是否开启 TLS。开启后客户端可通过 `-tls_enable=true` 连接 `tls_bridge_port` | `true` |
| tls_bridge_port | TLS 桥接端口,默认 `8025`。**与 `bridge_port` 并存**:客户端可分别用 `bridge_port`(明文)或 `tls_bridge_port`(TLS)接入 | `8025` |
| disconnect_timeout | 客户端连接超时,单位为 5s,默认 `60`(即 5 分钟) | `60` |
| flow_store_interval | 流量数据持久化间隔,单位分钟;忽略表示不持久化| `1` |
| log_level | 日志级别 0~7 | `6` |
| log_path | 日志文件路径 | `nps.log` |
| ip_limit | 是否限制 IP 访问,`true` / `false` / 忽略 | - |
## HTTP(S) 代理
| 名称 | 含义 | 默认值 |
| --- | --- | --- |
| http_proxy_ip | http(s) 代理监听 IP,默认 `0.0.0.0` | `0.0.0.0` |
| http_proxy_port | 域名代理 http 监听端口(默认 `80`),留空关闭 | `80` |
| https_proxy_port | 域名代理 https 监听端口(默认 `443`),留空关闭。详见 [使用 https](/server/nps_extend.html#使用-https) | `443` |
| show_http_proxy_port | 域名隧道访问地址是否拼接非 80/443 端口,`true` / `false` | `true` |
| http_add_origin_header | 是否在 http(s) 请求头中追加 `X-Forwarded-For` / `X-Real-IP`,用于内网获取真实 IP | `true` |
| http_cache | 是否开启静态文件缓存 | `false` |
| http_cache_length | 缓存条目数上限,`0` 表示不限制 | `100` |
## Web 管理后台
| 名称 | 含义 | 默认值 |
| --- | --- | --- |
| web_host | web 管理使用的二级域名,端口复用时区分用 | `a.o.com` |
| web_username | web 后台用户名(默认 `admin` | `admin` |
| web_password | web 后台密码 | 首次启动随机生成 |
| web_port | web 管理端口,留空关闭 web | `8081` |
| web_ip | web 管理监听 IP | `0.0.0.0` |
| web_base_url | web 管理子路径,例如 `/nps`,用于反代到子路径时使用 | (空) |
| web_open_ssl | web 管理是否启用 https | `false` |
| web_cert_file | web 管理 https 证书路径 | `conf/server.pem` |
| web_key_file | web 管理 https 私钥路径 | `conf/server.key` |
| open_captcha | 登录是否开启验证码校验 | `false` |
| allow_user_login | 是否允许多用户登录,开启后用户名 `user`,密码为客户端的验证密钥 | `true` |
| allow_user_register | 是否允许从登录页注册账号 | `false` |
| allow_user_change_username | 多用户登录后是否允许修改用户名 | `true` |
## API 鉴权
| 名称 | 含义 | 默认值 |
| --- | --- | --- |
| auth_key | web API 鉴权密钥,详见 [Web API](/nps/extend/api.html) | 首次启动随机生成 |
| auth_crypt_key | `auth/getauthkey` 接口的 AES 加密密钥,**必须 16 位** | 首次启动随机生成 |
## P2P
| 名称 | 含义 | 默认值 |
| --- | --- | --- |
| p2p_ip | 服务端 IP,使用 p2p 模式必填 | - |
| p2p_port | p2p 模式开启的 UDP 起始端口。若设为 `6000`,请额外开放 `6001`、`6002` | - |
## 限制开关
> 这些开关默认关闭。开启后才会在 web 管理中暴露对应字段。
| 名称 | 含义 | 默认值 |
| --- | --- | --- |
| allow_flow_limit | 是否启用客户端流量限制 | `true` |
| allow_rate_limit | 是否启用客户端带宽限制 | `true` |
| allow_tunnel_num_limit | 是否启用客户端最大隧道数限制 | `true` |
| allow_connection_num_limit | 是否启用客户端最大连接数限制 | `true` |
| allow_multi_ip | 是否允许每个隧道监听不同的服务端 IP | `true` |
| allow_local_proxy | 是否允许把隧道目标转发到 nps 所在服务器本地 | `false` |
| allow_ports | 限制可开放的隧道端口范围,例如 `9001-9009,10001,11000-12000`,留空不限制 | (空) |
| system_info_display | 是否在 web 上展示服务器系统监控信息图表 | `true` |
## debug / pprof
| 名称 | 含义 | 默认值 |
| --- | --- | --- |
| pprof_ip | debug pprof 监听 IP | - |
| pprof_port | debug pprof 监听端口 | - |
-24
View File
@@ -1,24 +0,0 @@
# 服务端配置文件
- /etc/nps/conf/nps.conf
名称 | 含义
---|---
web_port | web管理端口
web_password | web界面管理密码
web_username | web界面管理账号
web_base_url | web管理主路径,用于将web管理置于代理子路径后面
bridge_port | 服务端客户端通信端口
https_proxy_port | 域名代理https代理监听端口
http_proxy_port | 域名代理http代理监听端口
auth_key|web api密钥
bridge_type|客户端与服务端连接方式kcp或tcp
public_vkey|客户端以配置文件模式启动时的密钥,设置为空表示关闭客户端配置文件连接模式
ip_limit|是否限制ip访问,true或false或忽略
flow_store_interval|服务端流量数据持久化间隔,单位分钟,忽略表示不持久化
log_level|日志输出级别
auth_crypt_key | 获取服务端authKey时的aes加密密钥,16位
p2p_ip| 服务端Ip,使用p2p模式必填
p2p_port|p2p模式开启的udp端口
pprof_ip|debug pprof 服务端ip
pprof_port|debug pprof 端口
disconnect_timeout|客户端连接超时,单位 5s,默认值 60,即 300s = 5mins
-5
View File
@@ -1,5 +0,0 @@
Thanks [jetbrains](https://www.jetbrains.com/?from=nps) for providing development tools for nps
<html>
<img src="https://ftp.bmp.ovh/imgs/2019/12/6435398b0c7402b1.png" width="300" align=center />
</html>
-225
View File
@@ -1,225 +0,0 @@
# 基本使用
## 无配置文件模式
此模式的各种配置在服务端web管理中完成,客户端除运行一条命令外无需任何其他设置
```
./npc -server=ip:port -vkey=web界面中显示的密钥
```
## 注册到系统服务(开机启动、守护进程)
对于linux、darwin
- 注册:`sudo ./npc install 其他参数(例如-server=xx -vkey=xx或者-config=xxx)`
- 启动:`sudo npc start`
- 停止:`sudo npc stop`
- 如果需要更换命令内容需要先卸载`./npc uninstall`,再重新注册
对于windows,使用管理员身份运行cmd
- 注册:`npc.exe install 其他参数(例如-server=xx -vkey=xx或者-config=xxx)`
- 启动:`npc.exe start`
- 停止:`npc.exe stop`
- 如果需要更换命令内容需要先卸载`npc.exe uninstall`,再重新注册
- 如果需要当客户端退出时自动重启客户端,请按照如图所示配置
![image](https://github.com/ehang-io/nps/blob/master/docs/windows_client_service_configuration.png?raw=true)
注册到服务后,日志文件windows位于当前目录下,linux和darwin位于/var/log/npc.log
## 客户端更新
首先进入到对于的客户端二进制文件目录
请首先执行`sudo npc stop`或者`npc.exe stop`停止运行,然后
对于linux
```shell
sudo npc-update update
```
对于windows
```shell
npc-update.exe update
```
更新完成后,执行执行`sudo npc start`或者`npc.exe start`重新运行即可完成升级
如果无法更新成功,可以直接自行下载releases压缩包然后覆盖原有的npc二进制文件
## 配置文件模式
此模式使用nps的公钥或者客户端私钥验证,各种配置在客户端完成,同时服务端web也可以进行管理
```
./npc -config=npc配置文件路径
```
## 配置文件说明
[示例配置文件](https://github.com/ehang-io/nps/tree/master/conf/npc.conf)
#### 全局配置
```ini
[common]
server_addr=1.1.1.1:8024
conn_type=tcp
vkey=123
username=111
password=222
compress=true
crypt=true
rate_limit=10000
flow_limit=100
remark=test
max_conn=10
#pprof_addr=0.0.0.0:9999
```
项 | 含义
---|---
server_addr | 服务端ip/域名:port
conn_type | 与服务端通信模式(tcp或kcp)
vkey|服务端配置文件中的密钥(非web)
username|socks5或http(s)密码保护用户名(可忽略)
password|socks5或http(s)密码保护密码(可忽略)
compress|是否压缩传输(true或false或忽略)
crypt|是否加密传输(true或false或忽略)
rate_limit|速度限制,可忽略
flow_limit|流量限制,可忽略
remark|客户端备注,可忽略
max_conn|最大连接数,可忽略
pprof_addr|debug pprof ip:port
#### 域名代理
```ini
[common]
server_addr=1.1.1.1:8024
vkey=123
[web1]
host=a.proxy.com
target_addr=127.0.0.1:8080,127.0.0.1:8082
host_change=www.proxy.com
header_set_proxy=nps
```
项 | 含义
---|---
web1 | 备注
host | 域名(http|https都可解析)
target_addr|内网目标,负载均衡时多个目标,逗号隔开
host_change|请求host修改
header_xxx|请求header修改或添加,header_proxy表示添加header proxy:nps
#### tcp隧道模式
```ini
[common]
server_addr=1.1.1.1:8024
vkey=123
[tcp]
mode=tcp
target_addr=127.0.0.1:8080
server_port=9001
```
项 | 含义
---|---
mode | tcp
server_port | 在服务端的代理端口
tartget_addr|内网目标
#### udp隧道模式
```ini
[common]
server_addr=1.1.1.1:8024
vkey=123
[udp]
mode=udp
target_addr=127.0.0.1:8080
server_port=9002
```
项 | 含义
---|---
mode | udp
server_port | 在服务端的代理端口
target_addr|内网目标
#### http代理模式
```ini
[common]
server_addr=1.1.1.1:8024
vkey=123
[http]
mode=httpProxy
server_port=9003
```
项 | 含义
---|---
mode | httpProxy
server_port | 在服务端的代理端口
#### socks5代理模式
```ini
[common]
server_addr=1.1.1.1:8024
vkey=123
[socks5]
mode=socks5
server_port=9004
multi_account=multi_account.conf
```
项 | 含义
---|---
mode | socks5
server_port | 在服务端的代理端口
multi_account | socks5多账号配置文件(可选),配置后使用basic_username和basic_password无法通过认证
#### 私密代理模式
```ini
[common]
server_addr=1.1.1.1:8024
vkey=123
[secret_ssh]
mode=secret
password=ssh2
target_addr=10.1.50.2:22
```
项 | 含义
---|---
mode | secret
password | 唯一密钥
target_addr|内网目标
#### p2p代理模式
```ini
[common]
server_addr=1.1.1.1:8024
vkey=123
[p2p_ssh]
mode=p2p
password=ssh2
target_addr=10.1.50.2:22
```
项 | 含义
---|---
mode | p2p
password | 唯一密钥
target_addr|内网目标
#### 文件访问模式
利用nps提供一个公网可访问的本地文件服务,此模式仅客户端使用配置文件模式方可启动
```ini
[common]
server_addr=1.1.1.1:8024
vkey=123
[file]
mode=file
server_port=9100
local_path=/tmp/
strip_pre=/web/
````
项 | 含义
---|---
mode | file
server_port | 服务端开启的端口
local_path|本地文件目录
strip_pre|前缀
对于`strip_pre`,访问公网`ip:9100/web/`相当于访问`/tmp/`目录
#### 断线重连
```ini
[common]
auto_reconnection=true
```
-233
View File
@@ -1,233 +0,0 @@
获取客户端列表
```
POST /client/list/
```
| 参数 | 含义 |
| --- | --- |
| search | 搜索 |
| order | 排序asc 正序 desc倒序 |
| offset | 分页(第几页) |
| limit | 条数(分页显示的条数) |
***
获取单个客户端
```
POST /client/getclient/
```
| 参数 | 含义 |
| --- | --- |
| id | 客户端id |
***
添加客户端
```
POST /client/add/
```
| 参数 | 含义 |
| --- | --- |
| remark | 备注 |
| u | basic权限认证用户名 |
| p | basic权限认证密码 |
| limit | 条数(分页显示的条数) |
| vkey | 客户端验证密钥 |
| config\_conn\_allow | 是否允许客户端以配置文件模式连接 1允许 0不允许 |
| compress | 压缩1允许 0不允许 |
| crypt | 是否加密(1或者0)1允许 0不允许 |
| rate\_limit | 带宽限制 单位KB/S 空则为不限制 |
| flow\_limit | 流量限制 单位M 空则为不限制 |
| max\_conn | 客户端最大连接数量 空则为不限制 |
| max\_tunnel | 客户端最大隧道数量 空则为不限制 |
***
修改客户端
```
POST /client/edit/
```
| 参数 | 含义 |
| --- | --- |
| remark | 备注 |
| u | basic权限认证用户名 |
| p | basic权限认证密码 |
| limit | 条数(分页显示的条数) |
| vkey | 客户端验证密钥 |
| config\_conn\_allow | 是否允许客户端以配置文件模式连接 1允许 0不允许 |
| compress | 压缩1允许 0不允许 |
| crypt | 是否加密(1或者0)1允许 0不允许 |
| rate\_limit | 带宽限制 单位KB/S 空则为不限制 |
| flow\_limit | 流量限制 单位M 空则为不限制 |
| max\_conn | 客户端最大连接数量 空则为不限制 |
| max\_tunnel | 客户端最大隧道数量 空则为不限制 |
| id | 要修改的客户端id |
***
删除客户端
```
POST /client/del/
```
| 参数 | 含义 |
| --- | --- |
| id | 要删除的客户端id |
***
获取域名解析列表
```
POST /index/hostlist/
```
| 参数 | 含义 |
| --- | --- |
| search | 搜索(可以搜域名/备注什么的) |
| offset | 分页(第几页) |
| limit | 条数(分页显示的条数) |
***
添加域名解析
```
POST /index/addhost/
```
| 参数 | 含义 |
| --- | --- |
| remark | 备注 |
| host | 域名 |
| scheme | 协议类型(三种 all http https) |
| location | url路由 空则为不限制 |
| client\_id | 客户端id |
| target | 内网目标(ip:端口) |
| header | request header 请求头 |
| hostchange | request host 请求主机 |
***
修改域名解析
```
POST /index/edithost/
```
| 参数 | 含义 |
| --- | --- |
| remark | 备注 |
| host | 域名 |
| scheme | 协议类型(三种 all http https) |
| location | url路由 空则为不限制 |
| client\_id | 客户端id |
| target | 内网目标(ip:端口) |
| header | request header 请求头 |
| hostchange | request host 请求主机 |
| id | 需要修改的域名解析id |
***
删除域名解析
```
POST /index/delhost/
```
| 参数 | 含义 |
| --- | --- |
| id | 需要删除的域名解析id |
***
获取单条隧道信息
```
POST /index/getonetunnel/
```
| 参数 | 含义 |
| --- | --- |
| id | 隧道的id |
***
获取隧道列表
```
POST /index/gettunnel/
```
| 参数 | 含义 |
| --- | --- |
| client\_id | 穿透隧道的客户端id |
| type | 类型tcp udp httpProx socks5 secret p2p |
| search | 搜索 |
| offset | 分页(第几页) |
| limit | 条数(分页显示的条数) |
***
添加隧道
```
POST /index/add/
```
| 参数 | 含义 |
| --- | --- |
| type | 类型tcp udp httpProx socks5 secret p2p |
| remark | 备注 |
| port | 服务端端口 |
| target | 目标(ip:端口) |
| client\_id | 客户端id |
***
修改隧道
```
POST /index/edit/
```
| 参数 | 含义 |
| --- | --- |
| type | 类型tcp udp httpProx socks5 secret p2p |
| remark | 备注 |
| port | 服务端端口 |
| target | 目标(ip:端口) |
| client\_id | 客户端id |
| id | 隧道id |
***
删除隧道
```
POST /index/del/
```
| 参数 | 含义 |
| --- | --- |
| id | 隧道id |
***
隧道停止工作
```
POST /index/stop/
```
| 参数 | 含义 |
| --- | --- |
| id | 隧道id |
***
隧道开始工作
```
POST /index/start/
```
| 参数 | 含义 |
| --- | --- |
| id | 隧道id |
Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 132 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

+10
View File
@@ -21,6 +21,9 @@ const (
RES_MSG = "msg0"
RES_CLOSE = "clse"
NEW_UDP_CONN = "udpc" //p2p udp conn
// REPORT_LOCAL_IP: server requests client local/private IPs on WORK_MAIN.
// New clients reply with WriteLenContent; old clients ignore the flag (server times out).
REPORT_LOCAL_IP = "rlip"
NEW_TASK = "task"
NEW_CONF = "conf"
NEW_HOST = "host"
@@ -32,6 +35,13 @@ Content-Type: text/plain; charset=utf-8
WWW-Authenticate: Basic realm="easyProxy"
401 Unauthorized`
// ProxyAuthRequiredBytes is the challenge for HTTP forward proxy Basic auth (RFC 7235).
// Clients expect 407 + Proxy-Authenticate, not 401 + WWW-Authenticate.
ProxyAuthRequiredBytes = "HTTP/1.1 407 Proxy Authentication Required\r\n" +
"Content-Type: text/plain; charset=utf-8\r\n" +
"Proxy-Authenticate: Basic realm=\"nps\"\r\n" +
"\r\n" +
"407 Proxy Authentication Required"
ConnectionFailBytes = `HTTP/1.1 404 Not Found
`
+93
View File
@@ -482,6 +482,99 @@ func GetIntranetIp() (error, string) {
return errors.New("get intranet ip error"), ""
}
// isUsefulPrivateIPv4 reports whether ip is a usable LAN IPv4 for display:
// RFC1918 private only — excludes loopback, link-local (169.254.0.0/16), public, etc.
func isUsefulPrivateIPv4(ip net.IP) bool {
if ip == nil {
return false
}
v4 := ip.To4()
if v4 == nil {
return false
}
if v4.IsLoopback() || v4.IsLinkLocalUnicast() || v4.IsLinkLocalMulticast() || v4.IsUnspecified() || v4.IsMulticast() {
return false
}
// RFC1918 only (not 169.254, not public)
return v4.IsPrivate()
}
func ipFromAddr(addr net.Addr) net.IP {
if addr == nil {
return nil
}
switch a := addr.(type) {
case *net.TCPAddr:
return a.IP
case *net.UDPAddr:
return a.IP
default:
return net.ParseIP(GetIpByAddr(addr.String()))
}
}
// GetLocalIPs returns private (RFC1918) IPv4 addresses useful for identifying the npc host.
// Prefers the local IP of conn (path toward nps). Falls back to interface scan.
// Link-local 169.254.0.0/16, loopback and public addresses are excluded.
func GetLocalIPs(conn net.Conn) string {
seen := make(map[string]struct{})
ips := make([]string, 0, 4)
add := func(ip net.IP) {
if !isUsefulPrivateIPv4(ip) {
return
}
s := ip.To4().String()
if _, ok := seen[s]; ok {
return
}
seen[s] = struct{}{}
ips = append(ips, s)
}
// 1) Local endpoint of the bridge connection — usually the real LAN IP used to reach nps.
if conn != nil {
add(ipFromAddr(conn.LocalAddr()))
// One correct path IP is enough for most hosts (avoids docker/vm junk alongside).
if len(ips) > 0 {
return ips[0]
}
}
// 2) Outbound interface toward the internet (same idea as GetLocalUdpAddr).
if tmp, err := net.Dial("udp", "114.114.114.114:53"); err == nil {
add(ipFromAddr(tmp.LocalAddr()))
_ = tmp.Close()
if len(ips) > 0 {
return ips[0]
}
}
// 3) Fallback: all up interfaces with private IPv4.
ifaces, err := net.Interfaces()
if err == nil {
for _, iface := range ifaces {
if iface.Flags&net.FlagUp == 0 || iface.Flags&net.FlagLoopback != 0 {
continue
}
addrs, err := iface.Addrs()
if err != nil {
continue
}
for _, address := range addrs {
if ipnet, ok := address.(*net.IPNet); ok {
add(ipnet.IP)
}
}
}
}
if len(ips) > 1 {
sort.Strings(ips)
}
return strings.Join(ips, ",")
}
func IsPublicIP(IP net.IP) bool {
if IP.IsLoopback() || IP.IsLinkLocalMulticast() || IP.IsLinkLocalUnicast() {
return false
+7 -5
View File
@@ -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
@@ -374,7 +376,7 @@ func SetUdpSession(sess *kcp.UDPSession) {
//conn1 mux conn
func CopyWaitGroup(conn1, conn2 net.Conn, crypt bool, snappy bool, rate *rate.Rate,
flow *file.Flow, isServer bool, rb []byte, task *file.Tunnel) {
flow *file.Flow, isServer bool, rb []byte, task *file.Tunnel, host *file.Host) {
//var in, out int64
//var wg sync.WaitGroup
connHandle := GetConn(conn1, crypt, snappy, rate, isServer)
@@ -397,7 +399,7 @@ func CopyWaitGroup(conn1, conn2 net.Conn, crypt bool, snappy bool, rate *rate.Ra
//}
wg := new(sync.WaitGroup)
wg.Add(1)
err := goroutine.CopyConnsPool.Invoke(goroutine.NewConns(connHandle, conn2, flow, wg, task))
err := goroutine.CopyConnsPool.Invoke(goroutine.NewConns(connHandle, conn2, flow, wg, task, host))
wg.Wait()
if err != nil {
logs.Error(err)
+77
View File
@@ -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)
}
}
+75 -52
View File
@@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"net/http"
"sort"
"strings"
"sync"
@@ -36,43 +35,42 @@ func GetDb() *DbUtils {
return Db
}
func GetMapKeys(m sync.Map, isSort bool, sortKey, order string) (keys []int) {
if sortKey != "" && isSort {
return sortClientByKey(m, sortKey, order)
}
m.Range(func(key, value interface{}) bool {
keys = append(keys, key.(int))
func (s *DbUtils) GetClientList(start, length int, search, sortField, order string, clientId int) ([]*Client, int) {
all := make([]*Client, 0)
s.JsonDb.Clients.Range(func(key, value interface{}) bool {
v := value.(*Client)
if v.NoDisplay {
return true
}
if clientId != 0 && clientId != v.Id {
return true
}
if search != "" && !(v.Id == common.GetIntNoErrByStr(search) || strings.Contains(v.VerifyKey, search) || strings.Contains(v.Remark, search) || strings.Contains(v.Addr, search) || strings.Contains(v.LocalAddr, search)) {
return true
}
all = append(all, v)
return true
})
sort.Ints(keys)
return
SortClients(all, sortField, order)
return paginateClients(all, start, length)
}
func (s *DbUtils) GetClientList(start, length int, search, sort, order string, clientId int) ([]*Client, int) {
list := make([]*Client, 0)
var cnt int
keys := GetMapKeys(s.JsonDb.Clients, true, sort, order)
for _, key := range keys {
if value, ok := s.JsonDb.Clients.Load(key); ok {
v := value.(*Client)
if v.NoDisplay {
continue
}
if clientId != 0 && clientId != v.Id {
continue
}
if search != "" && !(v.Id == common.GetIntNoErrByStr(search) || strings.Contains(v.VerifyKey, search) || strings.Contains(v.Remark, search)) {
continue
}
cnt++
if start--; start < 0 {
if length--; length >= 0 {
list = append(list, v)
}
}
}
func paginateClients(all []*Client, start, length int) ([]*Client, int) {
cnt := len(all)
if start < 0 {
start = 0
}
return list, cnt
if length <= 0 {
return []*Client{}, cnt
}
if start >= cnt {
return []*Client{}, cnt
}
end := start + length
if end > cnt {
end = cnt
}
return all[start:end], cnt
}
func (s *DbUtils) GetIdByVerifyKey(vKey string, addr string) (id int, err error) {
@@ -96,7 +94,7 @@ func (s *DbUtils) GetIdByVerifyKey(vKey string, addr string) (id int, err error)
func (s *DbUtils) NewTask(t *Tunnel) (err error) {
s.JsonDb.Tasks.Range(func(key, value interface{}) bool {
v := value.(*Tunnel)
if (v.Mode == "secret" || v.Mode == "p2p") && v.Password == t.Password {
if (v.Mode == "secret" || v.Mode == "p2p") && v.Password == t.Password && t.Password != "" {
err = errors.New(fmt.Sprintf("secret mode keys %s must be unique", t.Password))
return false
}
@@ -182,27 +180,45 @@ func (s *DbUtils) NewHost(t *Host) error {
return nil
}
func (s *DbUtils) GetHost(start, length int, id int, search string) ([]*Host, int) {
list := make([]*Host, 0)
var cnt int
keys := GetMapKeys(s.JsonDb.Hosts, false, "", "")
for _, key := range keys {
if value, ok := s.JsonDb.Hosts.Load(key); ok {
v := value.(*Host)
if search != "" && !(v.Id == common.GetIntNoErrByStr(search) || strings.Contains(v.Host, search) || strings.Contains(v.Remark, search) || strings.Contains(v.Client.VerifyKey, search)) {
continue
func (s *DbUtils) GetHost(start, length int, id int, search, sortField, order string) ([]*Host, int) {
all := make([]*Host, 0)
s.JsonDb.Hosts.Range(func(key, value interface{}) bool {
v := value.(*Host)
if search != "" {
vkey := ""
if v.Client != nil {
vkey = v.Client.VerifyKey
}
if id == 0 || v.Client.Id == id {
cnt++
if start--; start < 0 {
if length--; length >= 0 {
list = append(list, v)
}
}
if !(v.Id == common.GetIntNoErrByStr(search) || strings.Contains(v.Host, search) || strings.Contains(v.Remark, search) || strings.Contains(vkey, search)) {
return true
}
}
if id != 0 && (v.Client == nil || v.Client.Id != id) {
return true
}
all = append(all, v)
return true
})
SortHosts(all, sortField, order)
return paginateHosts(all, start, length)
}
func paginateHosts(all []*Host, start, length int) ([]*Host, int) {
cnt := len(all)
if start < 0 {
start = 0
}
return list, cnt
if length <= 0 {
return []*Host{}, cnt
}
if start >= cnt {
return []*Host{}, cnt
}
end := start + length
if end > cnt {
end = cnt
}
return all[start:end], cnt
}
func (s *DbUtils) DelClient(id int) error {
@@ -273,7 +289,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
@@ -377,6 +393,13 @@ func (s *DbUtils) GetInfoByHost(host string, r *http.Request) (h *Host, err erro
if v.Location == "" {
v.Location = "/"
}
// "*" means SNI-based HTTPS lookup where actual URI is unknown, skip location filter
if r.RequestURI == "*" {
if h == nil || (len(v.Location) > len(h.Location)) {
h = v
}
continue
}
if strings.Index(r.RequestURI, v.Location) == 0 {
if h == nil || (len(v.Location) > len(h.Location)) {
h = v
+31 -11
View File
@@ -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)
@@ -184,8 +187,14 @@ func storeSyncMapToFile(m sync.Map, filePath string) {
file, err := os.Create(filePath + ".tmp")
// first create a temporary file to store
if err != nil {
panic(err)
logs.Error("store to file: create tmp file error: %v", err)
return
}
defer func() {
file.Close()
os.Remove(filePath + ".tmp")
}()
var writeErr bool
m.Range(func(key, value interface{}) bool {
var b []byte
var err error
@@ -208,9 +217,6 @@ func storeSyncMapToFile(m sync.Map, filePath string) {
return true
}
b, err = json.Marshal(obj)
//case *Glob:
// obj := value.(*Glob)
// b, err = json.Marshal(obj)
default:
return true
}
@@ -219,40 +225,54 @@ func storeSyncMapToFile(m sync.Map, filePath string) {
}
_, err = file.Write(b)
if err != nil {
panic(err)
logs.Error("store to file: write error: %v", err)
writeErr = true
return false
}
_, err = file.Write([]byte("\n" + common.CONN_DATA_SEQ))
if err != nil {
panic(err)
logs.Error("store to file: write separator error: %v", err)
writeErr = true
return false
}
return true
})
if writeErr {
return
}
_ = file.Sync()
_ = file.Close()
// must close file first, then rename it
err = os.Rename(filePath+".tmp", filePath)
if err != nil {
logs.Error(err, "store to file err, data will lost")
}
// replace the file, maybe provides atomic operation
}
func storeGlobalToFile(m *Glob, filePath string) {
file, err := os.Create(filePath + ".tmp")
// first create a temporary file to store
if err != nil {
panic(err)
logs.Error("store global to file: create tmp file error: %v", err)
return
}
defer func() {
file.Close()
os.Remove(filePath + ".tmp")
}()
var b []byte
b, err = json.Marshal(m)
if err != nil {
logs.Error("store global to file: marshal error: %v", err)
return
}
_, err = file.Write(b)
if err != nil {
panic(err)
logs.Error("store global to file: write error: %v", err)
return
}
_ = file.Sync()
_ = file.Close()
// must close file first, then rename it
err = os.Rename(filePath+".tmp", filePath)
if err != nil {
logs.Error(err, "store to file err, data will lost")

Some files were not shown because too many files have changed in this diff Show More