Compare commits

...
66 Commits
Author SHA1 Message Date
yisier a3a801370b v0.26.27 2025-11-01 04:22:36 +08:00
yisier bb9b4501c2 v0.26.27 2025-11-01 04:21:57 +08:00
yisier 492c259568 0.26.27 2025-11-01 03:55:18 +08:00
yisier c5efa76623 Merge remote-tracking branch 'origin/master' 2025-09-09 16:47:19 -06:00
yisier b44cd17324 0.26.26 2025-09-09 16:44:04 -06:00
yisier acf7f297f0 Update README.md 2025-09-05 17:00:26 -06:00
yisier fdb24b115b 修复
- windows注册服务 使用tls无法连接
- 域名解析自动HTTPS逻辑bug
2025-08-15 16:59:42 -06:00
yisier 1cd77f877d Update README.md 2025-06-09 15:37:08 +08:00
yisier f3ad499273 readme 2025-05-28 14:36:14 +08:00
yisier 8fca98bdf8 Update README.md 2025-05-28 14:35:40 +08:00
yisier 7123027287 0.26.25 2025-05-28 14:24:52 +08:00
yisier 90a85b1b88 Update README.md 2025-05-09 13:16:53 +08:00
yisier 745b056be9 Update README.md 2025-05-09 12:26:30 +08:00
yisier 831fe8e32e 0.26.24 2025-04-17 17:37:10 +08:00
yisier 50e2da3fcb v0.26.24 2025-04-16 16:45:39 +08:00
yisier 7db25b9c3a v0.26.24 2025-04-16 16:44:09 +08:00
yisier be3358b744 v0.26.24 2025-04-16 16:43:29 +08:00
yisier 965fa40429 Docker 2025-04-11 23:24:29 +08:00
yisier 944181c79b Docker 2025-04-11 23:19:00 +08:00
yisier 6332cfbf9b Docker 2025-04-11 23:15:00 +08:00
yisier 7cd1a0ade9 android 2025-04-11 23:12:27 +08:00
yisier 57ca48f127 Merge remote-tracking branch 'origin/master'
# Conflicts:
#	.github/workflows/pkg.yml
2025-04-11 23:07:27 +08:00
yisier 08e1811dc8 test 2025-04-11 23:07:06 +08:00
yisier d02c2b70a4 Update pkg.yml 2025-04-11 22:59:01 +08:00
yisier a7d23e6ff3 test 2025-04-11 22:46:02 +08:00
yisier db954f8071 v0.26.23 2025-04-11 22:32:21 +08:00
yisier ce08f966d2 Merge pull request #244 from huanglei288766/master
FIX too many goroutine
2025-04-11 22:11:38 +08:00
huanglei 87cdc8634f MOD setMaxThreads 2025-03-07 18:30:32 +08:00
huanglei 3068d972ae FIX too many goroutine 2025-02-21 17:21:20 +08:00
yisier e2e5c0dd75 0.26.22 2025-01-23 17:38:33 +08:00
yisier ed1a361fd0 0.26.22 2025-01-23 17:31:55 +08:00
yisier 23c26f13c0 readme 2025-01-07 14:04:18 +08:00
yisier fdb674282c readme 2025-01-07 14:02:54 +08:00
yisier 78a733606a 域名解析和隧道列表增加访问地址,可以点击隧道链接,直接网页打开 2025-01-07 13:33:10 +08:00
yisier 36182e4b60 客户端更新 2025-01-07 11:58:18 +08:00
yisier 65528fbcf2 bt 2024-11-21 17:23:20 +08:00
yisier 9b0b5b00c1 bt 2024-11-21 17:15:59 +08:00
yisier 899b512ddf bt 2024-11-14 16:52:47 +08:00
yisier bf622b87ba 隧道列表排序 2024-11-07 15:40:37 +08:00
yisier 700332ef0d Merge pull request #177 from axfinn/fix/nat_0614
fix: 修复nat参数指定stun服务错误问题
2024-11-07 14:59:16 +08:00
yisier 02d8c6b561 - 在 Client 结构中添加 CreateTime 字段,用于记录客户端创建时间
- 在添加客户端时设置创建时间
- 在客户端列表页面显示创建时间- 修复了客户端限速单位不统一的问题
- 增加了从下拉菜单选择客户端的功能
- 优化了编辑客户端后不会刷新页面的问题
-修复了隧道数量限制无法统计域名映射的问题
2024-11-07 14:49:49 +08:00
yisier f7c04f3271 Update README.md 2024-09-27 22:29:49 +08:00
yisier 257816e793 Update README.md 2024-09-26 15:05:24 +08:00
yisier 00e16e88ff 客户端限速单位不统一 2024-09-03 11:26:43 -04:00
yisier c265f0ea2a Update README.md 2024-08-31 18:14:26 -04:00
axiu 4085181585 fix: 修复nat参数指定stun服务错误问题 2024-06-14 10:42:39 +08:00
yisier 55ee7acd97 配置文件多了空格 2024-06-04 18:03:02 +08:00
yisier a1894ca898 darwin arm64 2024-06-04 15:46:15 +08:00
yisier 191b21b8cd v0.26.19 2024-06-01 22:25:27 +08:00
yisier c5d96a4105 v0.26.19 2024-06-01 22:09:11 +08:00
yisier 37b4e234ef Update pkg.yml 2024-06-01 21:58:30 +08:00
yisier 955687ba31 Merge remote-tracking branch 'origin/master' into dev 2024-05-28 17:58:26 +08:00
yisier 22018dab14 v0.26.19 2024-05-28 17:56:36 +08:00
yisier 7084d7df85 1.移除版本强校验
2.客户端支持启动多个vkey
2024-03-19 15:43:31 +08:00
yisier 83a5e8eb99 Update README.md 2024-03-18 13:50:02 +08:00
yisier e505eaa72c Merge remote-tracking branch 'origin/master' 2024-03-07 12:00:11 +08:00
yisier d4fdd0843c README.md 2024-03-07 11:59:52 +08:00
yisier eeafa867a5 Update README.md 2024-03-07 11:30:10 +08:00
yisier 352ac408ed Update README.md 2024-03-07 11:29:48 +08:00
yisier 9fedfa1023 Update README.md 2024-02-28 15:43:45 +08:00
yisier c0afe54bc3 Update README.md 2024-02-28 15:43:34 +08:00
yisier 91bcc55fbf tls 独立端口 2024-02-27 16:57:47 +08:00
yisier 783e475872 version 2024-01-31 23:00:34 +08:00
yisier e53df0cede 版本号将继续沿用 0.26.xx 2024-01-31 22:53:30 +08:00
yisier c44a5dade8 http optimize 2024-01-05 21:00:13 +08:00
yisier 19a1e31904 log 2024-01-02 22:57:48 +08:00
71 changed files with 2644 additions and 569 deletions
+27
View File
@@ -0,0 +1,27 @@
name: Android
on:
workflow_dispatch:
release:
types: [published]
branches: [ master ]
jobs:
build_android:
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Build
run: |
chmod +x build.android.sh
docker run --rm -i -w /app -v $(pwd):/app -e ANDROID_HOME=/usr/local/android_sdk -e GOPROXY=direct fyneio/fyne-cross:android-latest /app/build.android.sh
- name: Upload
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: |
android_client.apk
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+1 -1
View File
@@ -22,7 +22,7 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Cache Docker layers
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
+61 -59
View File
@@ -9,65 +9,67 @@ on:
jobs:
build_assets:
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: 1.15
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Get dependencies
run: |
go get -v -t -d ./...
if [ -f Gopkg.toml ]; then
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
dep ensure
fi
- name: Build
run: |
chmod +x build.assets.sh
./build.assets.sh
- name: Upload
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: |
freebsd_386_client.tar.gz
freebsd_386_server.tar.gz
freebsd_amd64_client.tar.gz
freebsd_amd64_server.tar.gz
freebsd_arm_client.tar.gz
freebsd_arm_server.tar.gz
linux_386_client.tar.gz
linux_386_server.tar.gz
linux_amd64_client.tar.gz
linux_amd64_server.tar.gz
linux_arm64_client.tar.gz
linux_arm64_server.tar.gz
linux_arm_v5_client.tar.gz
linux_arm_v6_client.tar.gz
linux_arm_v7_client.tar.gz
linux_arm_v5_server.tar.gz
linux_arm_v6_server.tar.gz
linux_arm_v7_server.tar.gz
linux_mips64le_client.tar.gz
linux_mips64le_server.tar.gz
linux_mips64_client.tar.gz
linux_mips64_server.tar.gz
linux_mipsle_client.tar.gz
linux_mipsle_server.tar.gz
linux_mips_client.tar.gz
linux_mips_server.tar.gz
darwin_amd64_client.tar.gz
darwin_amd64_server.tar.gz
windows_386_client.tar.gz
windows_386_server.tar.gz
windows_amd64_client.tar.gz
windows_amd64_server.tar.gz
npc_sdk.tar.gz
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: 1.22
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Get dependencies
run: |
go get -v -t -d ./...
if [ -f Gopkg.toml ]; then
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
dep ensure
fi
- name: Build
run: |
chmod +x build.assets.sh
./build.assets.sh
- name: Upload
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: |
freebsd_386_client.tar.gz
freebsd_386_server.tar.gz
freebsd_amd64_client.tar.gz
freebsd_amd64_server.tar.gz
freebsd_arm_client.tar.gz
freebsd_arm_server.tar.gz
linux_386_client.tar.gz
linux_386_server.tar.gz
linux_amd64_client.tar.gz
linux_amd64_server.tar.gz
linux_arm64_client.tar.gz
linux_arm64_server.tar.gz
linux_arm_v5_client.tar.gz
linux_arm_v6_client.tar.gz
linux_arm_v7_client.tar.gz
linux_arm_v5_server.tar.gz
linux_arm_v6_server.tar.gz
linux_arm_v7_server.tar.gz
linux_mips64le_client.tar.gz
linux_mips64le_server.tar.gz
linux_mips64_client.tar.gz
linux_mips64_server.tar.gz
linux_mipsle_client.tar.gz
linux_mipsle_server.tar.gz
linux_mips_client.tar.gz
linux_mips_server.tar.gz
darwin_amd64_client.tar.gz
darwin_amd64_server.tar.gz
darwin_arm64_client.tar.gz
darwin_arm64_server.tar.gz
windows_386_client.tar.gz
windows_386_server.tar.gz
windows_amd64_client.tar.gz
windows_amd64_server.tar.gz
npc_sdk.tar.gz
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+1 -1
View File
@@ -1,4 +1,4 @@
FROM golang:1.15 as builder
FROM golang:1.22 as builder
ARG GOPROXY=direct
WORKDIR /go/src/ehang.io/nps
COPY . .
+1 -1
View File
@@ -1,4 +1,4 @@
FROM golang:1.15 as builder
FROM golang:1.22 as builder
ARG GOPROXY=direct
WORKDIR /go/src/ehang.io/nps
COPY . .
+113 -7
View File
@@ -1,24 +1,125 @@
# NPS
[README](https://github.com/ehang-io/nps/blob/master/README.md)|[中文文档](https://github.com/ehang-io/nps/blob/master/README_zh.md)
[新特性文档](https://dqg9t9eulqq.feishu.cn/wiki/FmVVwDcEGiTZxekYJl5ccuFanlg?from=from_copylink)
# 说明
由于nps已经有一年多的时间没有更新了,存留了不少bug和未完善的功能。
由于nps已经停更多年,存留了不少bug和未完善的功能。
此版本基于 nps 0.26.10的基础上二次开发而来。
***DockerHub***: [NPS](https://hub.docker.com/r/yisier1/nps) [NPC](https://hub.docker.com/r/yisier1/npc)
***宝塔面板***:[宝塔面板 Docker](docs/bt.md)
# 交流群
聊天灌水QQ群:619833483
聊天灌水QQ群:619833483(2000人群),770569342
# 捐赠
![image](image/new/payCode.png)
# 免费NPS节点
https://natnps.com/
免费NPS内网穿透节点,长期免费,6M带宽,3条隧道,欢迎来嫖,自行注册账号。
# 特价云服务器
国内BGP,游戏开服,2核 2G 15M上行 25元/月,[专属连接,首月5折](https://www.rainyun.com/MjY0MzY1_)
# 提示
强烈推荐使用无配置文件模式启动客户端(删除掉npc.exe 目录下的`conf`文件夹即可),所有数据应该在服务端保存和配置,而客户端只做连接转发。客户端配置文件对小白极不友好,配置繁琐,容易出错。
0.26.21 版本后的客户端,无需再通过命令行方式启动、安装、卸载客户端,直接双击运行,按照提示输入指令即可完成,非常方便。
# 更新日志
- 2025-11-051 v0.26.27
新增:
- 1.客户端新增【IP白名单】,可通过两种方式添加IP:
- 方式1️⃣:在【客户端】新建/修改页面,配置IP授权密码,不在IP白名单的外网访问将被跳转到 IP 授权页面,输入正确的授权密码,即可完成添加 IP。
- 方式2️⃣:在【客户端】新建/修改页面,直接添加IP到白名单中。
![img.png](image/new/ip.png)
- 2.客户端配置移除【压缩】和【加密】功能,此功能会显著提高内存和CPU占用率,"利大于弊"。
- 3.客户端默认不再提供配置文件,***强烈推荐使用无配置文件模式启动客户端***
- 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)
## 更新日志
- 2024-01-02 v0.27.01
- 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`
@@ -85,3 +186,8 @@
- 2022-09-14:
修改NPS工作目录为当前可执行文件目录(即配置文件和nps可执行文件放在同一目录下,直接执行nps文件即可),去除注册系统服务,启动、停止、升级等命令
# 捐赠
![image](image/new/payCode.png)
+37 -21
View File
@@ -80,26 +80,42 @@ func (s *Bridge) StartTunnel() error {
s.cliProcess(conn.NewConn(c))
})
} else {
listener, err := connection.GetBridgeListener(s.tunnelType)
if err != nil {
logs.Error(err)
os.Exit(0)
return err
}
conn.Accept(listener, func(c net.Conn) {
// tls
if ServerTlsEnable {
s.cliProcess(conn.NewConn(tls.Server(c, &tls.Config{Certificates: []tls.Certificate{crypt.GetCert()}})))
} else {
s.cliProcess(conn.NewConn(c))
go func() {
listener, err := connection.GetBridgeListener(s.tunnelType)
if err != nil {
logs.Error(err)
os.Exit(0)
return
}
})
conn.Accept(listener, func(c net.Conn) {
s.cliProcess(conn.NewConn(c))
})
}()
// tls
if ServerTlsEnable {
go func() {
// 监听TLS 端口
tlsBridgePort := beego.AppConfig.DefaultInt("tls_bridge_port", 8025)
logs.Info("tls server start, the bridge type is %s, the tls bridge port is %d", "tcp", tlsBridgePort)
tlsListener, tlsErr := net.ListenTCP("tcp", &net.TCPAddr{net.ParseIP(beego.AppConfig.String("bridge_ip")), tlsBridgePort, ""})
if tlsErr != nil {
logs.Error(tlsErr)
os.Exit(0)
return
}
conn.Accept(tlsListener, func(c net.Conn) {
s.cliProcess(conn.NewConn(tls.Server(c, &tls.Config{Certificates: []tls.Certificate{crypt.GetCert()}})))
})
}()
}
}
return nil
}
//get health information form client
// get health information form client
func (s *Bridge) GetHealthFromClient(id int, c *conn.Conn) {
for {
if info, status, err := c.GetHealthInfo(); err != nil {
@@ -164,7 +180,7 @@ func (s *Bridge) GetHealthFromClient(id int, c *conn.Conn) {
s.DelClient(id)
}
//验证失败,返回错误验证flag,并且关闭连接
// 验证失败,返回错误验证flag,并且关闭连接
func (s *Bridge) verifyError(c *conn.Conn) {
c.Write([]byte(common.VERIFY_EER))
}
@@ -181,9 +197,9 @@ func (s *Bridge) cliProcess(c *conn.Conn) {
}
//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
//logs.Info("The client %s version does not match", c.Conn.RemoteAddr())
//c.Close()
//return
}
//version get
var vs []byte
@@ -234,7 +250,7 @@ func (s *Bridge) DelClient(id int) {
}
}
//use different
// use different
func (s *Bridge) typeDeal(typeVal string, c *conn.Conn, id int, vs string) {
isPub := file.GetDb().IsPubClient(id)
switch typeVal {
@@ -313,7 +329,7 @@ func (s *Bridge) typeDeal(typeVal string, c *conn.Conn, id int, vs string) {
return
}
//register ip
// register ip
func (s *Bridge) register(c *conn.Conn) {
var hour int32
if err := binary.Read(c, binary.LittleEndian, &hour); err == nil {
@@ -397,7 +413,7 @@ func (s *Bridge) ping() {
}
}
//get config and add task from client config
// get config and add task from client config
func (s *Bridge) getConfig(c *conn.Conn, isPub bool, client *file.Client) {
var fail bool
loop:
+27 -16
View File
@@ -8,75 +8,80 @@ 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 conf/npc.conf conf/multi_account.conf
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 conf/npc.conf conf/multi_account.conf
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 conf/npc.conf conf/multi_account.conf
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 conf/npc.conf conf/multi_account.conf
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 conf/npc.conf conf/multi_account.conf
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 conf/npc.conf conf/multi_account.conf
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 conf/npc.conf conf/multi_account.conf
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 conf/npc.conf conf/multi_account.conf
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 conf/npc.conf conf/multi_account.conf
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 conf/npc.conf conf/multi_account.conf
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 conf/npc.conf conf/multi_account.conf
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 conf/npc.conf conf/multi_account.conf
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 conf/npc.conf conf/multi_account.conf
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 conf/npc.conf conf/multi_account.conf
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 conf/npc.conf conf/multi_account.conf
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 conf/npc.conf conf/multi_account.conf
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
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -w -extldflags -static -extldflags -static" ./cmd/nps/nps.go
@@ -146,6 +151,12 @@ CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags "-s -w -extldflags -sta
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
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
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
+18 -18
View File
@@ -1,5 +1,5 @@
#/bash/sh
export VERSION=0.26.16
export VERSION=0.26.27
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 conf/npc.conf conf/multi_account.conf
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 conf/npc.conf conf/multi_account.conf
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 conf/npc.conf conf/multi_account.conf
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 conf/npc.conf conf/multi_account.conf
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 conf/npc.conf conf/multi_account.conf
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 conf/npc.conf conf/multi_account.conf
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 conf/npc.conf conf/multi_account.conf
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 conf/npc.conf conf/multi_account.conf
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 conf/npc.conf conf/multi_account.conf
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 conf/npc.conf conf/multi_account.conf
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 conf/npc.conf conf/multi_account.conf
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 conf/npc.conf conf/multi_account.conf
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 conf/npc.conf conf/multi_account.conf
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 conf/npc.conf conf/multi_account.conf
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 conf/npc.conf conf/multi_account.conf
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 conf/npc.conf conf/multi_account.conf
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 conf/npc.conf conf/multi_account.conf
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
+46 -4
View File
@@ -4,6 +4,7 @@ import (
"bufio"
"bytes"
"ehang.io/nps/lib/nps_mux"
"github.com/pires/go-proxyproto"
"net"
"net/http"
"strconv"
@@ -34,7 +35,7 @@ type TRPClient struct {
once sync.Once
}
//new client
// new client
func NewRPClient(svraddr string, vKey string, bridgeConnType string, proxyUrl string, cnf *config.Config, disconnectTime int) *TRPClient {
return &TRPClient{
svrAddr: svraddr,
@@ -51,7 +52,7 @@ func NewRPClient(svraddr string, vKey string, bridgeConnType string, proxyUrl st
var NowStatus int
var CloseClient bool
//start
// start
func (s *TRPClient) Start() {
CloseClient = false
retry:
@@ -85,7 +86,7 @@ retry:
s.handleMain()
}
//handle main connection
// handle main connection
func (s *TRPClient) handleMain() {
for {
flags, err := s.signal.ReadFlag()
@@ -152,7 +153,7 @@ func (s *TRPClient) newUdpConn(localAddr, rAddr string, md5Password string) {
}
}
//pmux tunnel
// pmux tunnel
func (s *TRPClient) newChan() {
tunnel, err := NewConn(s.bridgeConnType, s.vKey, s.svrAddr, common.WORK_CHAN, s.proxyUrl)
if err != nil {
@@ -219,6 +220,47 @@ func (s *TRPClient) handleChan(src net.Conn) {
src.Close()
} else {
logs.Trace("new %s connection with the goal of %s, remote address:%s", lk.ConnType, lk.Host, lk.RemoteAddr)
if lk.ProtoVersion == "V1" || lk.ProtoVersion == "V2" {
var addr = targetConn.RemoteAddr()
if lk.RemoteAddr != "" {
s := strings.Split(lk.RemoteAddr, ":")[1]
port, _ := strconv.Atoi(s)
addr = &net.TCPAddr{
IP: net.ParseIP(strings.Split(lk.RemoteAddr, ":")[0]),
Port: port,
}
}
var version byte
if lk.ProtoVersion == "V1" {
version = 1
} else if lk.ProtoVersion == "V2" {
version = 2
}
transportProtocol := proxyproto.TCPv4
if strings.Contains(addr.String(), ".") {
transportProtocol = proxyproto.TCPv4
} else {
transportProtocol = proxyproto.TCPv6
}
header := &proxyproto.Header{
Command: proxyproto.PROXY,
SourceAddr: addr,
DestinationAddr: targetConn.RemoteAddr(),
Version: version,
TransportProtocol: transportProtocol,
}
_, err2 := header.WriteTo(targetConn)
if err2 != nil {
logs.Error(err2)
}
}
conn.CopyWaitGroup(src, targetConn, lk.Crypt, lk.Compress, nil, nil, false, nil, nil)
}
}
+22 -4
View File
@@ -108,6 +108,7 @@ func StartFromFile(path string) {
logs.Info("Loading configuration file %s successfully", path)
SetTlsEnable(cnf.CommonConfig.TlsEnable)
logs.Info("the version of client is %s, the core version of client is %s,tls enable is %t", version.VERSION, version.GetVersion(), GetTlsEnable())
re:
if first || cnf.CommonConfig.AutoReconnection {
if !first {
@@ -223,6 +224,23 @@ func NewConn(tp string, vkey string, server string, connType string, proxyUrl st
} else {
connection, err = net.Dial("tcp", server)
}
//header := &proxyproto.Header{
// Version: 1,
// Command: proxyproto.PROXY,
// TransportProtocol: proxyproto.TCPv4,
// SourceAddr: &net.TCPAddr{
// IP: net.ParseIP("10.1.1.1"),
// Port: 1000,
// },
// DestinationAddr: &net.TCPAddr{
// IP: net.ParseIP("20.2.2.2"),
// Port: 2000,
// },
//}
//
//_, err = header.WriteTo(connection)
//_, err = io.WriteString(connection, "HELO")
}
} else {
sess, err = kcp.DialWithOptions(server, nil, 10, 3)
@@ -252,8 +270,8 @@ func NewConn(tp string, vkey string, server string, connType string, proxyUrl st
return nil, err
}
if crypt.Md5(version.GetVersion()) != string(b) {
logs.Error("The client does not match the server version. The current core version of the client is", version.GetVersion())
return nil, err
//logs.Error("The client does not match the server version. The current core version of the client is", version.GetVersion())
//return nil, err
}
if _, err := c.Write([]byte(common.Getverifyval(vkey))); err != nil {
return nil, err
@@ -271,7 +289,7 @@ func NewConn(tp string, vkey string, server string, connType string, proxyUrl st
return c, nil
}
//http proxy connection
// http proxy connection
func NewHttpProxyConn(url *url.URL, remoteAddr string) (net.Conn, error) {
req, err := http.NewRequest("CONNECT", "http://"+remoteAddr, nil)
if err != nil {
@@ -298,7 +316,7 @@ func NewHttpProxyConn(url *url.URL, remoteAddr string) (net.Conn, error) {
return proxyConn, nil
}
//get a basic auth string
// get a basic auth string
func basicAuth(username, password string) string {
auth := username + ":" + password
return base64.StdEncoding.EncodeToString([]byte(auth))
+1 -1
View File
@@ -172,7 +172,7 @@ func handleP2PVisitor(localTcpConn net.Conn, config *config.CommonConfig, l *con
}
logs.Trace("start trying to connect with the server")
//TODO just support compress now because there is not tls file in client packages
link := conn.NewLink(common.CONN_TCP, l.Target, false, config.Client.Cnf.Compress, localTcpConn.LocalAddr().String(), false)
link := conn.NewLink(common.CONN_TCP, l.Target, false, config.Client.Cnf.Compress, localTcpConn.LocalAddr().String(), false, "")
if target, err := p2pNetBridge.SendLinkInfo(0, link, nil); err != nil {
logs.Error(err)
udpConnStatus = false
+324 -18
View File
@@ -1,23 +1,27 @@
package main
import (
"ehang.io/nps/client"
"ehang.io/nps/lib/common"
"ehang.io/nps/lib/config"
"ehang.io/nps/lib/file"
"ehang.io/nps/lib/install"
"ehang.io/nps/lib/version"
"bufio"
"ehang.io/nps/lib/crypt"
"flag"
"fmt"
"github.com/astaxie/beego/logs"
"github.com/ccding/go-stun/stun"
"github.com/kardianos/service"
"os"
"os/exec"
"runtime"
"strings"
"sync"
"time"
"ehang.io/nps/client"
"ehang.io/nps/lib/common"
"ehang.io/nps/lib/config"
"ehang.io/nps/lib/file"
"ehang.io/nps/lib/install"
"ehang.io/nps/lib/version"
"github.com/astaxie/beego/logs"
"github.com/ccding/go-stun/stun"
"github.com/fatih/color"
"github.com/kardianos/service"
)
var (
@@ -116,6 +120,7 @@ func main() {
return
case "nat":
c := stun.NewClient()
flag.CommandLine.Parse(os.Args[2:])
c.SetServerAddr(*stunAddr)
nat, host, err := c.Discover()
if err != nil || host == nil {
@@ -229,20 +234,321 @@ func run() {
if *verifyKey == "" {
*verifyKey, _ = env["NPC_SERVER_VKEY"]
}
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())
if *verifyKey != "" && *serverAddr != "" && *configPath == "" {
client.SetTlsEnable(*tlsEnable)
go func() {
for {
client.NewRPClient(*serverAddr, *verifyKey, *connType, *proxyUrl, nil, *disconnectTime).Start()
logs.Info("Client closed! It will be reconnected in five seconds")
time.Sleep(time.Second * 5)
}
}()
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())
vkeys := strings.Split(*verifyKey, `,`)
for _, key := range vkeys {
key := key
go func() {
for {
logs.Info("start vkey:" + key)
client.NewRPClient(*serverAddr, key, *connType, *proxyUrl, nil, *disconnectTime).Start()
logs.Info("Client closed! It will be reconnected in five seconds")
time.Sleep(time.Second * 5)
}
}()
}
} else {
if *configPath == "" {
*configPath = common.GetConfigPath()
}
go client.StartFromFile(*configPath)
// 判断路径下是否有配置文件
if common.FileExists(*configPath) {
logs.Info("配置文件模式启动")
go client.StartFromFile(*configPath)
} else {
// 无配置文件模式双击运行
printSlogan()
inputCmd()
}
}
}
func printSlogan() {
green := color.New(color.FgGreen).SprintFunc()
// 第一次输入,如果输入 1,2,3,4 则需要输入秘钥,否则
fmt.Printf("%s", green(""))
fmt.Printf("\033[32;0m###########################################################\n")
fmt.Printf("\033[32;0m# \033[31mNPS内网穿透客户端\033[0m #\n")
fmt.Printf("\033[32;0m# #\n")
fmt.Printf("\033[32;0m#\033[32m 地址:\033[31;0mhttps://github.com/yisier/nps\033[0m #\n")
fmt.Printf("\033[32;0m#\033[32m 提示:\033[32;0m1、涉及到系统服务的需要以管理员身份运行\033[0m\033[32;0m #\n")
fmt.Printf("\033[32;0m#\033[32m \033[32;0m2、直接启动或[注册系统服务]需要使用[快捷启动命令]\033[0m\033[32;0m #\n")
fmt.Printf("\033[32;0m#\033[32m \033[32;0m3、其他命令如卸载/启动/停止只需要输入[vkey]\033[0m\033[32;0m #\n")
fmt.Printf("\033[32;0m###########################################################\n")
fmt.Printf("\033[0m") // 重置颜色
fmt.Printf("\n")
fmt.Printf("\u001B[32m输入[1]\u001B[0m - 注册系统服务\n")
fmt.Printf("\u001B[32m输入[2]\u001B[0m - 卸载系统服务\n")
fmt.Printf("---------------------\n")
fmt.Printf("\u001B[32m输入[3]\u001B[0m - 启动系统服务\n")
fmt.Printf("\u001B[32m输入[4]\u001B[0m - 停止系统服务\n")
fmt.Printf("---------------------\n")
fmt.Printf("\u001B[32m输入[0]\u001B[0m - 退出\n")
fmt.Printf("---------------------\n")
fmt.Printf("直接输入[快捷启动命令]则是启动隧道,多个[快捷启动命令]用英文逗号拼接\n")
fmt.Printf("\n")
}
func inputCmd() {
var flag string
fmt.Printf("请输入:")
stdin := bufio.NewReader(os.Stdin)
_, err := fmt.Fscanln(stdin, &flag)
if err != nil {
fmt.Println("输入有误")
} else {
if flag == "0" {
os.Exit(0)
}
flag := strings.Replace(flag, " ", "", -1)
// 如果输入不等于 1,2,3,4,则启动隧道
if flag != "1" && flag != "2" && flag != "3" && flag != "4" {
vkeys := strings.Split(flag, `,`)
var cmdArray []string
for _, key := range vkeys {
startCmd, err := crypt.Base64Decoding(key)
if err != nil {
fmt.Println("快捷启动命令解析失败")
inputCmd()
return
}
cmdArray = append(cmdArray, startCmd)
}
for _, item := range cmdArray {
startNpcServer(item)
}
} else {
systemService(flag)
}
}
}
func startNpcServer(startCmd string) {
var serAddr string
var vkey string
var tls string
array := strings.Fields(startCmd)
serAddr = array[0]
vkey = array[1]
if len(array) > 2 {
tls = array[2]
}
go func() {
for {
if tls == "-tls_enable=true" || len(array) > 2 {
client.SetTlsEnable(true)
logs.Info("start cmd:-server=" + serAddr + " -vkey=" + vkey + " " + tls)
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())
} else {
client.SetTlsEnable(false)
logs.Info("start cmd:-server=" + serAddr + " -vkey=" + vkey)
logs.Info("the version of client is %s, the core version of client is %s", version.VERSION, version.GetVersion())
}
client.NewRPClient(serAddr, vkey, *connType, *proxyUrl, nil, *disconnectTime).Start()
logs.Info("Client closed! It will be reconnected in five seconds")
time.Sleep(time.Second * 5)
}
}()
}
func systemService(flag string) {
if flag == "1" {
fmt.Printf("请输入[快捷启动命令],多个[快捷启动命令]用英文逗号拼接:")
} else {
fmt.Printf("请输入[VKEY],多个[VKEY]用英文逗号拼接:")
}
var vkey string
stdin := bufio.NewReader(os.Stdin)
_, err := fmt.Fscanln(stdin, &vkey)
if err != nil {
fmt.Println("输入错误,请重试")
systemService(flag)
return
} else {
if vkey == "0" {
os.Exit(0)
}
}
vkey = strings.Replace(vkey, " ", "", -1)
vkeys := strings.Split(vkey, `,`)
if flag == "1" {
var cmdArray []string
for _, key := range vkeys {
startCmd, err := crypt.Base64Decoding(key)
if err != nil {
fmt.Println("快捷启动命令解析失败")
systemService(flag)
return
}
cmdArray = append(cmdArray, startCmd)
}
for _, item := range cmdArray {
array := strings.Fields(item)
// tls
if len(array) > 2 {
systemPro(flag, array[0], array[1], true)
} else {
systemPro(flag, array[0], array[1], false)
}
}
} else {
for _, key := range vkeys {
systemPro(flag, "", key, false)
}
}
inputCmd()
return
}
func systemPro(flag string, serAddr string, vkey string, tls bool) {
// init service
prg := &npc{
exit: make(chan struct{}),
}
options := make(service.KeyValue)
svcConfig := &service.Config{
Name: "nps-client-" + vkey,
DisplayName: "nps-client-" + vkey,
Description: "NPS内网穿透客户端,支持tcp、udp流量转发,支持内网http代理,地址:https://github.com/yisier/nps",
Option: options,
}
s, _ := service.New(prg, svcConfig)
switch flag {
case "1":
svcConfig.Arguments = append(svcConfig.Arguments, "-server="+serAddr)
svcConfig.Arguments = append(svcConfig.Arguments, "-vkey="+vkey)
if tls {
svcConfig.Arguments = append(svcConfig.Arguments, "-tls_enable=true")
}
svcConfig.Arguments = append(svcConfig.Arguments, "-debug=false")
*logPath = common.GetNpcLogPath()
if common.IsWindows() {
*logPath = strings.Replace(*logPath, "\\", "\\\\", -1)
}
*logPath = strings.Replace(*logPath, "npc.log", "npc-"+vkey+".log", -1)
svcConfig.Arguments = append(svcConfig.Arguments, "-log_path="+*logPath)
logs.NewLogger()
logs.Reset()
logs.EnableFuncCallDepth(true)
logs.SetLogFuncCallDepth(3)
logs.SetLogger(logs.AdapterFile, `{"level":`+*logLevel+`,"filename":"`+*logPath+`","daily":false,"maxlines":100000,"color":true}`)
install.InstallNpc()
err := service.Control(s, "install")
if err != nil {
fmt.Println("隧道["+vkey+"]安装到系统服务失败", err)
return
} else {
fmt.Println("隧道[" + vkey + "]已经安装到系统")
}
if service.Platform() == "unix-systemv" {
logs.Info("unix-systemv service")
confPath := "/etc/init.d/" + svcConfig.Name
os.Symlink(confPath, "/etc/rc.d/S90"+svcConfig.Name)
os.Symlink(confPath, "/etc/rc.d/K02"+svcConfig.Name)
}
err2 := service.Control(s, "start")
if err2 != nil {
fmt.Println("隧道["+vkey+"]启动服务失败", err2)
} else {
fmt.Println("隧道[" + vkey + "]服务已启动")
}
return
case "2":
// 卸载系统服务
err := service.Control(s, "stop")
if err != nil {
fmt.Println("隧道["+vkey+"]服务停止失败", err)
} else {
fmt.Println("隧道[" + vkey + "]服务已停止")
}
err = service.Control(s, "uninstall")
if err != nil {
fmt.Println("隧道["+vkey+"]服务卸载失败", err)
}
if service.Platform() == "unix-systemv" {
fmt.Println("unix-systemv service")
os.Remove("/etc/rc.d/S90" + svcConfig.Name)
os.Remove("/etc/rc.d/K02" + svcConfig.Name)
}
if err == nil {
fmt.Println("隧道[" + vkey + "]服务已卸载成功")
}
return
case "3":
//启动系统服务
if service.Platform() == "unix-systemv" {
logs.Info("unix-systemv service")
cmd := exec.Command("/etc/init.d/"+svcConfig.Name, "start")
err := cmd.Run()
if err != nil {
logs.Error(err)
}
return
}
err := service.Control(s, "start")
if err != nil {
fmt.Println("隧道["+vkey+"]服务启动失败", err)
} else {
fmt.Println("隧道[" + vkey + "]服务启动成功")
}
return
case "4":
if service.Platform() == "unix-systemv" {
logs.Info("unix-systemv service")
cmd := exec.Command("/etc/init.d/"+svcConfig.Name, "stop")
err := cmd.Run()
if err != nil {
logs.Error(err)
}
return
}
err := service.Control(s, "stop")
if err != nil {
fmt.Println("隧道["+vkey+"]服务停止失败", err)
} else {
fmt.Println("隧道[" + vkey + "]服务停止成功")
}
return
}
}
+211 -9
View File
@@ -1,21 +1,25 @@
package main
import (
"bufio"
"ehang.io/nps/bridge"
"ehang.io/nps/lib/daemon"
"ehang.io/nps/server"
"flag"
"fmt"
"github.com/fatih/color"
"log"
"os"
"os/exec"
"path/filepath"
"runtime"
"runtime/debug"
"strings"
"sync"
"ehang.io/nps/lib/file"
"ehang.io/nps/lib/install"
"ehang.io/nps/lib/version"
"ehang.io/nps/server"
"ehang.io/nps/server/connection"
"ehang.io/nps/server/tool"
"ehang.io/nps/web/routers"
@@ -29,20 +33,30 @@ import (
)
var (
level string
ver = flag.Bool("version", false, "show current version")
confPath = flag.String("conf_path", "", "set current confPath")
level string
ver = flag.Bool("version", false, "show current version")
confPath = flag.String("conf_path", "", "set current confPath")
serverCmd = flag.Bool("server", false, "NPS管理脚本")
npsLogPath = flag.String("log_path", "", "nps log path")
)
func main() {
debug.SetMaxThreads(1000000)
flag.Parse()
// init log
if *ver {
common.PrintVersion()
return
}
if *serverCmd {
printSlogan()
inputCmd()
return
}
var logPath string
// *confPath why get null value ?
for _, v := range os.Args[1:] {
switch v {
@@ -52,6 +66,10 @@ func main() {
if strings.Contains(v, "-conf_path=") {
common.ConfPath = strings.Replace(v, "-conf_path=", "", -1)
}
if strings.Contains(v, "-log_path=") {
logPath = strings.Replace(v, "-log_path=", "", -1)
}
}
if err := beego.LoadAppConfig("ini", filepath.Join(common.GetRunPath(), "conf", "nps.conf")); err != nil {
@@ -65,13 +83,17 @@ func main() {
logs.Reset()
logs.EnableFuncCallDepth(true)
logs.SetLogFuncCallDepth(3)
logPath := beego.AppConfig.String("log_path")
if logPath == "" {
logPath = common.GetLogPath()
}
if common.IsWindows() {
logPath = strings.Replace(logPath, "\\", "\\\\", -1)
logPath := beego.AppConfig.String("log_path")
if logPath == "" {
logPath = common.GetLogPath()
}
if common.IsWindows() {
logPath = strings.Replace(logPath, "\\", "\\\\", -1)
}
}
// init service
options := make(service.KeyValue)
svcConfig := &service.Config{
@@ -183,6 +205,185 @@ func main() {
_ = s.Run()
}
func printSlogan() {
green := color.New(color.FgGreen).SprintFunc()
// 第一次输入,如果输入 1,2,3,4 则需要输入秘钥,否则
fmt.Printf("%s", green(""))
fmt.Printf("\033[32;0m欢迎使用 NPS 管理脚本 \n")
fmt.Printf("\033[0m") // 重置颜色
fmt.Printf("\n")
fmt.Printf("\u001B[32m输入[1]\u001B[0m - 安装 NPS\n")
fmt.Printf("\u001B[32m输入[2]\u001B[0m - 卸载 NPS\n")
fmt.Printf("\u001B[32m输入[3]\u001B[0m - 更新 NPS\n")
fmt.Printf("---------------------\n")
fmt.Printf("\u001B[32m输入[4]\u001B[0m - 查看状态\n")
fmt.Printf("---------------------\n")
fmt.Printf("\u001B[32m输入[5]\u001B[0m - 启动 NPS\n")
fmt.Printf("\u001B[32m输入[6]\u001B[0m - 停止 NPS\n")
fmt.Printf("\u001B[32m输入[7]\u001B[0m - 重启 NPS\n")
fmt.Printf("---------------------\n")
fmt.Printf("\u001B[32m输入[0]\u001B[0m - 退出脚本\n")
fmt.Printf("---------------------\n")
fmt.Printf("\n")
}
func inputCmd() {
var flag string
fmt.Printf("请输入[0-7]:")
stdin := bufio.NewReader(os.Stdin)
_, err := fmt.Fscanln(stdin, &flag)
if err != nil {
fmt.Println("输入有误")
} else {
if flag == "0" {
os.Exit(0)
}
// init service
prg := &nps{
exit: make(chan struct{}),
}
options := make(service.KeyValue)
svcConfig := &service.Config{
Name: "Nps",
DisplayName: "nps内网穿透代理服务器",
Description: "一款轻量级、功能强大的内网穿透代理服务器。支持tcp、udp流量转发,支持内网http代理、内网socks5代理,同时支持snappy压缩、站点保护、加密传输、多路复用、header修改等。支持web图形化管理,集成多用户模式。",
Option: options,
}
s, _ := service.New(prg, svcConfig)
switch flag {
case "1":
// uninstall before
_ = service.Control(s, "stop")
_ = service.Control(s, "uninstall")
binPath := install.InstallNpsToCurrentDir()
beego.LoadAppConfig("ini", filepath.Join(common.GetAppPath(), "conf", "nps.conf"))
logPath := filepath.Join(common.GetAppPath(), "nps.log")
if common.IsWindows() {
logPath = strings.Replace(logPath, "\\", "\\\\", -1)
}
svcConfig.Arguments = append(svcConfig.Arguments, "service")
svcConfig.Arguments = append(svcConfig.Arguments, "-conf_path="+common.GetAppPath())
svcConfig.Arguments = append(svcConfig.Arguments, "-log_path="+logPath)
fmt.Println("日志文件路径为:", logPath)
svcConfig.Executable = binPath
s, err := service.New(prg, svcConfig)
if service.Platform() == "unix-systemv" {
logs.Info("unix-systemv service")
confPath := "/etc/init.d/" + svcConfig.Name
os.Symlink(confPath, "/etc/rc.d/S90"+svcConfig.Name)
os.Symlink(confPath, "/etc/rc.d/K02"+svcConfig.Name)
}
err = service.Control(s, "install")
if err != nil {
logs.Error("Valid actions: %q\n%s", service.ControlAction, err.Error())
} else {
fmt.Println("NPS服务安装成功")
}
err = service.Control(s, "start")
if err != nil {
fmt.Println("启动NPS服务失败", err)
} else {
fmt.Println("NPS服务已启动,管理面板访问地址:127.0.0.1:" + beego.AppConfig.String("web_port"))
}
break
case "2":
// 卸载系统服务
err := service.Control(s, "stop")
if err != nil {
fmt.Println("NPS服务停止失败", err)
} else {
fmt.Println("NPS服务已停止")
}
err = service.Control(s, "uninstall")
if err != nil {
logs.Error("NPS服务卸载失败")
}
if service.Platform() == "unix-systemv" {
logs.Info("unix-systemv service")
os.Remove("/etc/rc.d/S90" + svcConfig.Name)
os.Remove("/etc/rc.d/K02" + svcConfig.Name)
}
if err == nil {
fmt.Println("NPS服务已卸载成功")
}
break
case "3":
install.UpdateNpsNew()
return
case "4":
// 查看状态
var statusMsg = ""
status, err := s.Status()
if err != nil {
statusMsg = "\u001B[31m未运行\u001B[0m"
} else {
if status == 1 {
statusMsg = "\u001B[32m运行中\u001B[0m"
} else {
statusMsg = "\u001B[31m未运行\u001B[0m"
}
}
fmt.Println("NPS服务状态:" + statusMsg)
break
case "5":
// 启动 NPS
err := service.Control(s, "start")
if err != nil {
fmt.Println("NPS服务启动失败", err)
} else {
fmt.Println("NPS服务启动成功")
}
break
case "6":
// 停止 NPS
err := service.Control(s, "stop")
if err != nil {
fmt.Println("NPS服务停止失败", err)
} else {
fmt.Println("NPS服务停止成功")
}
break
case "7":
// 重启 NPS
err := service.Control(s, "restart")
if err != nil {
fmt.Println("NPS服务重启失败", err)
} else {
fmt.Println("NPS服务重启成功")
}
break
}
}
inputCmd()
}
func installNps() {
}
type nps struct {
exit chan struct{}
}
@@ -229,6 +430,7 @@ func run() {
os.Exit(0)
}
logs.Info("日志路径111:" + *npsLogPath)
logs.Info("the config path is:" + common.GetRunPath())
logs.Info("the version of server is %s ,allow client core version to be %s,tls enable is %t", version.VERSION, version.GetVersion(), bridge.ServerTlsEnable)
connection.InitConnectionService()
+1 -1
View File
@@ -1,2 +1,2 @@
{"Cnf":{"U":"","P":"","Compress":false,"Crypt":false},"Id":2,"VerifyKey":"a82kjhdyllqnlruk","Addr":"127.0.0.1","Remark":"","Status":true,"IsConnect":false,"RateLimit":0,"Flow":{"ExportFlow":551,"InletFlow":551,"FlowLimit":0},"Rate":{"NowRate":0},"NoStore":false,"NoDisplay":false,"MaxConn":0,"NowConn":0,"WebUserName":"","WebPassword":"","ConfigConnAllow":true,"MaxTunnelNum":0,"Version":"0.26.12","BlackIpList":[""]}
{"Cnf":{"U":"","P":"","Compress":false,"Crypt":false},"Id":34,"VerifyKey":"a1efa114df","Addr":"127.0.0.1","Remark":"","Status":true,"IsConnect":false,"RateLimit":0,"Flow":{"ExportFlow":0,"InletFlow":0,"FlowLimit":0},"Rate":{"NowRate":0},"NoStore":false,"NoDisplay":false,"MaxConn":0,"NowConn":0,"WebUserName":"","WebPassword":"","ConfigConnAllow":true,"MaxTunnelNum":0,"Version":"0.26.20","BlackIpList":[""],"CreateTime":"2025-01-03 17:07:37","LastOnlineTime":"2025-01-07 11:12:00"}
*#*
-2
View File
@@ -1,2 +0,0 @@
{"Id":1,"Host":"testlocal.com","HeaderChange":"","HostChange":"","Location":"/","Remark":"","Scheme":"all","CertFilePath":"","KeyFilePath":"","NoStore":false,"IsClose":false,"Flow":{"ExportFlow":0,"InletFlow":0,"FlowLimit":0},"Client":{"Cnf":{"U":"","P":"","Compress":false,"Crypt":false},"Id":2,"VerifyKey":"a82kjhdyllqnlruk","Addr":"127.0.0.1","Remark":"","Status":true,"IsConnect":false,"RateLimit":0,"Flow":{"ExportFlow":551,"InletFlow":551,"FlowLimit":0},"Rate":{"NowRate":0},"NoStore":false,"NoDisplay":false,"MaxConn":0,"NowConn":0,"WebUserName":"","WebPassword":"","ConfigConnAllow":true,"MaxTunnelNum":0,"Version":"0.26.12","BlackIpList":[""]},"Target":{"TargetStr":"127.0.0.1:8080","TargetArr":["127.0.0.1:8080"],"LocalProxy":false}}
*#*
+1 -1
View File
@@ -14,7 +14,7 @@ crypt=true
compress=true
#pprof_addr=0.0.0.0:9999
disconnect_timeout=60
tls_enable = true
tls_enable=true
[health_check_test1]
health_check_timeout=1
+3 -2
View File
@@ -84,7 +84,7 @@ http_cache=false
http_cache_length=100
#get origin ip
http_add_origin_header=false
#http_add_origin_header=false
#pprof debug options
#pprof_ip=0.0.0.0
@@ -98,4 +98,5 @@ open_captcha=false
# 是否开启tls
tls_enable=true
tls_enable=true
tls_bridge_port=8025
+42
View File
@@ -0,0 +1,42 @@
# 🐳 宝塔面板 (一键部署)
> 安装宝塔面板,前往宝塔面板官网,选择对应的脚本下载安装,推荐宝塔版本 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)
+44 -11
View File
@@ -1,33 +1,66 @@
module ehang.io/nps
go 1.15
go 1.22
require (
fyne.io/fyne/v2 v2.0.2
github.com/astaxie/beego v1.12.0
github.com/bradfitz/iter v0.0.0-20191230175014-e8f45d346db8 // indirect
github.com/c4milo/unpackit v0.0.0-20170704181138-4ed373e9ef1c
github.com/ccding/go-stun v0.0.0-20180726100737-be486d185f3d
github.com/dsnet/compress v0.0.1 // indirect
github.com/fatih/color v1.18.0
github.com/golang/snappy v0.0.3
github.com/hooklift/assert v0.0.0-20170704181755-9d1defd6d214 // indirect
github.com/google/uuid v1.6.0
github.com/kardianos/service v1.2.0
github.com/panjf2000/ants/v2 v2.4.2
github.com/pires/go-proxyproto v0.8.0
github.com/pkg/errors v0.9.1
github.com/shirou/gopsutil/v3 v3.23.10
github.com/xtaci/kcp-go v5.4.20+incompatible
golang.org/x/net v0.23.0
)
require (
github.com/bradfitz/iter v0.0.0-20191230175014-e8f45d346db8 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dsnet/compress v0.0.1 // indirect
github.com/fredbi/uri v0.0.0-20181227131451-3dcfdacbaaf3 // indirect
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/fyne-io/mobile v0.1.3-0.20210318200029-09e9c4e13a8f // indirect
github.com/go-gl/gl v0.0.0-20190320180904-bf2b1f2f34d7 // indirect
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20210311203641-62640a716d48 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/godbus/dbus/v5 v5.0.3 // indirect
github.com/goki/freetype v0.0.0-20181231101311-fa8a33aabaff // indirect
github.com/hooklift/assert v0.0.0-20170704181755-9d1defd6d214 // indirect
github.com/klauspost/compress v1.4.1 // indirect
github.com/klauspost/cpuid v1.3.1 // indirect
github.com/klauspost/cpuid/v2 v2.0.6 // indirect
github.com/klauspost/pgzip v1.2.1 // indirect
github.com/klauspost/reedsolomon v1.9.12 // indirect
github.com/panjf2000/ants/v2 v2.4.2
github.com/pkg/errors v0.9.1
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644 // indirect
github.com/shirou/gopsutil/v3 v3.21.3
github.com/shoenig/go-m1cpu v0.1.6 // indirect
github.com/srwiley/oksvg v0.0.0-20200311192757-870daf9aa564 // indirect
github.com/srwiley/rasterx v0.0.0-20200120212402-85cb7272f5e9 // indirect
github.com/stretchr/testify v1.8.4 // indirect
github.com/templexxx/cpufeat v0.0.0-20180724012125-cef66df7f161 // indirect
github.com/templexxx/xor v0.0.0-20191217153810-f85b25db303b // indirect
github.com/tjfoc/gmsm v1.4.0 // indirect
github.com/xtaci/kcp-go v5.4.20+incompatible
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
github.com/ulikunitz/xz v0.5.6 // indirect
github.com/xtaci/lossyconn v0.0.0-20190602105132-8df528c0c9ae // indirect
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 // indirect
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4
golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57 // indirect
github.com/yusufpapurcu/wmi v1.2.3 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/image v0.0.0-20200430140353-33d19683fad8 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/text v0.14.0 // indirect
gopkg.in/yaml.v2 v2.2.8 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
replace github.com/astaxie/beego => github.com/exfly/beego v1.12.0-export-init
+56 -25
View File
@@ -5,8 +5,6 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
github.com/Knetic/govaluate v3.0.0+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
github.com/Kodeworks/golang-image-ico v0.0.0-20141118225523-73f0f4cfade9/go.mod h1:7uhhqiBaR4CpN0k9rMjOtjpcfGd6DG2m04zQxKnWQ0I=
github.com/OwnLocal/goes v1.0.0/go.mod h1:8rIFjBGTue3lCU0wplczcUgt9Gxgrkkrw7etMIcn8TM=
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d h1:G0m3OIz70MZUWq3EgK3CesDbo8upS2Vm9/P3FtgI+Jk=
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
github.com/akavel/rsrc v0.8.0/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c=
github.com/beego/goyaml2 v0.0.0-20130207012346-5545475820dd/go.mod h1:1b+Y/CofkYwXMUU0OhQqGvsY2Bvgr4j6jfT699wyZKQ=
github.com/beego/x2j v0.0.0-20131220205130-a0352aadc542/go.mod h1:kSeGC/p1AbBiEp5kat81+DSQrZenVBZXklMLaELspWU=
@@ -40,6 +38,8 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/exfly/beego v1.12.0-export-init h1:VQNYKdXhAwZGUaFmQv8Aj921O3rQJZRIF8xeGrhsjrI=
github.com/exfly/beego v1.12.0-export-init/go.mod h1:fysx+LZNZKnvh4GED/xND7jWtjCR6HzydR2Hh2Im57o=
github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=
github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU=
github.com/fredbi/uri v0.0.0-20181227131451-3dcfdacbaaf3 h1:FDqhDm7pcsLhhWl1QtD8vlzI4mm59llRvNzrFg6/LAA=
github.com/fredbi/uri v0.0.0-20181227131451-3dcfdacbaaf3/go.mod h1:CzM2G82Q9BDUvMTGHnXf/6OExw/Dz2ivDj48nVg7Lg8=
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
@@ -50,8 +50,8 @@ github.com/go-gl/gl v0.0.0-20190320180904-bf2b1f2f34d7 h1:SCYMcCJ89LjRGwEa0tRluN
github.com/go-gl/gl v0.0.0-20190320180904-bf2b1f2f34d7/go.mod h1:482civXOzJJCPzJ4ZOX/pwvXBWSnzD4OKMdH4ClKGbk=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20210311203641-62640a716d48 h1:QrUfZrT8n72FUuiABt4tbu8PwDnOPAbnj3Mql1UhdRI=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20210311203641-62640a716d48/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-ole/go-ole v1.2.4 h1:nNBDSCOigTSiarFpYE9J/KtEA1IOW4CNeqT9TQDqCxI=
github.com/go-ole/go-ole v1.2.4/go.mod h1:XCwSNxSkXRo4vlyPy93sltvi/qJq0jqQhjqQNIwKuxM=
github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
github.com/go-redis/redis v6.14.2+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA=
github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
github.com/godbus/dbus/v5 v5.0.3 h1:ZqHaoEF7TBzh4jzPmqVhE/5A1z9of6orkAe5uHoAeME=
@@ -78,6 +78,12 @@ github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5a
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/hooklift/assert v0.0.0-20170704181755-9d1defd6d214 h1:WgfvpuKg42WVLkxNwzfFraXkTXPK36bMqXvMFN67clI=
github.com/hooklift/assert v0.0.0-20170704181755-9d1defd6d214/go.mod h1:kj6hFWqfwSjFjLnYW5PK1DoxZ4O0uapwHRmd9jhln4E=
github.com/jackmordaunt/icns v0.0.0-20181231085925-4f16af745526/go.mod h1:UQkeMHVoNcyXYq9otUupF7/h/2tmHlhrS2zw7ZVvUqc=
@@ -101,6 +107,13 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lucor/goinfo v0.0.0-20200401173949-526b5363a13a/go.mod h1:ORP3/rB5IsulLEBwQZCJyyV6niqmI7P4EWSmkug+1Ng=
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4=
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-sqlite3 v1.10.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
@@ -108,16 +121,24 @@ github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLA
github.com/panjf2000/ants/v2 v2.4.2 h1:kesjjo8JipN3vNNg1XaiXaeSs6xJweBTgenkBtsrHf8=
github.com/panjf2000/ants/v2 v2.4.2/go.mod h1:f6F0NZVFsGCp5A7QW/Zj/m92atWwOkY0OIhFxRNFr4A=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pires/go-proxyproto v0.8.0 h1:5unRmEAPbHXHuLjDg01CxJWf91cw3lKHc/0xzKpXEe0=
github.com/pires/go-proxyproto v0.8.0/go.mod h1:iknsfgnH8EkjrMeMyvfKByp9TiBZCKZM0jx2xmKqnVY=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c h1:ncq/mPwQF4JjgDlrVEn3C11VoGHZN7m8qihwgMEtzYw=
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644 h1:X+yvsM2yrEktyI+b2qND5gpH8YhURn0k8OCaeRnkINo=
github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644/go.mod h1:nkxAfR/5quYxwPZhyDxgasBMnRtBZd0FCEpawpjMUFg=
github.com/shirou/gopsutil/v3 v3.21.3 h1:wgcdAHZS2H6qy4JFewVTtqfiYxFzCeEJod/mLztdPG8=
github.com/shirou/gopsutil/v3 v3.21.3/go.mod h1:ghfMypLDrFSWN2c9cDYFLHyynQ+QUht0cv/18ZqVczw=
github.com/shirou/gopsutil/v3 v3.23.10 h1:/N42opWlYzegYaVkWejXWJpbzKv2JDy3mrgGzKsh9hM=
github.com/shirou/gopsutil/v3 v3.23.10/go.mod h1:JIE26kpucQi+innVlAUnIEOSBhBUkirr5b44yr55+WE=
github.com/shoenig/go-m1cpu v0.1.6 h1:nxdKQNcEB6vzgA2E2bvzKIYRuNj7XNJ4S/aRSwKzFtM=
github.com/shoenig/go-m1cpu v0.1.6/go.mod h1:1JJMcUBvfNwpq05QDQVAnx3gUHr9IYF7GNg9SUEw2VQ=
github.com/shoenig/test v0.6.4 h1:kVTaSd7WLz5WZ2IaoM0RSzRsUD+m8wRR+5qvntpn4LU=
github.com/shoenig/test v0.6.4/go.mod h1:byHiCGXqrVaflBLAMq/srcZIHynQPQgeyvkvXnjqq0k=
github.com/siddontang/go v0.0.0-20180604090527-bdc77568d726/go.mod h1:3yhqj7WBBfRhbBlzyOC3gUxftwsU0u8gqevxwIHQpMw=
github.com/siddontang/ledisdb v0.0.0-20181029004158-becf5f38d373/go.mod h1:mF1DpOSOUiJRMR+FDqaqu3EBqrybQtrDDszLUZ6oxPg=
github.com/siddontang/rdb v0.0.0-20150307021120-fc89ed2e418d/go.mod h1:AMEsy7v5z92TR1JKMkLLoaOQk++LVnOKL3ScbJ8GNGA=
@@ -129,11 +150,15 @@ github.com/srwiley/rasterx v0.0.0-20200120212402-85cb7272f5e9 h1:m59mIOBO4kfcNCE
github.com/srwiley/rasterx v0.0.0-20200120212402-85cb7272f5e9/go.mod h1:mvWM0+15UqyrFKqdRjY6LuAVJR0HOVhJlEgZ5JWtSWU=
github.com/ssdb/gossdb v0.0.0-20180723034631-88f6b59b84ec/go.mod h1:QBvMkMya+gXctz3kmljlUCu/yB3GZ6oee+dUozsezQE=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/syndtr/goleveldb v0.0.0-20181127023241-353a9fca669c/go.mod h1:Z4AUp2Km+PwemOoO/VB5AOx9XSsIItzFjoJlOSiYmn0=
github.com/templexxx/cpufeat v0.0.0-20180724012125-cef66df7f161 h1:89CEmDvlq/F7SJEOqkIdNDGJXrQIhuIx9D2DBXjavSU=
github.com/templexxx/cpufeat v0.0.0-20180724012125-cef66df7f161/go.mod h1:wM7WEvslTq+iOEAMDLSzhVuOt5BRZ05WirO+b09GHQU=
@@ -141,10 +166,10 @@ github.com/templexxx/xor v0.0.0-20191217153810-f85b25db303b h1:fj5tQ8acgNUr6O8LE
github.com/templexxx/xor v0.0.0-20191217153810-f85b25db303b/go.mod h1:5XA7W9S6mni3h5uvOC75dA3m9CCCaS83lltmc0ukdi4=
github.com/tjfoc/gmsm v1.4.0 h1:8nbaiZG+iVdh+fXVw0DZoZZa7a4TGm3Qab+xdrdzj8s=
github.com/tjfoc/gmsm v1.4.0/go.mod h1:j4INPkHWMrhJb38G+J6W4Tw0AbuN8Thu3PbdVYhVcTE=
github.com/tklauser/go-sysconf v0.3.4 h1:HT8SVixZd3IzLdfs/xlpq0jeSfTX57g1v6wB1EuzV7M=
github.com/tklauser/go-sysconf v0.3.4/go.mod h1:Cl2c8ZRWfHD5IrfHo9VN+FX9kCFjIOyVklgXycLB6ek=
github.com/tklauser/numcpus v0.2.1 h1:ct88eFm+Q7m2ZfXJdan1xYoXKlmwsfP+k88q05KvlZc=
github.com/tklauser/numcpus v0.2.1/go.mod h1:9aU+wOc6WjUIZEwWMP62PL/41d65P+iks1gBkr4QyP8=
github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU=
github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI=
github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk=
github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY=
github.com/ulikunitz/xz v0.5.6 h1:jGHAfXawEGZQ3blwU5wnWKQJvAraT7Ftq9EXjnXYgt8=
github.com/ulikunitz/xz v0.5.6/go.mod h1:2bypXElzHzzJZwzH67Y6wb67pO62Rzfn7BSiF4ABRW8=
github.com/wendal/errors v0.0.0-20130201093226-f66c77a7882b/go.mod h1:Q12BUT7DqIlHRmgv3RskH+UCM/4eqVMgI0EMmlSpAXc=
@@ -153,13 +178,15 @@ github.com/xtaci/kcp-go v5.4.20+incompatible/go.mod h1:bN6vIwHQbfHaHtFpEssmWsN45
github.com/xtaci/lossyconn v0.0.0-20190602105132-8df528c0c9ae h1:J0GxkO96kL4WF+AIT3M4mfUVinOCPgf2uUWYFUzN0sM=
github.com/xtaci/lossyconn v0.0.0-20190602105132-8df528c0c9ae/go.mod h1:gXtu8J62kEgmN++bm9BVICuT/e8yiLI2KFobd/TRFsE=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yusufpapurcu/wmi v1.2.3 h1:E1ctvB7uKFMOJw3fdOW32DwGE9I7t++CRUEMKvFoFiw=
github.com/yusufpapurcu/wmi v1.2.3/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
golang.org/x/crypto v0.0.0-20181127143415-eb0de9b17e85/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20201012173705-84dcc777aaee/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 h1:It14KIkyBFYkHkwZ7k45minvA9aorojkyjGk9KJ5B/w=
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20200430140353-33d19683fad8 h1:6WW6V3x1P/jokJBpRQYUJnMHRP6isStQwCozxnU7XQw=
@@ -178,9 +205,8 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20201010224723-4f7140c49acb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4 h1:4nGaVu0QrbjT/AK2PRLuQfQuh6DJve+pELhqTdAj3x0=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -189,21 +215,25 @@ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200720211630-cb9d2d5c5666/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201015000850-e3ed0017c211/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210217105451-b926d437f341/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57 h1:F5Gozwx4I1xtr/sr/8CFbb57iKi3297KFs0QDbGN60A=
golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
@@ -237,7 +267,8 @@ gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 156 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 119 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 132 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

+3
View File
@@ -34,5 +34,8 @@ WWW-Authenticate: Basic realm="easyProxy"
401 Unauthorized`
ConnectionFailBytes = `HTTP/1.1 404 Not Found
`
Unauthorized = `HTTP/1.1 401 Unauthorized
`
)
+20 -10
View File
@@ -8,10 +8,14 @@ import (
var ConfPath string
//Get the currently selected configuration file directory
//For non-Windows systems, select the /etc/nps as config directory if exist, or select ./
//windows system, select the C:\Program Files\nps as config directory if exist, or select ./
// Get the currently selected configuration file directory
// For non-Windows systems, select the /etc/nps as config directory if exist, or select ./
// windows system, select the C:\Program Files\nps as config directory if exist, or select ./
func GetRunPath() string {
if ConfPath != "" {
return ConfPath
}
var path string
if len(os.Args) == 1 {
if !IsWindows() {
@@ -28,7 +32,7 @@ func GetRunPath() string {
return path
}
//Different systems get different installation paths
// Different systems get different installation paths
func GetInstallPath() string {
var path string
@@ -45,7 +49,7 @@ func GetInstallPath() string {
return path
}
//Get the absolute path to the running directory
// Get the absolute path to the running directory
func GetAppPath() string {
if path, err := filepath.Abs(filepath.Dir(os.Args[0])); err == nil {
return path
@@ -53,7 +57,7 @@ func GetAppPath() string {
return os.Args[0]
}
//Determine whether the current system is a Windows system?
// Determine whether the current system is a Windows system?
func IsWindows() bool {
if runtime.GOOS == "windows" {
return true
@@ -61,7 +65,7 @@ func IsWindows() bool {
return false
}
//interface log file path
// interface log file path
func GetLogPath() string {
var path string
if IsWindows() {
@@ -72,7 +76,13 @@ func GetLogPath() string {
return path
}
//interface npc log file path
func GetLogPathCurrentPath() string {
var path string
path = filepath.Join(GetAppPath(), "nps.log")
return path
}
// interface npc log file path
func GetNpcLogPath() string {
var path string
if IsWindows() {
@@ -83,7 +93,7 @@ func GetNpcLogPath() string {
return path
}
//interface pid file path
// interface pid file path
func GetTmpPath() string {
var path string
if IsWindows() {
@@ -94,7 +104,7 @@ func GetTmpPath() string {
return path
}
//config file path
// config file path
func GetConfigPath() string {
var path string
if IsWindows() {
+55 -32
View File
@@ -7,6 +7,7 @@ import (
"encoding/binary"
"errors"
"fmt"
"github.com/astaxie/beego"
"github.com/astaxie/beego/logs"
"html/template"
"io"
@@ -23,7 +24,7 @@ import (
"ehang.io/nps/lib/crypt"
)
//Get the corresponding IP address through domain name
// Get the corresponding IP address through domain name
func GetHostByName(hostname string) string {
if !DomainCheck(hostname) {
return hostname
@@ -39,7 +40,7 @@ func GetHostByName(hostname string) string {
return ""
}
//Check the legality of domain
// Check the legality of domain
func DomainCheck(domain string) bool {
var match bool
IsLine := "^((http://)|(https://))?([a-zA-Z0-9]([a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])?\\.)+[a-zA-Z]{2,6}(/)"
@@ -51,7 +52,7 @@ func DomainCheck(domain string) bool {
return match
}
//Check if the Request request is validated
// Check if the Request request is validated
func CheckAuth(r *http.Request, user, passwd string) bool {
s := strings.SplitN(r.Header.Get("Authorization"), " ", 2)
if len(s) != 2 {
@@ -73,7 +74,7 @@ func CheckAuth(r *http.Request, user, passwd string) bool {
return pair[0] == user && pair[1] == passwd
}
//get bool by str
// get bool by str
func GetBoolByStr(s string) bool {
switch s {
case "1", "true":
@@ -82,7 +83,7 @@ func GetBoolByStr(s string) bool {
return false
}
//get str by bool
// get str by bool
func GetStrByBool(b bool) string {
if b {
return "1"
@@ -90,19 +91,19 @@ func GetStrByBool(b bool) string {
return "0"
}
//int
// int
func GetIntNoErrByStr(str string) int {
i, _ := strconv.Atoi(strings.TrimSpace(str))
return i
}
//Get verify value
// Get verify value
func Getverifyval(vkey string) string {
return crypt.Md5(vkey)
}
//Change headers and host of request
func ChangeHostAndHeader(r *http.Request, host string, header string, addr string, addOrigin bool) {
// Change headers and host of request
func ChangeHostAndHeader(r *http.Request, host string, header string, addr string) {
if host != "" {
r.Host = host
}
@@ -119,13 +120,17 @@ func ChangeHostAndHeader(r *http.Request, host string, header string, addr strin
if prior, ok := r.Header["X-Forwarded-For"]; ok {
addr = strings.Join(prior, ", ") + ", " + addr
}
addOrigin, _ := beego.AppConfig.Bool("http_add_origin_header")
if addOrigin {
logs.Debug("set X-Forwarded-For X-Real-IP = " + addr)
r.Header.Set("X-Forwarded-For", addr)
r.Header.Set("X-Real-IP", addr)
}
}
//Read file content by file path
// Read file content by file path
func ReadAllFromFile(filePath string) ([]byte, error) {
f, err := os.Open(filePath)
if err != nil {
@@ -145,7 +150,7 @@ func FileExists(name string) bool {
return true
}
//Judge whether the TCP port can open normally
// Judge whether the TCP port can open normally
func TestTcpPort(port int) bool {
l, err := net.ListenTCP("tcp", &net.TCPAddr{net.ParseIP("0.0.0.0"), port, ""})
defer func() {
@@ -159,7 +164,7 @@ func TestTcpPort(port int) bool {
return true
}
//Judge whether the UDP port can open normally
// Judge whether the UDP port can open normally
func TestUdpPort(port int) bool {
l, err := net.ListenUDP("udp", &net.UDPAddr{net.ParseIP("0.0.0.0"), port, ""})
defer func() {
@@ -173,9 +178,9 @@ func TestUdpPort(port int) bool {
return true
}
//Write length and individual byte data
//Length prevents sticking
//# Characters are used to separate data
// Write length and individual byte data
// Length prevents sticking
// # Characters are used to separate data
func BinaryWrite(raw *bytes.Buffer, v ...string) {
b := GetWriteStr(v...)
binary.Write(raw, binary.LittleEndian, int32(len(b)))
@@ -194,7 +199,7 @@ func GetWriteStr(v ...string) []byte {
return buffer.Bytes()
}
//inArray str interface
// inArray str interface
func InStrArr(arr []string, val string) bool {
for _, v := range arr {
if v == val {
@@ -204,7 +209,7 @@ func InStrArr(arr []string, val string) bool {
return false
}
//inArray int interface
// inArray int interface
func InIntArr(arr []int, val int) bool {
for _, v := range arr {
if v == val {
@@ -214,7 +219,7 @@ func InIntArr(arr []int, val int) bool {
return false
}
//format ports str to a int array
// format ports str to a int array
func GetPorts(p string) []int {
var ps []int
arr := strings.Split(p, ",")
@@ -238,7 +243,7 @@ func GetPorts(p string) []int {
return ps
}
//is the string a port
// is the string a port
func IsPort(p string) bool {
pi, err := strconv.Atoi(p)
if err != nil {
@@ -250,7 +255,7 @@ func IsPort(p string) bool {
return true
}
//if the s is just a port,return 127.0.0.1:s
// if the s is just a port,return 127.0.0.1:s
func FormatAddress(s string) string {
if strings.Contains(s, ":") {
return s
@@ -258,13 +263,21 @@ func FormatAddress(s string) string {
return "127.0.0.1:" + s
}
//get address from the complete address
// get address from the complete address
func GetIpByAddr(addr string) string {
arr := strings.Split(addr, ":")
return arr[0]
// 如果是 IPv6 地址,可能的格式为[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:8080或[2001:0db8:85a3:0000:0000:8a2e:0370:7334]
// IPv4 地址,可能的格式为192.168.1.1:80或192.168.1.1
// 截取地址
if strings.Contains(addr, "[") {
addr = strings.Split(addr, "[")[1]
addr = strings.Split(addr, "]")[0]
} else {
addr = strings.Split(addr, ":")[0]
}
return addr
}
//get port from the complete address
// get port from the complete address
func GetPortByAddr(addr string) int {
arr := strings.Split(addr, ":")
if len(arr) < 2 {
@@ -297,6 +310,17 @@ func IsBlackIp(ipPort, vkey string, blackIpList []string) bool {
return false
}
// 判断访问地址是否在白名单内
func IsAuthIp(ipPort, vkey string, authIpList []string) bool {
ip := GetIpByAddr(ipPort)
if in(ip, authIpList) {
return false
}
logs.Error("IP地址[" + ip + "]不在隧道[" + vkey + "]白名单列表内")
return true
}
func CopyBuffer(dst io.Writer, src io.Reader, label ...string) (written int64, err error) {
buf := CopyBuff.Get()
defer CopyBuff.Put(buf)
@@ -327,7 +351,7 @@ func CopyBuffer(dst io.Writer, src io.Reader, label ...string) (written int64, e
return written, err
}
//send this ip forget to get a local udp port
// send this ip forget to get a local udp port
func GetLocalUdpAddr() (net.Conn, error) {
tmpConn, err := net.Dial("udp", "114.114.114.114:53")
if err != nil {
@@ -336,7 +360,7 @@ func GetLocalUdpAddr() (net.Conn, error) {
return tmpConn, tmpConn.Close()
}
//parse template
// parse template
func ParseStr(str string) (string, error) {
tmp := template.New("npc")
var err error
@@ -350,7 +374,7 @@ func ParseStr(str string) (string, error) {
return w.String(), nil
}
//get env
// get env
func GetEnvMap() map[string]string {
m := make(map[string]string)
environ := os.Environ()
@@ -363,7 +387,7 @@ func GetEnvMap() map[string]string {
return m
}
//throw the empty element of the string array
// throw the empty element of the string array
func TrimArr(arr []string) []string {
newArr := make([]string, 0)
for _, v := range arr {
@@ -374,7 +398,6 @@ func TrimArr(arr []string) []string {
return newArr
}
//
func IsArrContains(arr []string, val string) bool {
if arr == nil {
return false
@@ -387,7 +410,7 @@ func IsArrContains(arr []string, val string) bool {
return false
}
//remove value from string array
// remove value from string array
func RemoveArrVal(arr []string, val string) []string {
for k, v := range arr {
if v == val {
@@ -398,7 +421,7 @@ func RemoveArrVal(arr []string, val string) []string {
return arr
}
//convert bytes to num
// convert bytes to num
func BytesToNum(b []byte) int {
var str string
for i := 0; i < len(b); i++ {
@@ -408,7 +431,7 @@ func BytesToNum(b []byte) int {
return int(x)
}
//get the length of the sync map
// get the length of the sync map
func GeSynctMapLen(m sync.Map) int {
var c int
m.Range(func(key, value interface{}) bool {
+17 -15
View File
@@ -15,13 +15,14 @@ func NewSecret(p string, conn *Conn) *Secret {
}
type Link struct {
ConnType string //连接类型
Host string //目标
Crypt bool //加密
Compress bool
LocalProxy bool
RemoteAddr string
Option Options
ConnType string //连接类型
Host string //目标
Crypt bool //加密
Compress bool
LocalProxy bool
RemoteAddr string
ProtoVersion string
Option Options
}
type Option func(*Options)
@@ -32,17 +33,18 @@ type Options struct {
var defaultTimeOut = time.Second * 5
func NewLink(connType string, host string, crypt bool, compress bool, remoteAddr string, localProxy bool, opts ...Option) *Link {
func NewLink(connType string, host string, crypt bool, compress bool, remoteAddr string, localProxy bool, protoVersion string, opts ...Option) *Link {
options := newOptions(opts...)
return &Link{
RemoteAddr: remoteAddr,
ConnType: connType,
Host: host,
Crypt: crypt,
Compress: compress,
LocalProxy: localProxy,
Option: options,
RemoteAddr: remoteAddr,
ConnType: connType,
Host: host,
Crypt: crypt,
Compress: compress,
LocalProxy: localProxy,
ProtoVersion: protoVersion,
Option: options,
}
}
+38 -6
View File
@@ -5,13 +5,16 @@ import (
"crypto/aes"
"crypto/cipher"
"crypto/md5"
"encoding/base64"
"encoding/hex"
"errors"
"github.com/google/uuid"
"math/rand"
"strings"
"time"
)
//en
// en
func AesEncrypt(origData, key []byte) ([]byte, error) {
block, err := aes.NewCipher(key)
if err != nil {
@@ -25,7 +28,7 @@ func AesEncrypt(origData, key []byte) ([]byte, error) {
return crypted, nil
}
//de
// de
func AesDecrypt(crypted, key []byte) ([]byte, error) {
block, err := aes.NewCipher(key)
if err != nil {
@@ -39,14 +42,14 @@ func AesDecrypt(crypted, key []byte) ([]byte, error) {
return origData, err
}
//Completion when the length is insufficient
// Completion when the length is insufficient
func PKCS5Padding(ciphertext []byte, blockSize int) []byte {
padding := blockSize - len(ciphertext)%blockSize
padtext := bytes.Repeat([]byte{byte(padding)}, padding)
return append(ciphertext, padtext...)
}
//Remove excess
// Remove excess
func PKCS5UnPadding(origData []byte) (error, []byte) {
length := len(origData)
unpadding := int(origData[length-1])
@@ -56,14 +59,14 @@ func PKCS5UnPadding(origData []byte) (error, []byte) {
return nil, origData[:(length - unpadding)]
}
//Generate 32-bit MD5 strings
// Generate 32-bit MD5 strings
func Md5(s string) string {
h := md5.New()
h.Write([]byte(s))
return hex.EncodeToString(h.Sum(nil))
}
//Generating Random Verification Key
// Generating Random Verification Key
func GetRandomString(l int) string {
str := "0123456789abcdefghijklmnopqrstuvwxyz"
bytes := []byte(str)
@@ -74,3 +77,32 @@ func GetRandomString(l int) string {
}
return string(result)
}
func GetVkey() string {
// 生成UUID
u, _ := uuid.NewRandom()
// 将UUID转换为字符串
uuidStr := u.String()
uuidStr = strings.ReplaceAll(uuidStr, "-", "")
// 截取前10位
return uuidStr[:10]
}
func Base64Decoding(encodedString string) (string, error) {
decodedBytes, err := base64.StdEncoding.DecodeString(encodedString)
if err != nil {
// 处理解码错误
return "", err
}
// 将解码后的字节数组转换为字符串
decodedString := string(decodedBytes)
// 如果startCmd开头不包含"nps ",则报错
if len(decodedString) < 4 || !(decodedString[0:4] == "nps ") {
return "", errors.New("快捷启动命令错误,请检查")
}
return decodedString[4:], nil
}
+22 -4
View File
@@ -22,7 +22,7 @@ var (
once sync.Once
)
//init csv from file
// init csv from file
func GetDb() *DbUtils {
once.Do(func() {
jsonDb := NewJsonDb(common.GetRunPath())
@@ -128,7 +128,7 @@ func (s *DbUtils) DelTask(id int) error {
return nil
}
//md5 password
// md5 password
func (s *DbUtils) GetTaskByMd5Password(p string) (t *Tunnel) {
s.JsonDb.Tasks.Range(func(key, value interface{}) bool {
if crypt.Md5(value.(*Tunnel).Password) == p {
@@ -218,7 +218,7 @@ func (s *DbUtils) NewClient(c *Client) error {
reset:
if c.VerifyKey == "" || isNotSet {
isNotSet = true
c.VerifyKey = crypt.GetRandomString(16)
c.VerifyKey = crypt.GetVkey()
}
if c.RateLimit == 0 {
c.Rate = rate.NewRate(int64(2 << 23))
@@ -317,6 +317,24 @@ func (s *DbUtils) GetClientIdByVkey(vkey string) (id int, err error) {
return
}
func (s *DbUtils) GetClientByVkey(vkey string) (c *Client, err error) {
var exist bool
s.JsonDb.Clients.Range(func(key, value interface{}) bool {
v := value.(*Client)
if v.VerifyKey == vkey {
exist = true
c = v
return false
}
return true
})
if exist {
return
}
err = errors.New("未找到客户端")
return
}
func (s *DbUtils) GetHostById(id int) (h *Host, err error) {
if v, ok := s.JsonDb.Hosts.Load(id); ok {
h = v.(*Host)
@@ -326,7 +344,7 @@ func (s *DbUtils) GetHostById(id int) (h *Host, err error) {
return
}
//get key by host from x
// get key by host from x
func (s *DbUtils) GetInfoByHost(host string, r *http.Request) (h *Host, err error) {
var hosts []*Host
//Handling Ported Access
+14 -1
View File
@@ -52,7 +52,11 @@ type Client struct {
MaxTunnelNum int
Version string
BlackIpList []string
CreateTime string
LastOnlineTime string
IpWhite bool // 是否启用ip白名单
IpWhitePass string // ip授权密码
IpWhiteList []string // ip白名单
sync.RWMutex
}
@@ -110,6 +114,14 @@ func (s *Client) GetTunnelNum() (num int) {
}
return true
})
GetDb().JsonDb.Hosts.Range(func(key, value interface{}) bool {
v := value.(*Host)
if v.Client.Id == s.Id {
num++
}
return true
})
return
}
@@ -140,9 +152,9 @@ type Tunnel struct {
Remark string
TargetAddr string
NoStore bool
IsHttp bool
LocalPath string
StripPre string
ProtoVersion string
Target *Target
MultiAccount *MultiAccount
Health
@@ -174,6 +186,7 @@ type Host struct {
KeyFilePath string
NoStore bool
IsClose bool
AutoHttps bool // 自动https
Flow *Flow
Client *Client
Target *Target //目标
+13 -16
View File
@@ -3,10 +3,13 @@ package goroutine
import (
"ehang.io/nps/lib/common"
"ehang.io/nps/lib/file"
"fmt"
"github.com/astaxie/beego"
"github.com/astaxie/beego/logs"
"github.com/panjf2000/ants/v2"
"io"
"net"
"path/filepath"
"strings"
"sync"
)
@@ -51,24 +54,18 @@ func CopyBuffer(dst io.Writer, src io.Reader, flow *file.Flow, task *file.Tunnel
}
nr, er := src.Read(buf)
//if len(pr)>0 && pr[0] && nr > 50 {
// logs.Warn(string(buf[:50]))
//}
if task != nil {
task.IsHttp = false
firstLine := string(buf[0:nr])
if len(firstLine) > 3 {
method := firstLine[0:3]
if method != "" && (method == "HTT" || method == "GET" || method == "POS" || method == "HEA" || method == "PUT" || method == "DEL") {
if method != "HTT" {
heads := strings.Split(firstLine, "\r\n")
if len(heads) >= 2 {
logs.Info("HTTP Request method %s, %s, remote address %s, target %s", heads[0], heads[1], remote, task.Target.TargetStr)
}
}
if task.Client.IpWhite && task.Client.IpWhitePass != "" {
if common.IsAuthIp(remote, task.Client.VerifyKey, task.Client.IpWhiteList) {
errorContent, _ := common.ReadAllFromFile(filepath.Join(common.GetRunPath(), "web", "static", "page", "auth.html"))
authHtml := string(errorContent)
authHtml = strings.ReplaceAll(authHtml, "${ip}", common.GetIpByAddr(remote))
authHtml = strings.ReplaceAll(authHtml, "${vkey}", task.Client.VerifyKey)
authHtml = strings.ReplaceAll(authHtml, "${port}", beego.AppConfig.String("web_port"))
task.IsHttp = true
response := fmt.Sprintf("HTTP/1.1 401 Unauthorized\r\nContent-Type: text/html; charset=utf-8\r\nContent-Length: %d\r\nConnection: close\r\n\r\n%s", len(authHtml), authHtml)
dst.Write([]byte(response))
break
}
}
}
+77 -2
View File
@@ -141,6 +141,13 @@ func UpdateNps() {
fmt.Println("Update completed, please restart")
}
func UpdateNpsNew() {
destPath := downloadLatest2("server", filepath.Join(common.GetAppPath(), "temp"))
//复制文件到对应目录
copyStaticFileReplaceNps(destPath, common.GetAppPath())
fmt.Println("更新成功,请重启服务")
}
func UpdateNpc() {
destPath := downloadLatest("client")
//复制文件到对应目录
@@ -190,6 +197,43 @@ func downloadLatest(bin string) string {
return destPath
}
func downloadLatest2(bin string, path string) string {
// get version
data, err := http.Get("https://api.github.com/repos/yisier/nps/releases/latest")
if err != nil {
log.Fatal(err.Error())
}
b, err := ioutil.ReadAll(data.Body)
if err != nil {
log.Fatal(err)
}
rl := new(release)
json.Unmarshal(b, &rl)
version := rl.TagName
fmt.Println("the latest version is", version)
filename := runtime.GOOS + "_" + runtime.GOARCH + "_" + bin + ".tar.gz"
// download latest package
downloadUrl := fmt.Sprintf("https://github.com/yisier/nps/releases/download/%s/%s", version, filename)
fmt.Println("download package from ", downloadUrl)
resp, err := http.Get(downloadUrl)
if err != nil {
log.Fatal(err.Error())
}
destPath, err := unpackit.Unpack(resp.Body, path)
if err != nil {
log.Fatal(err)
}
if bin == "server" {
destPath = strings.Replace(destPath, "/web", "", -1)
destPath = strings.Replace(destPath, `\web`, "", -1)
destPath = strings.Replace(destPath, "/views", "", -1)
destPath = strings.Replace(destPath, `\views`, "", -1)
} else {
destPath = strings.Replace(destPath, `\conf`, "", -1)
destPath = strings.Replace(destPath, "/conf", "", -1)
}
return destPath
}
func copyStaticFile(srcPath, bin string) string {
path := common.GetInstallPath()
if bin == "nps" {
@@ -226,6 +270,22 @@ func copyStaticFile(srcPath, bin string) string {
return binPath
}
func copyStaticFileReplaceNps(srcPath, descPath string) string {
//复制文件到对应目录
os.Rename(filepath.Join(srcPath, "web"), filepath.Join(descPath, "web"))
chMod(filepath.Join(descPath, "web"), 0766)
binPath, _ := filepath.Abs(os.Args[0])
if !common.IsWindows() {
os.Rename(filepath.Join(srcPath, "nps"), filepath.Join(descPath, "nps"))
} else {
os.Rename(filepath.Join(srcPath, "nps.exe"), filepath.Join(descPath, "nps.exe"))
}
chMod(binPath, 0755)
os.RemoveAll(srcPath)
return binPath
}
func InstallNpc() {
path := common.GetInstallPath()
if !common.FileExists(path) {
@@ -266,6 +326,21 @@ now!`)
chMod(common.GetLogPath(), 0777)
return binPath
}
func InstallNpsToCurrentDir() string {
path := common.GetAppPath()
log.Println("install path:" + path)
log.Println("install ok!")
chMod(filepath.Join(path, "nps.log"), 0777)
if !common.IsWindows() {
path = filepath.Join(path, "nps")
} else {
path = filepath.Join(path, "nps.exe")
}
return path
}
func MkidrDirAll(path string, v ...string) {
for _, item := range v {
if err := os.MkdirAll(filepath.Join(path, item), 0755); err != nil {
@@ -310,7 +385,7 @@ func CopyDir(srcPath string, destPath string) error {
return err
}
//生成目录并拷贝文件
// 生成目录并拷贝文件
func copyFile(src, dest string) (w int64, err error) {
srcFile, err := os.Open(src)
if err != nil {
@@ -345,7 +420,7 @@ func copyFile(src, dest string) (w int64, err error) {
return io.Copy(dstFile, srcFile)
}
//检测文件夹路径时候存在
// 检测文件夹路径时候存在
func pathExists(path string) (bool, error) {
_, err := os.Stat(path)
if err == nil {
+2 -2
View File
@@ -1,8 +1,8 @@
package version
const VERSION = "0.27.01"
const VERSION = "0.26.27"
// Compulsory minimum version, Minimum downward compatibility to this version
func GetVersion() string {
return "0.27.0"
return "0.26.0"
}
+14 -8
View File
@@ -23,12 +23,13 @@ type NetBridge interface {
SendLinkInfo(clientId int, link *conn.Link, t *file.Tunnel) (target net.Conn, err error)
}
//BaseServer struct
// BaseServer struct
type BaseServer struct {
id int
bridge NetBridge
task *file.Tunnel
errorContent []byte
errorCode int
sync.Mutex
}
@@ -41,7 +42,7 @@ func NewBaseServer(bridge *bridge.Bridge, task *file.Tunnel) *BaseServer {
}
}
//add the flow
// add the flow
func (s *BaseServer) FlowAdd(in, out int64) {
s.Lock()
defer s.Unlock()
@@ -49,7 +50,7 @@ func (s *BaseServer) FlowAdd(in, out int64) {
s.task.Flow.InletFlow += in
}
//change the flow
// change the flow
func (s *BaseServer) FlowAddHost(host *file.Host, in, out int64) {
s.Lock()
defer s.Unlock()
@@ -57,13 +58,13 @@ func (s *BaseServer) FlowAddHost(host *file.Host, in, out int64) {
host.Flow.InletFlow += in
}
//write fail bytes to the connection
// write fail bytes to the connection
func (s *BaseServer) writeConnFail(c net.Conn) {
c.Write([]byte(common.ConnectionFailBytes))
c.Write(s.errorContent)
}
//auth check
// auth check
func (s *BaseServer) auth(r *http.Request, c *conn.Conn, u, p string) error {
if u != "" && p != "" && !common.CheckAuth(r, u, p) {
c.Write([]byte(common.UnauthorizedBytes))
@@ -73,7 +74,7 @@ func (s *BaseServer) auth(r *http.Request, c *conn.Conn, u, p string) error {
return nil
}
//check flow limit of the client ,and decrease the allow num of client
// check flow limit of the client ,and decrease the allow num of client
func (s *BaseServer) CheckFlowAndConnNum(client *file.Client) error {
if client.Flow.FlowLimit > 0 && (client.Flow.FlowLimit<<20) < (client.Flow.ExportFlow+client.Flow.InletFlow) {
return errors.New("Traffic exceeded")
@@ -93,7 +94,7 @@ func in(target string, str_array []string) bool {
return false
}
//create a new connection and start bytes copying
// create a new connection and start bytes copying
func (s *BaseServer) DealClient(c *conn.Conn, client *file.Client, addr string,
rb []byte, tp string, f func(), flow *file.Flow, localProxy bool, task *file.Tunnel) error {
@@ -109,7 +110,12 @@ func (s *BaseServer) DealClient(c *conn.Conn, client *file.Client, addr string,
return nil
}
link := conn.NewLink(tp, addr, client.Cnf.Crypt, client.Cnf.Compress, c.Conn.RemoteAddr().String(), localProxy)
protoVersion := ""
if task != nil {
protoVersion = task.ProtoVersion
}
link := conn.NewLink(tp, addr, client.Cnf.Crypt, client.Cnf.Compress, c.Conn.RemoteAddr().String(), localProxy, protoVersion)
if target, err := s.bridge.SendLinkInfo(client.Id, link, s.task); err != nil {
logs.Warn("get connection from client id %d error %s", client.Id, err.Error())
c.Close()
+77 -12
View File
@@ -10,6 +10,7 @@ import (
"ehang.io/nps/lib/file"
"ehang.io/nps/lib/goroutine"
"ehang.io/nps/server/connection"
"github.com/astaxie/beego"
"github.com/astaxie/beego/logs"
"io"
"net"
@@ -102,6 +103,20 @@ func (s *httpServer) Close() error {
func (s *httpServer) handleTunneling(w http.ResponseWriter, r *http.Request) {
var host *file.Host
var err error
host, err = file.GetDb().GetInfoByHost(r.Host, r)
if err != nil {
logs.Debug("the url %s %s %s can't be parsed!", r.URL.Scheme, r.Host, r.RequestURI)
return
}
// 自动 http 301 https
if host.AutoHttps && r.TLS == nil {
http.Redirect(w, r, "https://"+r.Host+r.RequestURI, http.StatusMovedPermanently)
return
}
if r.Header.Get("Upgrade") != "" {
rProxy := NewHttpReverseProxy(s)
rProxy.ServeHTTP(w, r)
@@ -147,12 +162,27 @@ reset:
if isReset {
host.Client.AddConn()
}
if host, err = file.GetDb().GetInfoByHost(r.Host, r); err != nil {
logs.Notice("the url %s %s %s can't be parsed!", r.URL.Scheme, r.Host, r.RequestURI)
remoteAddr = strings.TrimSpace(r.Header.Get("X-Forwarded-For"))
if len(remoteAddr) == 0 {
remoteAddr = c.RemoteAddr().String()
}
// 判断访问地址是否在全局黑名单内
if IsGlobalBlackIp(c.RemoteAddr().String()) {
c.Close()
return
}
if host, err = file.GetDb().GetInfoByHost(r.Host, r); err != nil {
logs.Notice("the url %s %s %s can't be parsed!, host %s, url %s, remote address %s", r.URL.Scheme, r.Host, r.RequestURI, r.Host, r.URL.Path, remoteAddr)
c.Close()
return
}
if err := s.CheckFlowAndConnNum(host.Client); err != nil {
logs.Warn("client id %d, host id %d, error %s, when https connection", host.Client.Id, host.Id, err.Error())
c.Close()
return
}
if !isReset {
@@ -167,10 +197,17 @@ reset:
return
}
// 判断访问地址是否在全局黑名单内
if IsGlobalBlackIp(c.RemoteAddr().String()) {
c.Close()
return
if host.Client.IpWhite && host.Client.IpWhitePass != "" {
if common.IsAuthIp(c.RemoteAddr().String(), host.Client.VerifyKey, host.Client.IpWhiteList) {
errorContent, _ := common.ReadAllFromFile(filepath.Join(common.GetRunPath(), "web", "static", "page", "auth.html"))
authHtml := string(errorContent)
authHtml = strings.ReplaceAll(authHtml, "${ip}", common.GetIpByAddr(c.RemoteAddr().String()))
authHtml = strings.ReplaceAll(authHtml, "${vkey}", host.Client.VerifyKey)
authHtml = strings.ReplaceAll(authHtml, "${port}", beego.AppConfig.String("web_port"))
s.errorContent, err = []byte(authHtml), err
s.errorCode = 401
return
}
}
// 判断访问地址是否在黑名单内
@@ -179,7 +216,7 @@ reset:
return
}
lk = conn.NewLink("http", targetAddr, host.Client.Cnf.Crypt, host.Client.Cnf.Compress, r.RemoteAddr, host.Target.LocalProxy)
lk = conn.NewLink("http", targetAddr, host.Client.Cnf.Crypt, host.Client.Cnf.Compress, r.RemoteAddr, host.Target.LocalProxy, "")
if target, err = s.bridge.SendLinkInfo(host.Client.Id, lk, nil); err != nil {
logs.Notice("connect to target %s error %s", lk.Host, err)
return
@@ -237,12 +274,8 @@ reset:
}
//change the host and header and set proxy setting
common.ChangeHostAndHeader(r, host.HostChange, host.HeaderChange, c.Conn.RemoteAddr().String(), s.addOrigin)
common.ChangeHostAndHeader(r, host.HostChange, host.HeaderChange, c.Conn.RemoteAddr().String())
remoteAddr = strings.TrimSpace(r.Header.Get("X-Forwarded-For"))
if len(remoteAddr) == 0 {
remoteAddr = c.RemoteAddr().String()
}
logs.Info("%s request, method %s, host %s, url %s, remote address %s, target %s", r.URL.Scheme, r.Method, r.Host, r.URL.Path, remoteAddr, lk.Host)
//write
@@ -298,3 +331,35 @@ func (s *httpServer) NewServer(port int, scheme string) *http.Server {
TLSNextProto: make(map[string]func(*http.Server, *tls.Conn, http.Handler)),
}
}
func (s *httpServer) NewServerWithTls(port int, scheme string, l net.Listener, certFile string, keyFile string) error {
if certFile == "" || keyFile == "" {
logs.Error("证书文件为空")
return nil
}
var certFileByte = []byte(certFile)
var keyFileByte = []byte(keyFile)
config := &tls.Config{}
config.Certificates = make([]tls.Certificate, 1)
var err error
config.Certificates[0], err = tls.X509KeyPair(certFileByte, keyFileByte)
if err != nil {
return err
}
s2 := &http.Server{
Addr: ":" + strconv.Itoa(port),
Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
r.URL.Scheme = scheme
s.handleTunneling(w, r)
}),
// Disable HTTP/2.
TLSNextProto: make(map[string]func(*http.Server, *tls.Conn, http.Handler)),
TLSConfig: config,
}
return s2.ServeTLS(l, "", "")
}
+191 -53
View File
@@ -4,7 +4,7 @@ import (
"net"
"net/http"
"net/url"
"path/filepath"
"strings"
"sync"
"ehang.io/nps/lib/cache"
@@ -12,7 +12,6 @@ import (
"ehang.io/nps/lib/conn"
"ehang.io/nps/lib/crypt"
"ehang.io/nps/lib/file"
"github.com/astaxie/beego"
"github.com/astaxie/beego/logs"
"github.com/pkg/errors"
)
@@ -21,6 +20,7 @@ type HttpsServer struct {
httpServer
listener net.Listener
httpsListenerMap sync.Map
hostIdCertMap sync.Map
}
func NewHttpsServer(l net.Listener, bridge NetBridge, useCache bool, cacheLen int) *HttpsServer {
@@ -33,63 +33,199 @@ func NewHttpsServer(l net.Listener, bridge NetBridge, useCache bool, cacheLen in
return https
}
//start https server
// start https server
func (https *HttpsServer) Start() error {
var err error
if https.errorContent, err = common.ReadAllFromFile(filepath.Join(common.GetRunPath(), "web", "static", "page", "error.html")); err != nil {
https.errorContent = []byte("nps 404")
}
if b, err := beego.AppConfig.Bool("https_just_proxy"); err == nil && b {
conn.Accept(https.listener, func(c net.Conn) {
https.handleHttps(c)
})
} else {
//start the default listener
certFile := beego.AppConfig.String("https_default_cert_file")
keyFile := beego.AppConfig.String("https_default_key_file")
if common.FileExists(certFile) && common.FileExists(keyFile) {
l := NewHttpsListener(https.listener)
https.NewHttps(l, certFile, keyFile)
https.httpsListenerMap.Store("default", l)
}
conn.Accept(https.listener, func(c net.Conn) {
serverName, rb := GetServerNameFromClientHello(c)
//if the clientHello does not contains sni ,use the default ssl certificate
if serverName == "" {
serverName = "default"
}
var l *HttpsListener
if v, ok := https.httpsListenerMap.Load(serverName); ok {
l = v.(*HttpsListener)
conn.Accept(https.listener, func(c net.Conn) {
serverName, rb := GetServerNameFromClientHello(c)
r := buildHttpsRequest(serverName)
if host, err := file.GetDb().GetInfoByHost(serverName, r); err != nil {
c.Close()
logs.Debug("the url %s can't be parsed!,remote addr %s", serverName, c.RemoteAddr().String())
return
} else {
if host.CertFilePath == "" || host.KeyFilePath == "" {
logs.Debug("加载客户端本地证书")
https.handleHttps2(c, serverName, rb, r)
} else {
r := buildHttpsRequest(serverName)
if host, err := file.GetDb().GetInfoByHost(serverName, r); err != nil {
c.Close()
logs.Notice("the url %s can't be parsed!,remote addr %s", serverName, c.RemoteAddr().String())
return
logs.Debug("使用上传证书")
// 判断是路径还是证书,-----BEGIN 开头的为证书
if strings.Contains(host.CertFilePath, "-----BEGIN") || strings.Contains(host.KeyFilePath, "-----BEGIN") {
logs.Debug("通过上传文件加载证书")
https.cert(host, c, rb, host.CertFilePath, host.KeyFilePath)
} else {
logs.Debug("通过路径加载证书")
if !common.FileExists(host.CertFilePath) || !common.FileExists(host.KeyFilePath) {
//if the host cert file or key file is not set ,use the default file
if v, ok := https.httpsListenerMap.Load("default"); ok {
l = v.(*HttpsListener)
} else {
c.Close()
logs.Error("the key %s cert %s file is not exist", host.KeyFilePath, host.CertFilePath)
return
}
} else {
l = NewHttpsListener(https.listener)
https.NewHttps(l, host.CertFilePath, host.KeyFilePath)
https.httpsListenerMap.Store(serverName, l)
c.Close()
logs.Error("证书或秘钥文件不存在", host.KeyFilePath, host.CertFilePath)
return
}
cert, err := common.ReadAllFromFile(host.CertFilePath)
if err != nil {
c.Close()
logs.Error("加载证书失败", err)
return
}
key, err := common.ReadAllFromFile(host.KeyFilePath)
if err != nil {
c.Close()
logs.Error("加载证书秘钥失败", err)
return
}
https.cert(host, c, rb, string(cert), string(key))
}
}
}
})
//var err error
//if https.errorContent, err = common.ReadAllFromFile(filepath.Join(common.GetRunPath(), "web", "static", "page", "error.html")); err != nil {
// https.errorContent = []byte("nps 404")
//}
//if b, err := beego.AppConfig.Bool("https_just_proxy"); err == nil && b {
// conn.Accept(https.listener, func(c net.Conn) {
// https.handleHttps(c)
// })
//} else {
// //start the default listener
// certFile := beego.AppConfig.String("https_default_cert_file")
// keyFile := beego.AppConfig.String("https_default_key_file")
// if common.FileExists(certFile) && common.FileExists(keyFile) {
// l := NewHttpsListener(https.listener)
// https.NewHttps(l, certFile, keyFile)
// https.httpsListenerMap.Store("default", l)
// }
// conn.Accept(https.listener, func(c net.Conn) {
// serverName, rb := GetServerNameFromClientHello(c)
// //if the clientHello does not contains sni ,use the default ssl certificate
// if serverName == "" {
// serverName = "default"
// }
// var l *HttpsListener
// if v, ok := https.httpsListenerMap.Load(serverName); ok {
// l = v.(*HttpsListener)
// } else {
// r := buildHttpsRequest(serverName)
// if host, err := file.GetDb().GetInfoByHost(serverName, r); err != nil {
// c.Close()
// logs.Notice("the url %s can't be parsed!,remote addr %s", serverName, c.RemoteAddr().String())
// return
// } else {
// if !common.FileExists(host.CertFilePath) || !common.FileExists(host.KeyFilePath) {
// //if the host cert file or key file is not set ,use the default file
// if v, ok := https.httpsListenerMap.Load("default"); ok {
// l = v.(*HttpsListener)
// } else {
// c.Close()
// logs.Error("the key %s cert %s file is not exist", host.KeyFilePath, host.CertFilePath)
// return
// }
// } else {
// l = NewHttpsListener(https.listener)
// https.NewHttps(l, host.CertFilePath, host.KeyFilePath)
// https.httpsListenerMap.Store(serverName, l)
// }
// }
// }
// acceptConn := conn.NewConn(c)
// acceptConn.Rb = rb
// l.acceptConn <- acceptConn
// })
//}
return nil
}
func (https *HttpsServer) cert(host *file.Host, c net.Conn, rb []byte, certFileUrl string, keyFileUrl string) {
var l *HttpsListener
i := 0
https.hostIdCertMap.Range(func(key, value interface{}) bool {
i++
// 如果host Id 不存在,则删除map
if id, ok := key.(int); ok {
var err error
_, err = file.GetDb().GetHostById(id)
if err != nil {
// 说明这个host已经不存了,需要释放Listener
logs.Error(err)
if oldL, ok := https.httpsListenerMap.Load(value); ok {
err := oldL.(*HttpsListener).Close()
if err != nil {
logs.Error(err)
}
https.httpsListenerMap.Delete(value)
https.hostIdCertMap.Delete(key)
logs.Info("Listener 已释放")
}
}
acceptConn := conn.NewConn(c)
acceptConn.Rb = rb
l.acceptConn <- acceptConn
})
}
return true
})
logs.Info("当前 Listener 连接数量", i)
if cert, ok := https.hostIdCertMap.Load(host.Id); ok {
if cert == certFileUrl {
// 证书已经存在,直接加载
if v, ok := https.httpsListenerMap.Load(certFileUrl); ok {
l = v.(*HttpsListener)
}
} else {
// 证书修改过,重新加载证书
l = NewHttpsListener(https.listener)
https.NewHttps(l, certFileUrl, keyFileUrl)
if oldL, ok := https.httpsListenerMap.Load(cert); ok {
err := oldL.(*HttpsListener).Close()
if err != nil {
logs.Error(err)
}
https.httpsListenerMap.Delete(cert)
}
https.httpsListenerMap.Store(certFileUrl, l)
https.hostIdCertMap.Store(host.Id, certFileUrl)
}
} else {
// 第一次加载证书
l = NewHttpsListener(https.listener)
https.NewHttps(l, certFileUrl, keyFileUrl)
https.httpsListenerMap.Store(certFileUrl, l)
https.hostIdCertMap.Store(host.Id, certFileUrl)
}
return nil
acceptConn := conn.NewConn(c)
acceptConn.Rb = rb
l.acceptConn <- acceptConn
}
// handle the https which is just proxy to other client
func (https *HttpsServer) handleHttps2(c net.Conn, hostName string, rb []byte, r *http.Request) {
var targetAddr string
var host *file.Host
var err error
if host, err = file.GetDb().GetInfoByHost(hostName, r); err != nil {
c.Close()
logs.Debug("the url %s can't be parsed!", hostName)
return
}
if err := https.CheckFlowAndConnNum(host.Client); err != nil {
logs.Debug("client id %d, host id %d, error %s, when https connection", host.Client.Id, host.Id, err.Error())
c.Close()
return
}
defer host.Client.AddConn()
if err = https.auth(r, conn.NewConn(c), host.Client.Cnf.U, host.Client.Cnf.P); err != nil {
logs.Warn("auth error", err, r.RemoteAddr)
return
}
if targetAddr, err = host.Target.GetRandomTarget(); err != nil {
logs.Warn(err.Error())
}
logs.Info("new https connection,clientId %d,host %s,remote address %s", host.Client.Id, r.Host, c.RemoteAddr().String())
https.DealClient(conn.NewConn(c), host.Client, targetAddr, rb, common.CONN_TCP, nil, host.Client.Flow, host.Target.LocalProxy, nil)
}
// close
@@ -100,11 +236,13 @@ func (https *HttpsServer) Close() error {
// new https server by cert and key file
func (https *HttpsServer) NewHttps(l net.Listener, certFile string, keyFile string) {
go func() {
logs.Error(https.NewServer(0, "https").ServeTLS(l, certFile, keyFile))
//logs.Error(https.NewServer(0, "https").ServeTLS(l, certFile, keyFile))
logs.Error(https.NewServerWithTls(0, "https", l, certFile, keyFile))
}()
}
//handle the https which is just proxy to other client
// handle the https which is just proxy to other client
func (https *HttpsServer) handleHttps(c net.Conn) {
hostName, rb := GetServerNameFromClientHello(c)
var targetAddr string
+11 -11
View File
@@ -51,7 +51,7 @@ type Sock5ModeServer struct {
listener net.Listener
}
//req
// req
func (s *Sock5ModeServer) handleRequest(c net.Conn) {
/*
The SOCKS request is formed as follows:
@@ -84,7 +84,7 @@ func (s *Sock5ModeServer) handleRequest(c net.Conn) {
}
}
//reply
// reply
func (s *Sock5ModeServer) sendReply(c net.Conn, rep uint8) {
reply := []byte{
5,
@@ -105,7 +105,7 @@ func (s *Sock5ModeServer) sendReply(c net.Conn, rep uint8) {
c.Write(reply)
}
//do conn
// do conn
func (s *Sock5ModeServer) doConnect(c net.Conn, command uint8) {
addrType := make([]byte, 1)
c.Read(addrType)
@@ -146,7 +146,7 @@ func (s *Sock5ModeServer) doConnect(c net.Conn, command uint8) {
return
}
//conn
// conn
func (s *Sock5ModeServer) handleConnect(c net.Conn) {
s.doConnect(c, connectMethod)
}
@@ -216,7 +216,7 @@ func (s *Sock5ModeServer) handleUDP(c net.Conn) {
s.sendUdpReply(c, reply, succeeded, common.GetServerIpByClientIp(c.RemoteAddr().(*net.TCPAddr).IP))
defer reply.Close()
// new a tunnel to client
link := conn.NewLink("udp5", "", s.task.Client.Cnf.Crypt, s.task.Client.Cnf.Compress, c.RemoteAddr().String(), false)
link := conn.NewLink("udp5", "", s.task.Client.Cnf.Crypt, s.task.Client.Cnf.Compress, c.RemoteAddr().String(), false, "")
target, err := s.bridge.SendLinkInfo(s.task.Client.Id, link, s.task)
if err != nil {
logs.Warn("get connection from client id %d error %s", s.task.Client.Id, err.Error())
@@ -280,7 +280,7 @@ func (s *Sock5ModeServer) handleUDP(c net.Conn) {
}
}
//new conn
// new conn
func (s *Sock5ModeServer) handleConn(c net.Conn) {
buf := make([]byte, 2)
if _, err := io.ReadFull(c, buf); err != nil {
@@ -317,7 +317,7 @@ func (s *Sock5ModeServer) handleConn(c net.Conn) {
s.handleRequest(c)
}
//socks5 auth
// socks5 auth
func (s *Sock5ModeServer) Auth(c net.Conn) error {
header := []byte{0, 0}
if _, err := io.ReadAtLeast(c, header, 2); err != nil {
@@ -345,7 +345,7 @@ func (s *Sock5ModeServer) Auth(c net.Conn) error {
// enable multi user auth
U = string(user)
if len(U) == 0 {
return errors.New("验证不通过")
return errors.New("验证不通过")
}
var ok bool
P, ok = s.task.MultiAccount.AccountMap[U]
@@ -370,7 +370,7 @@ func (s *Sock5ModeServer) Auth(c net.Conn) error {
}
}
//start
// start
func (s *Sock5ModeServer) Start() error {
return conn.NewTcpListenerAndProcess(s.task.ServerIp+":"+strconv.Itoa(s.task.Port), func(c net.Conn) {
if err := s.CheckFlowAndConnNum(s.task.Client); err != nil {
@@ -384,7 +384,7 @@ func (s *Sock5ModeServer) Start() error {
}, &s.listener)
}
//new
// new
func NewSock5ModeServer(bridge NetBridge, task *file.Tunnel) *Sock5ModeServer {
s := new(Sock5ModeServer)
s.bridge = bridge
@@ -392,7 +392,7 @@ func NewSock5ModeServer(bridge NetBridge, task *file.Tunnel) *Sock5ModeServer {
return s
}
//close
// close
func (s *Sock5ModeServer) Close() error {
return s.listener.Close()
}
+2 -2
View File
@@ -27,7 +27,7 @@ func NewUdpModeServer(bridge *bridge.Bridge, task *file.Tunnel) *UdpModeServer {
return s
}
//开始
// 开始
func (s *UdpModeServer) Start() error {
var err error
if s.task.ServerIp == "" {
@@ -80,7 +80,7 @@ func (s *UdpModeServer) process(addr *net.UDPAddr, data []byte) {
return
}
defer s.task.Client.AddConn()
link := conn.NewLink(common.CONN_UDP, s.task.Target.TargetStr, s.task.Client.Cnf.Crypt, s.task.Client.Cnf.Compress, addr.String(), s.task.Target.LocalProxy)
link := conn.NewLink(common.CONN_UDP, s.task.Target.TargetStr, s.task.Client.Cnf.Crypt, s.task.Client.Cnf.Compress, addr.String(), s.task.Target.LocalProxy, "")
if clientConn, err := s.bridge.SendLinkInfo(s.task.Client.Id, link, s.task); err != nil {
return
} else {
+3 -3
View File
@@ -100,7 +100,7 @@ func NewHttpReverseProxy(s *httpServer) *HttpReverseProxy {
proxy := NewReverseProxy(&httputil.ReverseProxy{
Director: func(r *http.Request) {
host := r.Context().Value("host").(*file.Host)
common.ChangeHostAndHeader(r, host.HostChange, host.HeaderChange, "", false)
common.ChangeHostAndHeader(r, host.HostChange, host.HeaderChange, "")
},
Transport: &http.Transport{
ResponseHeaderTimeout: rp.responseHeaderTimeout,
@@ -119,7 +119,7 @@ func NewHttpReverseProxy(s *httpServer) *HttpReverseProxy {
host = ctx.Value("host").(*file.Host)
targetAddr = ctx.Value("target").(string)
lk = conn.NewLink("http", targetAddr, host.Client.Cnf.Crypt, host.Client.Cnf.Compress, r.RemoteAddr, host.Target.LocalProxy)
lk = conn.NewLink("http", targetAddr, host.Client.Cnf.Crypt, host.Client.Cnf.Compress, r.RemoteAddr, host.Target.LocalProxy, "")
if target, err = s.bridge.SendLinkInfo(host.Client.Id, lk, nil); err != nil {
logs.Notice("connect to target %s error %s", lk.Host, err)
return nil, NewHTTPError(http.StatusBadGateway, "Cannot connect to the server")
@@ -150,7 +150,7 @@ func NewHttpReverseProxy(s *httpServer) *HttpReverseProxy {
host = ctx.Value("host").(*file.Host)
targetAddr = ctx.Value("target").(string)
lk = conn.NewLink("tcp", targetAddr, host.Client.Cnf.Crypt, host.Client.Cnf.Compress, r.RemoteAddr, host.Target.LocalProxy)
lk = conn.NewLink("tcp", targetAddr, host.Client.Cnf.Crypt, host.Client.Cnf.Compress, r.RemoteAddr, host.Target.LocalProxy, "")
if target, err = s.bridge.SendLinkInfo(host.Client.Id, lk, nil); err != nil {
logs.Notice("connect to target %s error %s", lk.Host, err)
return nil, NewHTTPError(http.StatusBadGateway, "Cannot connect to the target")
+75 -54
View File
@@ -5,6 +5,7 @@ import (
"errors"
"math"
"os"
"sort"
"strconv"
"strings"
"sync"
@@ -26,13 +27,14 @@ import (
var (
Bridge *bridge.Bridge
RunList sync.Map //map[int]interface{}
once sync.Once
)
func init() {
RunList = sync.Map{}
}
//init task from db
// init task from db
func InitFromCsv() {
//Add a public password
if vkey := beego.AppConfig.String("public_vkey"); vkey != "" {
@@ -50,7 +52,7 @@ func InitFromCsv() {
})
}
//get bridge command
// get bridge command
func DealBridgeTask() {
for {
select {
@@ -84,7 +86,7 @@ func DealBridgeTask() {
}
}
//start a new server
// start a new server
func StartNewServer(bridgePort int, cnf *file.Tunnel, bridgeType string, bridgeDisconnect int) {
Bridge = bridge.NewTunnel(bridgePort, bridgeType, common.GetBoolByStr(beego.AppConfig.String("ip_limit")), RunList, bridgeDisconnect)
go func() {
@@ -122,7 +124,7 @@ func dealClientFlow() {
}
}
//new a server by mode name
// new a server by mode name
func NewMode(Bridge *bridge.Bridge, c *file.Tunnel) proxy.Service {
var service proxy.Service
switch c.Mode {
@@ -156,7 +158,7 @@ func NewMode(Bridge *bridge.Bridge, c *file.Tunnel) proxy.Service {
return service
}
//stop server
// stop server
func StopServer(id int) error {
//if v, ok := RunList[id]; ok {
if v, ok := RunList.Load(id); ok {
@@ -182,7 +184,7 @@ func StopServer(id int) error {
return errors.New("task is not running")
}
//add task
// add task
func AddTask(t *file.Tunnel) error {
if t.Mode == "secret" || t.Mode == "p2p" {
logs.Info("secret task %s start ", t.Remark)
@@ -215,7 +217,7 @@ func AddTask(t *file.Tunnel) error {
return nil
}
//start task
// start task
func StartTask(id int) error {
if t, err := file.GetDb().GetTask(id); err != nil {
return err
@@ -227,7 +229,7 @@ func StartTask(id int) error {
return nil
}
//delete task
// delete task
func DelTask(id int) error {
//if _, ok := RunList[id]; ok {
if _, ok := RunList.Load(id); ok {
@@ -238,18 +240,64 @@ func DelTask(id int) error {
return file.GetDb().DelTask(id)
}
//get task list by page num
func GetTunnel(start, length int, typeVal string, clientId int, search string) ([]*file.Tunnel, int) {
// get task list by page num
func GetTunnel(start, length int, typeVal string, clientId int, search string, sortField string, order string) ([]*file.Tunnel, int) {
all_list := make([]*file.Tunnel, 0) //store all Tunnel
list := make([]*file.Tunnel, 0)
var cnt int
keys := file.GetMapKeys(file.GetDb().JsonDb.Tasks, false, "", "")
//get all Tunnel and sort
for _, key := range keys {
if value, ok := file.GetDb().JsonDb.Tasks.Load(key); ok {
v := value.(*file.Tunnel)
if (typeVal != "" && v.Mode != typeVal || (clientId != 0 && v.Client.Id != clientId)) || (typeVal == "" && clientId != v.Client.Id) {
continue
}
if search != "" && !(v.Id == common.GetIntNoErrByStr(search) || v.Port == common.GetIntNoErrByStr(search) || strings.Contains(v.Password, search) || strings.Contains(v.Remark, search) || strings.Contains(v.Client.VerifyKey, search)) {
all_list = append(all_list, v)
}
}
//sort by Id, Remark, TargetStr, Port, asc or desc
if sortField == "Id" {
if order == "asc" {
sort.SliceStable(all_list, func(i, j int) bool { return all_list[i].Id < all_list[j].Id })
} else {
sort.SliceStable(all_list, func(i, j int) bool { return all_list[i].Id > all_list[j].Id })
}
} else if sortField == "ClientId" {
if order == "asc" {
sort.SliceStable(all_list, func(i, j int) bool { return all_list[i].Client.Id < all_list[j].Client.Id })
} else {
sort.SliceStable(all_list, func(i, j int) bool { return all_list[i].Client.Id > all_list[j].Client.Id })
}
} else if sortField == "Remark" {
if order == "asc" {
sort.SliceStable(all_list, func(i, j int) bool { return all_list[i].Remark < all_list[j].Remark })
} else {
sort.SliceStable(all_list, func(i, j int) bool { return all_list[i].Remark > all_list[j].Remark })
}
} else if sortField == "Client.VerifyKey" {
if order == "asc" {
sort.SliceStable(all_list, func(i, j int) bool { return all_list[i].Client.VerifyKey < all_list[j].Client.VerifyKey })
} else {
sort.SliceStable(all_list, func(i, j int) bool { return all_list[i].Client.VerifyKey > all_list[j].Client.VerifyKey })
}
} else if sortField == "Target" {
if order == "asc" {
sort.SliceStable(all_list, func(i, j int) bool { return all_list[i].Target.TargetStr < all_list[j].Target.TargetStr })
} else {
sort.SliceStable(all_list, func(i, j int) bool { return all_list[i].Target.TargetStr > all_list[j].Target.TargetStr })
}
}
//search
for _, key := range all_list {
if value, ok := file.GetDb().JsonDb.Tasks.Load(key.Id); ok {
v := value.(*file.Tunnel)
if (typeVal != "" && v.Mode != typeVal || (clientId != 0 && v.Client.Id != clientId)) || (typeVal == "" && clientId != v.Client.Id) {
continue
}
if search != "" && !(v.Id == common.GetIntNoErrByStr(search) || v.Port == common.GetIntNoErrByStr(search) || strings.Contains(v.Password, search) || strings.Contains(v.Remark, search) || strings.Contains(v.Target.TargetStr, search)) {
continue
}
cnt++
@@ -260,7 +308,6 @@ func GetTunnel(start, length int, typeVal string, clientId int, search string) (
}
if start--; start < 0 {
if length--; length >= 0 {
//if _, ok := RunList[v.Id]; ok {
if _, ok := RunList.Load(v.Id); ok {
v.RunStatus = true
} else {
@@ -274,7 +321,7 @@ func GetTunnel(start, length int, typeVal string, clientId int, search string) (
return list, cnt
}
//get client list
// get client list
func GetClientList(start, length int, search, sort, order string, clientId int) (list []*file.Client, cnt int) {
list, cnt = file.GetDb().GetClientList(start, length, search, sort, order, clientId)
dealClientData()
@@ -282,7 +329,6 @@ func GetClientList(start, length int, search, sort, order string, clientId int)
}
func dealClientData() {
//logs.Info("dealClientData.........")
file.GetDb().JsonDb.Clients.Range(func(key, value interface{}) bool {
v := value.(*file.Client)
@@ -293,40 +339,13 @@ func dealClientData() {
} else {
v.IsConnect = false
}
//v.Flow.InletFlow = 0
//v.Flow.ExportFlow = 0
//if len(file.GetDb().JsonDb.Hosts) == 0 {
//
//}
//var inflow int64 = 0
//var outflow int64 = 0
//file.GetDb().JsonDb.Hosts.Range(func(key, value interface{}) bool {
// h := value.(*file.Host)
// if h.Client.Id == v.Id {
// inflow += h.Flow.InletFlow
// outflow += h.Flow.ExportFlow
// }
// return true
//})
//file.GetDb().JsonDb.Tasks.Range(func(key, value interface{}) bool {
// t := value.(*file.Tunnel)
// if t.Client.Id == v.Id {
// inflow += t.Flow.InletFlow
// outflow += t.Flow.ExportFlow
// }
// return true
//})
//
//if inflow >0 || outflow >0{
// v.Flow.InletFlow = inflow
// v.Flow.ExportFlow = outflow
//}
return true
})
return
}
//delete all host and tasks by client id
// delete all host and tasks by client id
func DelTunnelAndHostByClientId(clientId int, justDelNoStore bool) {
var ids []int
file.GetDb().JsonDb.Tasks.Range(func(key, value interface{}) bool {
@@ -358,7 +377,7 @@ func DelTunnelAndHostByClientId(clientId int, justDelNoStore bool) {
}
}
//close the client
// close the client
func DelClientConnect(clientId int) {
Bridge.DelClient(clientId)
}
@@ -462,15 +481,17 @@ func GetDashboardData() map[string]interface{} {
// 实例化流量数据到文件
func flowSession(m time.Duration) {
ticker := time.NewTicker(m)
defer ticker.Stop()
for {
select {
case <-ticker.C:
file.GetDb().JsonDb.StoreHostToJsonFile()
file.GetDb().JsonDb.StoreTasksToJsonFile()
file.GetDb().JsonDb.StoreClientsToJsonFile()
file.GetDb().JsonDb.StoreGlobalToJsonFile()
once.Do(func() {
ticker := time.NewTicker(m)
defer ticker.Stop()
for {
select {
case <-ticker.C:
file.GetDb().JsonDb.StoreHostToJsonFile()
file.GetDb().JsonDb.StoreTasksToJsonFile()
file.GetDb().JsonDb.StoreClientsToJsonFile()
file.GetDb().JsonDb.StoreGlobalToJsonFile()
}
}
}
})
}
+51
View File
@@ -1,7 +1,9 @@
package controllers
import (
"ehang.io/nps/lib/file"
"encoding/hex"
"html"
"time"
"ehang.io/nps/lib/crypt"
@@ -40,3 +42,52 @@ func (s *AuthController) GetTime() {
s.Data["json"] = m
s.ServeJSON()
}
func (s *AuthController) IpWhiteAuth() {
s.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Origin", "*")
s.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Methods", "GET, POST, OPTIONS")
s.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Headers", "Content-Type")
vkey := s.getEscapeString("vkey")
ip := s.getEscapeString("ip")
password := s.getEscapeString("pass")
if vkey == "" || ip == "" || password == "" {
s.Data["json"] = map[string]interface{}{"success": false, "message": "参数错误"}
s.ServeJSON()
return
}
c, err := file.GetDb().GetClientByVkey(vkey)
if err != nil {
s.Data["json"] = map[string]interface{}{"success": false, "message": "客户端密钥错误"}
s.ServeJSON()
return
}
if c.IpWhitePass != password {
s.Data["json"] = map[string]interface{}{"success": false, "message": "授权密码错误"}
s.ServeJSON()
return
}
ipExists := false
for _, existingIp := range c.IpWhiteList {
if existingIp == ip {
ipExists = true
break
}
}
if !ipExists {
c.IpWhiteList = append(c.IpWhiteList, ip)
file.GetDb().UpdateClient(c)
}
s.Data["json"] = map[string]interface{}{"success": true, "message": "授权成功"}
s.ServeJSON()
}
func (s *AuthController) getEscapeString(key string) string {
return html.EscapeString(s.GetString(key))
}
+12 -1
View File
@@ -1,6 +1,7 @@
package controllers
import (
"ehang.io/nps/bridge"
"html"
"math"
"strconv"
@@ -83,7 +84,17 @@ func (s *BaseController) display(tpl ...string) {
if common.IsWindows() {
s.Data["win"] = ".exe"
}
s.Data["p"] = server.Bridge.TunnelPort
s.Data["p"] = strconv.Itoa(server.Bridge.TunnelPort)
if bridge.ServerTlsEnable {
tlsPort := strconv.Itoa(beego.AppConfig.DefaultInt("tls_bridge_port", 8025))
s.Data["tls_p"] = tlsPort
s.Data["p1"] = strconv.Itoa(server.Bridge.TunnelPort) + " / " + tlsPort
} else {
s.Data["p1"] = strconv.Itoa(server.Bridge.TunnelPort)
}
s.Data["proxyPort"] = beego.AppConfig.String("hostPort")
s.Layout = "public/layout.html"
s.TplName = tplname
+19 -5
View File
@@ -1,12 +1,14 @@
package controllers
import (
"strings"
"time"
"ehang.io/nps/lib/common"
"ehang.io/nps/lib/file"
"ehang.io/nps/lib/rate"
"ehang.io/nps/server"
"github.com/astaxie/beego"
"strings"
)
type ClientController struct {
@@ -37,7 +39,7 @@ func (s *ClientController) List() {
s.AjaxTable(list, cnt, cnt, cmd)
}
//添加客户端
// 添加客户端
func (s *ClientController) Add() {
if s.Ctx.Request.Method == "GET" {
s.Data["menu"] = "client"
@@ -68,6 +70,10 @@ func (s *ClientController) Add() {
FlowLimit: int64(s.GetIntNoErr("flow_limit")),
},
BlackIpList: RemoveRepeatedElement(strings.Split(s.getEscapeString("blackiplist"), "\r\n")),
IpWhite: s.GetBoolNoErr("ipwhite"),
IpWhitePass: s.getEscapeString("ipwhitepass"),
IpWhiteList: RemoveRepeatedElement(strings.Split(s.getEscapeString("ipwhitelist"), "\r\n")),
CreateTime: time.Now().Format("2006-01-02 15:04:05"),
}
if err := file.GetDb().NewClient(t); err != nil {
s.AjaxErr(err.Error())
@@ -90,7 +96,7 @@ func (s *ClientController) GetClient() {
}
}
//修改客户端
// 修改客户端
func (s *ClientController) Edit() {
id := s.GetIntNoErr("id")
if s.Ctx.Request.Method == "GET" {
@@ -100,6 +106,7 @@ func (s *ClientController) Edit() {
} else {
s.Data["c"] = c
s.Data["BlackIpList"] = strings.Join(c.BlackIpList, "\r\n")
s.Data["IpWhiteList"] = strings.Join(c.IpWhiteList, "\r\n")
}
s.SetInfo("edit client")
s.display()
@@ -137,6 +144,9 @@ func (s *ClientController) Edit() {
}
c.WebPassword = s.getEscapeString("web_password")
c.ConfigConnAllow = s.GetBoolNoErr("config_conn_allow")
c.IpWhite = s.GetBoolNoErr("ipwhite")
c.IpWhitePass = s.getEscapeString("ipwhitepass")
c.IpWhiteList = RemoveRepeatedElement(strings.Split(s.getEscapeString("ipwhitelist"), "\r\n"))
if c.Rate != nil {
c.Rate.Stop()
}
@@ -158,6 +168,10 @@ func (s *ClientController) Edit() {
func RemoveRepeatedElement(arr []string) (newArr []string) {
newArr = make([]string, 0)
for i := 0; i < len(arr); i++ {
// 过滤空IP
if strings.TrimSpace(arr[i]) == "" {
continue
}
repeat := false
for j := i + 1; j < len(arr); j++ {
if arr[i] == arr[j] {
@@ -172,7 +186,7 @@ func RemoveRepeatedElement(arr []string) (newArr []string) {
return
}
//更改状态
// 更改状态
func (s *ClientController) ChangeStatus() {
id := s.GetIntNoErr("id")
if client, err := file.GetDb().GetClient(id); err == nil {
@@ -185,7 +199,7 @@ func (s *ClientController) ChangeStatus() {
s.AjaxErr("modified fail")
}
//删除客户端
// 删除客户端
func (s *ClientController) Del() {
id := s.GetIntNoErr("id")
if err := file.GetDb().DelClient(id); err != nil {
+77 -12
View File
@@ -81,7 +81,7 @@ func (s *IndexController) GetTunnel() {
start, length := s.GetAjaxParams()
taskType := s.getEscapeString("type")
clientId := s.GetIntNoErr("client_id")
list, cnt := server.GetTunnel(start, length, taskType, clientId, s.getEscapeString("search"))
list, cnt := server.GetTunnel(start, length, taskType, clientId, s.getEscapeString("search"), s.getEscapeString("sort"), s.getEscapeString("order"))
s.AjaxTable(list, cnt, cnt, nil)
}
@@ -94,17 +94,18 @@ func (s *IndexController) Add() {
} else {
id := int(file.GetDb().JsonDb.GetTaskId())
t := &file.Tunnel{
Port: s.GetIntNoErr("port"),
ServerIp: s.getEscapeString("server_ip"),
Mode: s.getEscapeString("type"),
Target: &file.Target{TargetStr: s.getEscapeString("target"), LocalProxy: s.GetBoolNoErr("local_proxy")},
Id: id,
Status: true,
Remark: s.getEscapeString("remark"),
Password: s.getEscapeString("password"),
LocalPath: s.getEscapeString("local_path"),
StripPre: s.getEscapeString("strip_pre"),
Flow: &file.Flow{},
Port: s.GetIntNoErr("port"),
ServerIp: s.getEscapeString("server_ip"),
Mode: s.getEscapeString("type"),
Target: &file.Target{TargetStr: s.getEscapeString("target"), LocalProxy: s.GetBoolNoErr("local_proxy")},
Id: id,
Status: true,
Remark: s.getEscapeString("remark"),
Password: s.getEscapeString("password"),
LocalPath: s.getEscapeString("local_path"),
StripPre: s.getEscapeString("strip_pre"),
ProtoVersion: s.getEscapeString("proto_version"),
Flow: &file.Flow{},
}
if t.Port <= 0 {
@@ -131,6 +132,53 @@ func (s *IndexController) Add() {
}
}
}
func (s *IndexController) Copy() {
oldId := s.GetIntNoErr("id")
if oldTask, err := file.GetDb().GetTask(oldId); err != nil {
s.error()
} else {
if client, err := file.GetDb().GetClient(oldTask.Client.Id); err != nil {
s.AjaxErr("modified error,the client is not exist")
return
} else {
oldTask.Client = client
}
id := int(file.GetDb().JsonDb.GetTaskId())
newTask := &file.Tunnel{
Client: oldTask.Client,
Port: tool.GenerateServerPort(oldTask.Mode),
ServerIp: oldTask.ServerIp,
Mode: oldTask.Mode,
Target: oldTask.Target,
Id: id,
Status: true,
Remark: oldTask.Remark,
Password: oldTask.Password,
LocalPath: oldTask.LocalPath,
StripPre: oldTask.StripPre,
ProtoVersion: oldTask.ProtoVersion,
Flow: &file.Flow{},
}
if !tool.TestServerPort(newTask.Port, newTask.Mode) {
s.AjaxErr("The port cannot be opened because it may has been occupied or is no longer allowed.")
}
if newTask.Client.MaxTunnelNum != 0 && newTask.Client.GetTunnelNum() >= newTask.Client.MaxTunnelNum {
s.AjaxErr("The number of tunnels exceeds the limit")
}
if err := file.GetDb().NewTask(newTask); err != nil {
s.AjaxErr(err.Error())
}
if err := server.AddTask(newTask); err != nil {
s.AjaxErr(err.Error())
} else {
s.AjaxOkWithId("add success", id)
}
}
}
func (s *IndexController) GetOneTunnel() {
id := s.GetIntNoErr("id")
data := make(map[string]interface{})
@@ -181,6 +229,7 @@ func (s *IndexController) Edit() {
t.Password = s.getEscapeString("password")
t.Id = id
t.LocalPath = s.getEscapeString("local_path")
t.ProtoVersion = s.getEscapeString("proto_version")
t.StripPre = s.getEscapeString("strip_pre")
t.Remark = s.getEscapeString("remark")
t.Target.LocalProxy = s.GetBoolNoErr("local_proxy")
@@ -272,11 +321,21 @@ func (s *IndexController) AddHost() {
Scheme: s.getEscapeString("scheme"),
KeyFilePath: s.getEscapeString("key_file_path"),
CertFilePath: s.getEscapeString("cert_file_path"),
AutoHttps: s.GetBoolNoErr("AutoHttps"),
}
if h.Scheme == "http" {
h.AutoHttps = false
}
var err error
if h.Client, err = file.GetDb().GetClient(s.GetIntNoErr("client_id")); err != nil {
s.AjaxErr("add error the client can not be found")
}
if h.Client.MaxTunnelNum != 0 && h.Client.GetTunnelNum() >= h.Client.MaxTunnelNum {
s.AjaxErr("The number of tunnels exceeds the limit")
}
if err := file.GetDb().NewHost(h); err != nil {
s.AjaxErr("add fail" + err.Error())
}
@@ -324,6 +383,12 @@ func (s *IndexController) EditHost() {
h.KeyFilePath = s.getEscapeString("key_file_path")
h.CertFilePath = s.getEscapeString("cert_file_path")
h.Target.LocalProxy = s.GetBoolNoErr("local_proxy")
h.AutoHttps = s.GetBoolNoErr("AutoHttps")
if h.Scheme == "http" {
h.AutoHttps = false
}
file.GetDb().JsonDb.StoreHostToJsonFile()
}
s.AjaxOk("modified success")
+2
View File
@@ -14,6 +14,7 @@ func Init() {
beego.NSAutoRouter(&controllers.LoginController{}),
beego.NSAutoRouter(&controllers.ClientController{}),
beego.NSAutoRouter(&controllers.AuthController{}),
beego.NSRouter("/auth/ipwhiteauth", &controllers.AuthController{}, "*:IpWhiteAuth"),
beego.NSAutoRouter(&controllers.GlobalController{}),
)
beego.AddNamespace(ns)
@@ -23,6 +24,7 @@ func Init() {
beego.AutoRouter(&controllers.LoginController{})
beego.AutoRouter(&controllers.ClientController{})
beego.AutoRouter(&controllers.AuthController{})
beego.Router("/auth/ipwhiteauth", &controllers.AuthController{}, "*:IpWhiteAuth")
beego.AutoRouter(&controllers.GlobalController{})
}
+1
View File
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+7 -2
View File
@@ -59,7 +59,7 @@
$.fn.cloudLang = function () {
$.ajax({
type: 'GET',
url: window.nps.web_base_url + '/static/page/languages.xml',
url: window.nps.web_base_url + '/static/page/languages.xml?v=20250107',
dataType: 'xml',
success: function (xml) {
languages['content'] = xml2json($(xml).children())['content'];
@@ -144,6 +144,7 @@ function submitform(action, url, postdata) {
case 'start':
case 'stop':
case 'delete':
case 'copy':
var langobj = languages['content']['confirm'][action];
action = (langobj[languages['current']] || langobj[languages['default']] || 'Are you sure you want to ' + action + ' it?');
if (! confirm(action)) return;
@@ -157,7 +158,11 @@ function submitform(action, url, postdata) {
success: function (res) {
alert(langreply(res.msg));
if (res.status) {
if (postsubmit) {document.location.reload();}else{history.back(-1);}
if (postsubmit) {
document.location.reload();
}else{
window.location.href= document.referrer
}
}
}
});
+2
View File
File diff suppressed because one or more lines are too long
+234
View File
@@ -0,0 +1,234 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, user-scalable=0, minimal-ui">
<title>NPS访问验证</title>
<style>
html {
padding: 30px 10px;
font-size: 20px;
line-height: 1.4;
color: #737373;
background: #ddd;
-webkit-text-size-adjust: 100%;
-ms-text-size-adjust: 100%;
}
html,
input {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}
body {
max-width: 500px;
_width: 500px;
padding: 30px 20px 50px;
/* background-color: white; */
margin: 40px auto;
-webkit-border-radius: 6px;
-moz-border-radius: 6px;
border-radius: 6px;
-webkit-box-shadow: 0 0px 2px rgba(0, 0, 0, 0.05);
-moz-box-shadow: 0 0px 2px rgba(0, 0, 0, 0.1);
box-shadow: 0 0px 2px rgba(0, 0, 0, 0.05);
}
h1 {
margin: 0 10px;
font-size: 50px;
text-align: center;
}
h1 span {
color: #bbb;
}
h3 {
margin: 1.5em 0 0.5em;
}
p {
margin: 1em 0;
}
ul {
padding: 0 0 0 40px;
margin: 1em 0;
}
.container {
max-width: 380px;
_width: 380px;
margin: 0 auto;
}
html .login-wrap {
position: relative;
/* margin: 180px auto; */
background: #ecf0f1;
/* width: 350px; */
border-radius: 5px;
box-shadow: 3px 3px 10px #333;
padding: 15px;
}
html .login-wrap h2 {
text-align: center;
/* font-weight: 200; */
font-size: 1.6em;
margin-top: 20px;
color: #34495e;
height: 50px;
}
html .login-wrap .form {
padding-top: 20px;
}
html .login-wrap .form input[type="text"],
html .login-wrap .form input[type="password"],
html .login-wrap .form button {
width: 80%;
margin-left: 10%;
margin-bottom: 25px;
height: 40px;
border-radius: 5px;
outline: 0;
-moz-outline-style: none;
}
html .login-wrap .form input[type="text"],
html .login-wrap .form input[type="password"] {
border: 1px solid #bbb;
padding: 0 0 0 10px;
font-size: 14px;
}
html .login-wrap .form input[type="text"]:focus,
html .login-wrap .form input[type="password"]:focus {
border: 1px solid #3498db;
}
html .login-wrap .form a {
text-align: center;
font-size: 12px;
color: #3498db;
}
html .login-wrap .form a {
text-align: center;
font-size: 12px;
color: #3498db;
}
html .login-wrap .form a p {
padding-bottom: 10px;
}
html .login-wrap .form button {
background: #e74c3c;
border: none;
color: white;
font-size: 18px;
font-weight: 200;
cursor: pointer;
transition: box-shadow .4s ease;
}
html .login-wrap .form button:hover {
box-shadow: 1px 1px 5px #555;
}
html .login-wrap .form button:active {
box-shadow: 1px 1px 7px #222;
}
html .login-wrap:after {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
background: -webkit-linear-gradient(left, #27ae60 0%, #27ae60 20%, #8e44ad 20%, #8e44ad 40%, #3498db 40%, #3498db 60%, #e74c3c 60%, #e74c3c 80%, #f1c40f 80%, #f1c40f 100%);
background: -moz-linear-gradient(left, #27ae60 0%, #27ae60 20%, #8e44ad 20%, #8e44ad 40%, #3498db 40%, #3498db 60%, #e74c3c 60%, #e74c3c 80%, #f1c40f 80%, #f1c40f 100%);
height: 5px;
border-radius: 5px 5px 0 0;
}
.tips {
text-align: center;
font-size: 14px;
}
.ip-addr {
font-weight: bolder;
}
.error {
text-align: center;
color: red;
}
</style>
</head>
<body>
<div hidden id="vkey">${vkey}</div>
<div hidden id="port">${port}</div>
<div class="container">
<div class="login-wrap">
<h2>访问验证</h2>
<div class="tips">当前 IP (<span class="ip-addr" id="ip_addr">${ip}</span>) 未经授权, 已禁止访问</div>
<div class="form">
<input type="text" id="pwd" placeholder="请输入访问密码" name="pw">
<button onclick="submitAuth()"> 提交验证 </button>
<div hidden id="error" class="error"></div>
</div>
</div>
</div>
</body>
<script>
function submitAuth() {
var pwd = document.getElementById("pwd").value
var vkey = document.getElementById("vkey").innerText
var ip = document.getElementById("ip_addr").innerText
var port = document.getElementById("port").innerText
if (pwd === '' || pwd == null){
document.getElementById("error").hidden = false;
document.getElementById("error").innerHTML = "请输入授权秘钥"
}
const xhr = new XMLHttpRequest()
xhr.addEventListener("readystatechange", function () {
// debugger
if (xhr.response != null && xhr.response !== '') {
var resp = JSON.parse(xhr.response);
console.log(resp)
if (resp.success !== true) {
document.getElementById("error").hidden = false;
document.getElementById("error").innerHTML = resp.message
}else{
location.reload();
}
}
console.log(xhr.response)
})
var host = window.location.hostname
xhr.open("get", "//" + host + ':' + port + "/auth/ipwhiteauth?vkey=" + vkey + "&ip=" + ip + "&pass=" + pwd)
xhr.send()
}
</script>
</html>
+65 -2
View File
@@ -189,10 +189,31 @@
<zh-CN>访问端命令</zh-CN>
<en-US>Access command</en-US>
</lang>
<lang id="word-protoversion">
<zh-CN>Proxy Protocol Version</zh-CN>
<en-US>Proxy Protocol Version</en-US>
</lang>
<lang id="word-quicklycommand">
<zh-CN>快捷启动命令</zh-CN>
<en-US>Quickly command</en-US>
</lang>
<lang id="word-tlsquicklycommand">
<zh-CN>TLS快捷启动命令</zh-CN>
<en-US>TLS Quickly command</en-US>
</lang>
<lang id="word-commandclient">
<zh-CN>客户端命令</zh-CN>
<en-US>Command</en-US>
</lang>
<lang id="word-commandclient-tls">
<zh-CN>TLS 启动命令</zh-CN>
<en-US>TLS Command</en-US>
</lang>
<lang id="word-compress">
<zh-CN>压缩</zh-CN>
<en-US>Compress</en-US>
@@ -272,13 +293,13 @@
<en-US>HTTP port</en-US>
</lang>
<lang id="word-httpscert">
<zh-CN>HTTPS 证书</zh-CN>
<zh-CN>HTTPS 证书(或证书路径)</zh-CN>
<en-US>HTTPS cert</en-US>
</lang>
<lang id="word-https">HTTPS
</lang>
<lang id="word-httpskey">
<zh-CN>HTTPS 密钥</zh-CN>
<zh-CN>HTTPS 密钥(或秘钥路径)</zh-CN>
<en-US>HTTPS key</en-US>
</lang>
<lang id="word-httpsport">
@@ -383,6 +404,12 @@
<zh-CN>端口</zh-CN>
<en-US>Port</en-US>
</lang>
<lang id="word-accessaddress">
<zh-CN>访问地址</zh-CN>
<en-US>Access address</en-US>
</lang>
<lang id="word-proxytolocal">
<zh-CN>代理到服务器本地</zh-CN>
<en-US>Proxy to server local</en-US>
@@ -572,6 +599,12 @@
<zh-CN>唯一值,不填将自动生成</zh-CN>
<en-US>Unique, non-filling will be generated automatically</en-US>
</lang>
<lang id="info-ipwhitepass">
<zh-CN>IP授权密码,不在IP白名单的访问将被跳转到IP授权页面,输入正确的授权密码,即可完成添加IP。</zh-CN>
<en-US>IP White Password, access that is not in the IP white list will be redirected to the IP authorization page, enter the correct authorization password, and you can complete the addition of IP.</en-US>
</lang>
<lang id="info-casefile">
<zh-CN>通提供一个公网可访问的本地文件服务,此模式仅客户端使用配置文件模式方可启动。</zh-CN>
<en-US>Provide a local file service accessible to the public network, which can only be started by the client using the profile mode.</en-US>
@@ -705,6 +738,12 @@
<en-US>Empty means to be unrestricted</en-US>
</lang>
<lang id="info-input-whitepass">
<zh-CN>留空表示不跳转IP授权页面</zh-CN>
<en-US>Empty means not to jump to the IP authorization page</en-US>
</lang>
<lang id="word-blackiplist">
<zh-CN>IP黑名单(防暴力破解)</zh-CN>
@@ -733,11 +772,31 @@
<en-US>IP Black List</en-US>
</lang>
<lang id="word-createtime">
<zh-CN>创建时间</zh-CN>
<en-US>Create Time</en-US>
</lang>
<lang id="word-lastonlinetime">
<zh-CN>上次在线时间</zh-CN>
<en-US>Last Online Time</en-US>
</lang>
<lang id="word-ipwhite">
<zh-CN>启用IP白名单</zh-CN>
<en-US> Enable IP White </en-US>
</lang>
<lang id="word-ipwhitepass">
<zh-CN>IP白名单授权密码</zh-CN>
<en-US>IP White Password </en-US>
</lang>
<lang id="word-ipwhitelist">
<zh-CN>IP白名单</zh-CN>
<en-US>IP White List </en-US>
</lang>
<confirm>
<lang id="delete">
<zh-CN>你确定你要删除它吗?</zh-CN>
@@ -751,6 +810,10 @@
<zh-CN>你确定你要停止它吗?</zh-CN>
<en-US>Are you sure you want to stop it?</en-US>
</lang>
<lang id="copy">
<zh-CN>你确定要复制它吗?</zh-CN>
<en-US>Are you sure you want to copy it?</en-US>
</lang>
</confirm>
<reply>
+53 -9
View File
@@ -88,22 +88,49 @@
</select>
</div>
</div>
<div class="form-group" id="compress">
<label class="control-label font-bold" langtag="word-compress"></label>
<!-- <div class="form-group" id="compress">-->
<!-- <label class="control-label font-bold" langtag="word-compress"></label>-->
<!-- <div class="col-sm-10">-->
<!-- <select class="form-control" name="compress">-->
<!-- <option value="0" langtag="word-no"></option>-->
<!-- <option value="1" langtag="word-yes"></option>-->
<!-- </select>-->
<!-- </div>-->
<!-- </div>-->
<!-- <div class="form-group" id="compress">-->
<!-- <label class="control-label font-bold" langtag="word-crypt"></label>-->
<!-- <div class="col-sm-10">-->
<!-- <select class="form-control" name="crypt">-->
<!-- <option value="0" langtag="word-no"></option>-->
<!-- <option value="1" langtag="word-yes"></option>-->
<!-- </select>-->
<!-- </div>-->
<!-- </div>-->
<div class="form-group" id="ip_white">
<label class="control-label font-bold" langtag="word-ipwhite"></label>
<div class="col-sm-10">
<select class="form-control" name="compress">
<select class="form-control" name="ipwhite">
<option value="0" langtag="word-no"></option>
<option value="1" langtag="word-yes"></option>
</select>
</div>
</div>
<div class="form-group" id="compress">
<label class="control-label font-bold" langtag="word-crypt"></label>
<div class="form-group" id="Ip_white_pass" style="display: none;">
<label class="control-label font-bold" langtag="word-ipwhitepass"></label>
<div class="col-sm-10">
<select class="form-control" name="crypt">
<option value="0" langtag="word-no"></option>
<option value="1" langtag="word-yes"></option>
</select>
<input class="form-control" type="text" name="ipwhitepass" placeholder="" langtag="info-input-whitepass">
<span class="help-block m-b-none" langtag="info-ipwhitepass"></span>
</div>
</div>
<div class="form-group" id="ip_white_list" style="display: none;">
<label class="control-label font-bold" langtag="word-ipwhitelist"></label>
<div class="col-sm-10">
<textarea class="form-control" rows="4" type="text" name="ipwhitelist" placeholder="" langtag="info-suchasblackiplist">{{.BlackIpList}}</textarea>
<span class="help-block m-b-none" langtag="info-descblackiplist"></span>
</div>
</div>
@@ -128,3 +155,20 @@
</div>
</div>
</div>
<script>
$(document).ready(function() {
// IP白名单选择change事件
$('select[name="ipwhite"]').change(function() {
if ($(this).val() == '1') {
$('#Ip_white_pass').show();
$('#ip_white_list').show();
$('#black_ip_list').hide();
} else {
$('#Ip_white_pass').hide();
$('#ip_white_list').hide();
$('#black_ip_list').show();
}
});
});
</script>
+96 -32
View File
@@ -8,96 +8,108 @@
<div class="form-group" id="remark">
<label class="control-label font-bold" langtag="word-remark"></label>
<div class="col-sm-10">
<input class="form-control" value="{{.c.Remark}}" type="text" name="remark" placeholder="" langtag="word-remark">
<input class="form-control" value="{{.c.Remark}}" type="text" name="remark" placeholder=""
langtag="word-remark">
</div>
</div>
{{if eq true .isAdmin}}
{{if eq true .allow_flow_limit}}
{{if eq true .isAdmin}}
{{if eq true .allow_flow_limit}}
<div class="form-group" id="flow_limit">
<label class="control-label font-bold" langtag="word-flowlimit"></label>
<div class="col-sm-10">
<input class="form-control" value="{{.c.Flow.FlowLimit}}" type="text" name="flow_limit" placeholder="" langtag="info-unrestricted">
<input class="form-control" value="{{.c.Flow.FlowLimit}}" type="text" name="flow_limit"
placeholder="" langtag="info-unrestricted">
<span class="help-block m-b-none" langtag="word-unit"></span>: M
</div>
</div>
{{end}}
{{if eq true .allow_rate_limit}}
{{end}}
{{if eq true .allow_rate_limit}}
<div class="form-group" id="rate_limit">
<label class="control-label font-bold" langtag="word-ratelimit"></label>
<div class="col-sm-10">
<input class="form-control" value="{{.c.RateLimit}}" type="text" name="rate_limit" placeholder="" langtag="info-unrestricted">
<input class="form-control" value="{{.c.RateLimit}}" type="text" name="rate_limit"
placeholder="" langtag="info-unrestricted">
<span class="help-block m-b-none" langtag="word-unit"></span>: KB/S
</div>
</div>
{{end}}
{{if eq true .allow_connection_num_limit}}
{{end}}
{{if eq true .allow_connection_num_limit}}
<div class="form-group" id="max_conn">
<label class="control-label font-bold" langtag="word-maxconnections"></label>
<div class="col-sm-10">
<input class="form-control" value="{{.c.MaxConn}}" type="text" name="max_conn" placeholder="" langtag="info-unrestricted">
<input class="form-control" value="{{.c.MaxConn}}" type="text" name="max_conn"
placeholder="" langtag="info-unrestricted">
</div>
</div>
{{end}}
{{if eq true .allow_tunnel_num_limit}}
{{end}}
{{if eq true .allow_tunnel_num_limit}}
<div class="form-group" id="max_tunnel">
<label class="control-label font-bold" langtag="word-maxtunnels"></label>
<div class="col-sm-10">
<input class="form-control" value="{{.c.MaxTunnelNum}}" type="text" name="max_tunnel" placeholder="" langtag="info-unrestricted">
<input class="form-control" value="{{.c.MaxTunnelNum}}" type="text" name="max_tunnel"
placeholder="" langtag="info-unrestricted">
</div>
</div>
{{end}}
{{end}}
{{end}}
{{end}}
<div class="form-group" id="u">
<label class="control-label font-bold" langtag="word-basicusername"></label>
<div class="col-sm-10">
<input class="form-control" value="{{.c.Cnf.U}}" type="text" name="u" placeholder="" langtag="info-unrestricted">
<input class="form-control" value="{{.c.Cnf.U}}" type="text" name="u" placeholder=""
langtag="info-unrestricted">
<span class="help-block m-b-none" langtag="info-onlyproxy"></span>
</div>
</div>
<div class="form-group" id="p">
<label class="control-label font-bold" langtag="word-basicpassword"></label>
<div class="col-sm-10">
<input class="form-control" value="{{.c.Cnf.P}}" type="text" name="p" placeholder="" langtag="info-unrestricted">
<input class="form-control" value="{{.c.Cnf.P}}" type="text" name="p" placeholder=""
langtag="info-unrestricted">
<span class="help-block m-b-none" langtag="info-onlyproxy"></span>
</div>
</div>
{{if eq true .isAdmin}}
{{if eq true .isAdmin}}
<div class="form-group" id="vkey">
<label class="control-label font-bold" langtag="word-verifyKey"></label>
<div class="col-sm-10">
<input class="form-control" value="{{.c.VerifyKey}}" type="text" name="vkey" placeholder="" langtag="info-unrestricted">
<input class="form-control" value="{{.c.VerifyKey}}" type="text" name="vkey" placeholder=""
langtag="info-unrestricted">
<span class="help-block m-b-none" langtag="info-autogenerated"></span>
</div>
</div>
{{end}}
{{if eq true .allow_user_login}}
{{if or (eq true .allow_user_change_username) (eq true .isAdmin)}}
{{end}}
{{if eq true .allow_user_login}}
{{if or (eq true .allow_user_change_username) (eq true .isAdmin)}}
<div class="form-group" id="web_username">
<label class="control-label font-bold" langtag="word-webusername"></label>
<div class="col-sm-10">
<input class="form-control" value="{{.c.WebUserName}}" type="text" name="web_username" placeholder="" langtag="info-unrestricted">
<input class="form-control" value="{{.c.WebUserName}}" type="text" name="web_username"
placeholder="" langtag="info-unrestricted">
</div>
</div>
{{end}}
{{end}}
<div class="form-group" id="web_password">
<label class="control-label font-bold" langtag="word-webpassword"></label>
<div class="col-sm-10">
<input class="form-control" value="{{.c.WebPassword}}" type="text" name="web_password" placeholder="" langtag="info-unrestricted">
<input class="form-control" value="{{.c.WebPassword}}" type="text" name="web_password"
placeholder="" langtag="info-unrestricted">
</div>
</div>
{{end}}
{{end}}
<div class="form-group" id="config_conn_allow">
<label class="control-label font-bold" langtag="word-connectbyconfig"></label>
<div class="col-sm-10">
<select class="form-control" name="config_conn_allow">
<option {{if eq true .c.ConfigConnAllow}}selected{{end}} value="1" langtag="word-yes"></option>
<option {{if eq false .c.ConfigConnAllow}}selected{{end}} value="0" langtag="word-no"></option>
<option {{if eq true .c.ConfigConnAllow}}selected{{end}} value="1" langtag="word-yes">
</option>
<option {{if eq false .c.ConfigConnAllow}}selected{{end}} value="0" langtag="word-no">
</option>
</select>
</div>
</div>
<div class="form-group" id="compress">
<!-- <div class="form-group" id="compress">
<label class="control-label font-bold" langtag="word-compress"></label>
<div class="col-sm-10">
<select class="form-control" name="compress">
@@ -114,12 +126,42 @@
<option {{if eq true .c.Cnf.Crypt}}selected{{end}} value="1" langtag="word-yes"></option>
</select>
</div>
</div> -->
<div class="form-group" id="ip_white">
<label class="control-label font-bold" langtag="word-ipwhite"></label>
<div class="col-sm-10">
<select class="form-control" name="ipwhite" onchange="changeIpWhite()">
<option {{if eq false .c.IpWhite}}selected{{end}} value="0" langtag="word-no"></option>
<option {{if eq true .c.IpWhite}}selected{{end}} value="1" langtag="word-yes"></option>
</select>
</div>
</div>
<div class="form-group" id="ip_white_pass" style="display: none;">
<label class="control-label font-bold" langtag="word-ipwhitepass"></label>
<div class="col-sm-10">
<input class="form-control" type="text" name="ipwhitepass" placeholder=""
langtag="info-input-whitepass" value="{{.c.IpWhitePass}}">
<span class="help-block m-b-none" langtag="info-ipwhitepass"></span>
</div>
</div>
<div class="form-group" id="ip_white_list" style="display: none;">
<label class="control-label font-bold" langtag="word-ipwhitelist"></label>
<div class="col-sm-10">
<textarea class="form-control" rows="4" type="text" name="ipwhitelist" placeholder=""
langtag="info-suchasblackiplist">{{.IpWhiteList}}</textarea>
<span class="help-block m-b-none" langtag="info-descblackiplist"></span>
</div>
</div>
<div class="form-group" id="black_ip_list">
<label class="control-label font-bold" langtag="word-blackiplist"></label>
<div class="col-sm-10">
<textarea class="form-control" rows="4" type="text" name="blackiplist" placeholder="" langtag="info-suchasblackiplist">{{.BlackIpList}}</textarea>
<textarea class="form-control" rows="4" type="text" name="blackiplist" placeholder=""
langtag="info-suchasblackiplist">{{.BlackIpList}}</textarea>
<span class="help-block m-b-none" langtag="info-descblackiplist"></span>
</div>
</div>
@@ -127,8 +169,9 @@
<div class="hr-line-dashed"></div>
<div class="form-group">
<div class="col-sm-4 col-sm-offset-2">
<button class="btn btn-success" type="button" onclick="submitform('add', '{{.web_base_url}}/client/edit', $('form').serializeArray())"> <i
class="fa fa-fw fa-lg fa-save"></i><span langtag="word-save"></span>
<button class="btn btn-success" type="button"
onclick="submitform('add', '{{.web_base_url}}/client/edit', $('form').serializeArray())">
<i class="fa fa-fw fa-lg fa-save"></i><span langtag="word-save"></span>
</button>
</div>
</div>
@@ -137,3 +180,24 @@
</div>
</div>
</div>
<script>
function changeIpWhite() {
var ipWhite = $('select[name="ipwhite"]').val();
if (ipWhite == '1') {
$('#ip_white_pass').show();
$('#ip_white_list').show();
$('#black_ip_list').hide();
} else {
$('#ip_white_pass').hide();
$('#ip_white_list').hide();
$('#black_ip_list').show();
}
}
$(document).ready(function () {
// 页面加载时初始化显示状态
changeIpWhite();
});
</script>
+31 -4
View File
@@ -61,18 +61,23 @@
return '<b langtag="word-maxconnections"></b>: ' + row.MaxConn + '&emsp;'
+ '<b langtag="word-curconnections"></b>: ' + row.NowConn + '&emsp;'
+ '<b langtag="word-flowlimit"></b>: ' + row.Flow.FlowLimit + 'm&emsp;'
+ '<b langtag="word-ratelimit"></b>: ' + row.RateLimit + 'kb/s&emsp;'
+ '<b langtag="word-ratelimit"></b>: ' + row.RateLimit + 'KB/s&emsp;'
+ '<b langtag="word-maxtunnels"></b>: ' + row.MaxTunnelNum + '&emsp;<br/><br/>'
+ '<b langtag="word-webusername"></b>: ' + row.WebUserName + '&emsp;'
+ '<b langtag="word-webpassword"></b>: ' + row.WebPassword + '&emsp;'
+ '<b langtag="word-basicusername"></b>: ' + row.Cnf.U + '&emsp;'
+ '<b langtag="word-basicpassword"></b>: ' + row.Cnf.P + '&emsp;<br/><br/>'
+ '<b langtag="word-crypt"></b>: <span langtag="word-' + row.Cnf.Crypt + '"></span>&emsp;'
+ '<b langtag="word-compress"></b>: <span langtag="word-' + row.Cnf.Compress + '"></span>&emsp;'
+ '<b langtag="word-connectbyconfig"></b>: <span langtag="word-' + row.ConfigConnAllow + '"></span>&emsp;<br/><br/>'
+ '<b langtag="word-ipwhite"></b>: ' + row.IpWhite + '&emsp;'
+ '<b langtag="word-ipwhitepass"></b>: ' + row.IpWhitePass + '&emsp;<br/>'
+ '<b langtag="word-ipwhitelist"></b>: ' + row.IpWhiteList + '&emsp;<br/>'
+ '<b langtag="word-blackip"></b>: ' + row.BlackIpList + '&emsp;<br/><br/>'
+ '<b langtag="word-createtime"></b>: ' + row.CreateTime + '&emsp;<br/>'
+ '<b langtag="word-lastonlinetime"></b>: ' + row.LastOnlineTime + '&emsp;<br/><br/>'
+ '<b langtag="word-commandclient"></b>: ' + "<code>./npc{{.win}} -server={{.ip}}:{{.p}} -vkey=" + row.VerifyKey + " -type=" +{{.bridgeType}} +"</code>"
+ '<b langtag="word-quicklycommand"></b>: <span>' + encodeToBase64('{{.ip}}:{{.p}} ' + row.VerifyKey) + '</span>&emsp;<button class="copy btn btn-info btn-xs" onclick="copyCommand(this)" data-clipboard-text="">复制</button><br/>'
+ '<b langtag="word-tlsquicklycommand"></b>: <span>' + encodeToBase64('{{.ip}}:{{.tls_p}} ' + row.VerifyKey + ' true') + '</span>&emsp;<button class="copy btn btn-info btn-xs" onclick="copyCommand(this)" data-clipboard-text="">复制</button><br/>'
+ '<b langtag="word-commandclient"></b>: ' + "<code>./npc{{.win}} -server={{.ip}}:{{.p}} -vkey=" + row.VerifyKey + " -type=" +{{.bridgeType}} +"</code><button class=\"copy btn btn-info btn-xs\" onclick=\"copyCommand(this)\" data-clipboard-text=\"\">复制</button><br/>"
+ '<b langtag="word-commandclient-tls"></b>: ' + "<code>./npc{{.win}} -server={{.ip}}:{{.tls_p}} -vkey=" + row.VerifyKey + " -tls_enable=true</code><button class=\"copy btn btn-info btn-xs\" onclick=\"copyCommand(this)\" data-clipboard-text=\"\">复制</button>"
},
//表格的列
columns: [
@@ -211,4 +216,26 @@
}
]
});
function encodeToBase64(str){
return btoa("nps "+ str);
}
function copyCommand(data) {
data.setAttribute("data-clipboard-text", data.previousElementSibling.innerHTML)
}
var clipboard = new ClipboardJS('.copy');
clipboard.on('success', function (e) {
// alert("复制成功"+e.text)
toastr.success('复制成功');
e.clearSelection();
});
clipboard.on('error', function (e) {
// alert("复制失败")
toastr.error('复制失败', '提示');
});
</script>
+59 -18
View File
@@ -24,7 +24,9 @@
<option value="socks5" langtag="scheme-socks5"></option>
<option value="secret" langtag="scheme-secret"></option>
<option value="p2p" langtag="scheme-p2p"></option>
{{/*<option value="file" langtag="scheme-file"></option>*/}}
{{/*
<option value="file" langtag="scheme-file"></option>
*/}}
</select>
</div>
</div>
@@ -32,8 +34,11 @@
<div class="form-group" id="client_id">
<label class="control-label font-bold" langtag="word-clientid"></label>
<div class="col-sm-10">
<input value="{{.client_id}}" class="form-control" type="text" name="client_id"
placeholder="" langtag="word-clientid">
<select class="form-control" name="client_id" placeholder="" id="nps_client_id"
langtag="word-belongclient"></select>
<!-- <input value="{{.client_id}}" class="form-control" type="text" name="client_id"-->
<!-- placeholder="" langtag="word-clientid">-->
</div>
</div>
@@ -45,13 +50,13 @@
</div>
</div>
{{if eq true .allow_multi_ip}}
<div class="form-group" id="server_ip">
<label class="control-label font-bold" langtag="word-serverip"></label>
<div class="col-sm-10">
<input class="form-control" type="text" value="0.0.0.0" name="server_ip" placeholder=""
langtag="info-suchasip">
</div>
<div class="form-group" id="server_ip">
<label class="control-label font-bold" langtag="word-serverip"></label>
<div class="col-sm-10">
<input class="form-control" type="text" value="0.0.0.0" name="server_ip" placeholder=""
langtag="info-suchasip">
</div>
</div>
{{end}}
<div class="form-group" id="port">
<label class="control-label font-bold" langtag="word-serverport"></label>
@@ -62,15 +67,15 @@
</div>
{{if eq true .allow_local_proxy}}
<div class="form-group" id="local_proxy">
<label class="control-label font-bold" langtag="word-proxytolocal"></label>
<div class="col-sm-10">
<select class="form-control" name="local_proxy">
<option value="0" langtag="word-no"></option>
<option value="1" langtag="word-yes"></option>
</select>
</div>
<div class="form-group" id="local_proxy">
<label class="control-label font-bold" langtag="word-proxytolocal"></label>
<div class="col-sm-10">
<select class="form-control" name="local_proxy">
<option value="0" langtag="word-no"></option>
<option value="1" langtag="word-yes"></option>
</select>
</div>
</div>
{{end}}
<div class="form-group" id="target">
@@ -106,6 +111,20 @@
<span class="help-block m-b-none" langtag="info-identificationkey"></span>
</div>
</div>
<div class="form-group" id="proto_version">
<label class="control-label font-bold">Proxy Protocol Version:</label>
<div class="col-sm-10">
<select class="form-control" name="proto_version">
<option value=""></option>
<option value="V1">V1</option>
<option value="V2">V2</option>
</select>
<span class="help-block m-b-none">开启此功能,请确保本地的服务能够支持 Proxy Protocol 协议。</span>
</div>
</div>
<div class="hr-line-dashed"></div>
<div class="form-group">
<div class="col-sm-4 col-sm-offset-2">
@@ -124,7 +143,7 @@
<script>
var arr = []
arr["all"] = ["port", "target", "password", "local_path", "strip_pre", "local_proxy", "client_id", "server_ip"]
arr["tcp"] = ["port", "target", "local_proxy", "client_id", "server_ip"]
arr["tcp"] = ["port", "target", "local_proxy", "client_id", "server_ip", "proto_version"]
arr["udp"] = ["port", "target", "local_proxy", "client_id", "server_ip"]
arr["socks5"] = ["port", "client_id", "server_ip"]
arr["httpProxy"] = ["port", "client_id", "server_ip"]
@@ -151,5 +170,27 @@
$("#use_client").on("change", function () {
resetForm()
})
getClientList()
})
function getClientList() {
$("select[name='client_id']").empty();
$.ajax({
type: "POST",
url: "{{.web_base_url}}/client/list", // 服务器数据的加载地址
data: {order: "asc", offset: 0, limit: 999},
dataType: "json",
success: function (data) {
if (data && data.rows.length > 0) {
for (var i = 0; i < data.rows.length; i++) {
var option = "<option value=\"" + data.rows[i].Id + "\"";
option += ">" + data.rows[i].Id + '-' + data.rows[i].Remark + "</option>"; //动态添加数据
$("select[name='client_id']").append(option);
$("select[name='client_id']").find("option[value='{{.client_id}}']").attr("selected", true);
}
}
}
});
}
</script>
+48 -20
View File
@@ -8,7 +8,7 @@
<div class="form-group">
<label class="col-sm-2 control-label font-bold" langtag="word-scheme"></label>
<div class="col-sm-10">
<span class="help-block m-b-none font-bold" langtag="word-usecase"></span>:
<span class="help-block m-b-none font-bold" langtag="word-usecase"></span>:
<span id="usecase">
<span id="casetcp" langtag="info-casetcp"></span>
<span id="caseudp" langtag="info-caseudp"></span>
@@ -25,7 +25,9 @@
<option value="socks5" langtag="scheme-socks5"></option>
<option value="secret" langtag="scheme-secret"></option>
<option value="p2p" langtag="scheme-p2p"></option>
{{/*<option value="file" langtag="scheme-file"></option>*/}}
{{/*
<option value="file" langtag="scheme-file"></option>
*/}}
</select>
</div>
</div>
@@ -33,45 +35,52 @@
<div class="form-group" id="client_id">
<label class="col-sm-2 control-label font-bold" langtag="word-clientid"></label>
<div class="col-sm-10">
<input value="{{.t.Client.Id}}" value="{{.client_id}}" class="form-control" type="text" name="client_id" placeholder="" langtag="word-clientid">
<input value="{{.t.Client.Id}}" value="{{.client_id}}" class="form-control" type="text"
name="client_id" placeholder="" langtag="word-clientid">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label font-bold" langtag="word-remark"></label>
<div class="col-sm-10">
<input value="{{.t.Remark}}" class="form-control" type="text" name="remark" placeholder="" langtag="info-unrestricted">
<input value="{{.t.Remark}}" class="form-control" type="text" name="remark" placeholder=""
langtag="info-unrestricted">
</div>
</div>
{{if eq true .allow_multi_ip}}
{{if eq true .allow_multi_ip}}
<div class="form-group" id="server_ip">
<label class="col-sm-2 control-label font-bold" langtag="word-serverip"></label>
<div class="col-sm-10">
<input class="form-control" type="text" value="{{.t.ServerIp}}" name="server_ip" placeholder="" langtag="info-suchasip">
<input class="form-control" type="text" value="{{.t.ServerIp}}" name="server_ip"
placeholder="" langtag="info-suchasip">
</div>
</div>
{{end}}
{{end}}
<div class="form-group" id="port">
<label class="col-sm-2 control-label font-bold" langtag="word-serverport"></label>
<div class="col-sm-10">
<input value="{{.t.Port}}" class="form-control" type="text" name="port" placeholder="" langtag="info-suchasport">
<input value="{{.t.Port}}" class="form-control" type="text" name="port" placeholder=""
langtag="info-suchasport">
</div>
</div>
{{if eq true .allow_local_proxy}}
{{if eq true .allow_local_proxy}}
<div class="form-group" id="local_proxy">
<label class="control-label col-sm-2 font-bold" langtag="word-proxytolocal"></label>
<div class="col-sm-10">
<select class="form-control" name="local_proxy">
<option {{if eq false .t.Target.LocalProxy}}selected{{end}} value="0" langtag="word-no"></option>
<option {{if eq true .t.Target.LocalProxy}}selected{{end}} value="1" langtag="word-yes"></option>
<option {{if eq false .t.Target.LocalProxy}}selected{{end}} value="0"
langtag="word-no"></option>
<option {{if eq true .t.Target.LocalProxy}}selected{{end}} value="1"
langtag="word-yes"></option>
</select>
</div>
</div>
{{end}}
{{end}}
<div class="form-group" id="target">
<label class="col-sm-2 control-label font-bold" langtag="word-target"></label>
<div class="col-sm-10">
<textarea class="form-control" name="target" rows="4" placeholder="" langtag="info-suchasiplist">{{.t.Target.TargetStr}}</textarea>
<textarea class="form-control" name="target" rows="4" placeholder=""
langtag="info-suchasiplist">{{.t.Target.TargetStr}}</textarea>
<span class="help-block m-b-none" langtag="info-targettunnel"></span>
</div>
</div>
@@ -79,30 +88,48 @@
<div class="form-group" id="local_path">
<label class="col-sm-2 control-label font-bold" langtag="word-localpath"></label>
<div class="col-sm-10">
<input value="{{.t.LocalPath}}" class="form-control" type="text" name="local_path" placeholder="" langtag="info-suchaslocalpath">
<input value="{{.t.LocalPath}}" class="form-control" type="text" name="local_path"
placeholder="" langtag="info-suchaslocalpath">
</div>
</div>
<div class="form-group" id="strip_pre">
<label class="col-sm-2 control-label font-bold" langtag="word-stripprefix"></label>
<div class="col-sm-10">
<input value="{{.t.StripPre}}" class="form-control" type="text" name="strip_pre" placeholder="" langtag="info-suchasstripprefix">
<input value="{{.t.StripPre}}" class="form-control" type="text" name="strip_pre"
placeholder="" langtag="info-suchasstripprefix">
</div>
</div>
<div class="form-group" id="password">
<label class="col-sm-2 control-label font-bold" langtag="word-identificationkey"></label>
<div class="col-sm-10">
<input value="{{.t.Password}}" class="form-control" type="text" name="password" placeholder="" langtag="word-identificationkey">
<input value="{{.t.Password}}" class="form-control" type="text" name="password"
placeholder="" langtag="word-identificationkey">
<span class="help-block m-b-none" langtag="info-identificationkey"></span>
</div>
</div>
<div class="form-group" id="proto_version">
<label class="control-label font-bold">Proxy Protocol Version:</label>
<div class="col-sm-10">
<select class="form-control" name="proto_version" id="ProtoVersion">
<option value=""></option>
<option value="V1">V1</option>
<option value="V2">V2</option>
</select>
<span class="help-block m-b-none">开启此功能,请确保本地的服务能够支持 Proxy Protocol 协议。</span>
</div>
</div>
<div class="hr-line-dashed"></div>
<div class="form-group">
<div class="col-sm-4 col-sm-offset-2">
<button class="btn btn-success" type="button" onclick="submitform('edit', '{{.web_base_url}}/index/edit', $('form').serializeArray())">
<button class="btn btn-success" type="button"
onclick="submitform('edit', '{{.web_base_url}}/index/edit', $('form').serializeArray())">
<i class="fa fa-fw fa-lg fa-check-circle"></i> <span langtag="word-save"></span>
</button>
</div>
</div>
@@ -115,7 +142,7 @@
<script>
var arr = []
arr["all"] = ["port", "target", "password", "local_path", "strip_pre", "local_proxy"]
arr["tcp"] = ["client_id", "port", "target", "local_proxy"]
arr["tcp"] = ["client_id", "port", "target", "local_proxy", "proto_version"]
arr["udp"] = ["client_id", "port", "target", "local_proxy"]
arr["socks5"] = ["client_id", "port"]
arr["httpProxy"] = ["client_id", "port"]
@@ -127,7 +154,7 @@
$(".form-group[id]").css("display", "none");
$("#usecase span").css("display", "none");
o = $("#type").val();
$('#case'+ o).css("display", "inline")
$('#case' + o).css("display", "inline")
for (var i = 0; i < arr[o].length; i++) {
$("#" + arr[o][i]).css("display", "block")
}
@@ -135,6 +162,7 @@
$(function () {
$("#type").val('{{.t.Mode}}');
$("#ProtoVersion").val('{{.t.ProtoVersion}}');
resetForm()
$("#type").on("change", function () {
resetForm()
+95 -13
View File
@@ -7,7 +7,9 @@
<div class="form-group">
<label class="control-label font-bold" langtag="word-clientid"></label>
<div class="col-sm-10">
<input value="{{.client_id}}" class="form-control" type="text" name="client_id" placeholder="" langtag="word-clientid">
<select class="form-control" name="client_id" placeholder=""
langtag="word-belongclient"></select>
<!-- <input value="{{.client_id}}" class="form-control" type="text" name="client_id" placeholder="" langtag="word-clientid">-->
</div>
</div>
<div class="form-group">
@@ -19,7 +21,8 @@
<div class="form-group">
<label class="control-label font-bold" langtag="word-host"></label>
<div class="col-sm-10">
<input class="form-control" type="text" name="host" placeholder="" langtag="info-suchashost">
<input class="form-control" type="text" name="host" placeholder=""
langtag="info-suchashost">
</div>
</div>
<div class="form-group" id="scheme">
@@ -32,27 +35,41 @@
</select>
</div>
</div>
{{if eq false .https_just_proxy}}
<div class="form-group" id="AutoHttps">
<label class="control-label font-bold">自动HTTPS(301)</label>
<div class="col-sm-10">
<select class="form-control" name="AutoHttps">
<option value="0" langtag="word-no"></option>
<option value="1" langtag="word-yes"></option>
</select>
</div>
</div>
<div class="form-group" id="cert_file">
<label class="control-label font-bold" langtag="word-httpscert"></label>
<div class="col-sm-10">
<input class="form-control" type="text" name="cert_file_path" placeholder="" langtag="info-unrestricted">
<textarea rows="6" class="form-control" type="text" name="cert_file_path" id="pemText"
placeholder="请将证书文件拖拽或将内容复制粘贴到此处,证书文件格式为:xxxx_example.com.pem。
或者配置证书文件路径。"></textarea>
</div>
</div>
<div class="form-group" id="key_file">
<label class="control-label font-bold" langtag="word-httpskey"></label>
<div class="col-sm-10">
<input class="form-control" type="text" name="key_file_path" placeholder="" langtag="info-unrestricted">
<textarea rows="6" class="form-control" type="text" name="key_file_path" id="pemKey"
placeholder="请将私钥文件拖拽或复制粘贴到此处,证书秘钥格式为:xxxx_example.com.key。
或者配置秘钥文件路径。"></textarea>
</div>
</div>
{{end}}
<div class="form-group">
<label class="control-label font-bold" langtag="word-urlroute"></label>
<div class="col-sm-10">
<input class="form-control" type="text" name="location" placeholder="" langtag="info-unrestricted">
<input class="form-control" type="text" name="location" placeholder=""
langtag="info-unrestricted">
</div>
</div>
{{if eq true .allow_local_proxy}}
{{if eq true .allow_local_proxy}}
<div class="form-group" id="local_proxy">
<label class="control-label font-bold" langtag="word-proxytolocal"></label>
<div class="col-sm-10">
@@ -62,11 +79,12 @@
</select>
</div>
</div>
{{end}}
{{end}}
<div class="form-group">
<label class="control-label font-bold" langtag="word-target"></label>
<div class="col-sm-10">
<textarea class="form-control" rows="4" type="text" name="target" placeholder="" langtag="info-suchasiplist"></textarea>
<textarea class="form-control" rows="4" type="text" name="target" placeholder=""
langtag="info-suchasiplist"></textarea>
<span class="help-block m-b-none" langtag="info-targethost"></span>
</div>
@@ -74,7 +92,8 @@
<div class="form-group" id="header">
<label class="control-label font-bold" langtag="word-requestheader"></label>
<div class="col-sm-10">
<textarea class="form-control" rows="4" type="text" name="header" placeholder="Cache-Control: no-cache"></textarea>
<textarea class="form-control" rows="4" type="text" name="header"
placeholder="Cache-Control: no-cache"></textarea>
<span class="help-block m-b-none" langtag="info-header"></span>
</div>
@@ -82,13 +101,15 @@
<div class="form-group" id="hostchange">
<label class="control-label font-bold" langtag="word-requesthost"></label>
<div class="col-sm-10">
<input class="form-control" value="" type="text" name="hostchange" placeholder="" langtag="word-requesthost">
<input class="form-control" value="" type="text" name="hostchange" placeholder=""
langtag="word-requesthost">
</div>
</div>
<div class="hr-line-dashed"></div>
<div class="form-group">
<div class="col-sm-4 col-sm-offset-2">
<button class="btn btn-success" type="button" onclick="submitform('add', '{{.web_base_url}}/index/addhost', $('form').serializeArray())">
<button class="btn btn-success" type="button"
onclick="submitform('add', '{{.web_base_url}}/index/addhost', $('form').serializeArray())">
<i class="fa fa-fw fa-lg fa-check-circle"></i> <span langtag="word-add"></span>
</button>
</div>
@@ -100,14 +121,75 @@
</div>
<script>
$(function () {
const pemText = document.getElementById("pemText");
const pemKey = document.getElementById("pemKey");
// 阻止浏览器默认打开文件的行为
document.addEventListener("dragover", function (event) {
event.preventDefault();
});
pemText.addEventListener("drop", function (event) {
event.preventDefault();
const file = event.dataTransfer.files[0];
const reader = new FileReader();
reader.onload = function (e) {
pemText.value = e.target.result;
console.log("上传pem")
$('#edit_form').data('bootstrapValidator').updateStatus('pemText', 'NOT_VALIDATED');
$('#edit_form').data('bootstrapValidator').validateField('pemText');
}
reader.readAsText(file);
});
pemKey.addEventListener("drop", function (event) {
event.preventDefault();
const file = event.dataTransfer.files[0];
const reader = new FileReader();
reader.onload = function (e) {
pemKey.value = e.target.result;
$('#edit_form').data('bootstrapValidator').updateStatus('pemKey', 'NOT_VALIDATED');
$('#edit_form').data('bootstrapValidator').validateField('pemKey');
}
reader.readAsText(file);
});
$("#scheme_select").on("change", function () {
if ($("#scheme_select").val() == "all" || $("#scheme_select").val() == "https") {
$("#cert_file").css("display", "block")
$("#key_file").css("display", "block")
$("#AutoHttps").css("display", "block")
} else {
$("#cert_file").css("display", "none")
$("#key_file").css("display", "none")
$("#AutoHttps").css("display", "none")
}
})
getClientList();
})
function getClientList() {
$("select[name='client_id']").empty();
$.ajax({
type: "POST",
url: "{{.web_base_url}}/client/list", // 服务器数据的加载地址
data: {order: "asc", offset: 0, limit: 999},
dataType: "json",
success: function (data) {
if (data && data.rows.length > 0) {
for (var i = 0; i < data.rows.length; i++) {
var option = "<option value=\"" + data.rows[i].Id + "\"";
option += ">" + data.rows[i].Id + '-' + data.rows[i].Remark + "</option>"; //动态添加数据
$("select[name='client_id']").append(option);
}
}
}
});
}
</script>
+71 -5
View File
@@ -34,24 +34,37 @@
</select>
</div>
</div>
{{if eq false .https_just_proxy}}
<div class="form-group" id="AutoHttps">
<label class="control-label font-bold">自动HTTPS(301)</label>
<div class="col-sm-10">
<select class="form-control" name="AutoHttps">
<option {{if eq false .h.AutoHttps}}selected{{end}} value="0" langtag="word-no"></option>
<option {{if eq true .h.AutoHttps}}selected{{end}} value="1" langtag="word-yes"></option>
</select>
</div>
</div>
<div class="form-group" id="cert_file">
<label class="control-label font-bold" langtag="word-httpscert"></label>
<div class="col-sm-10">
<input value="{{.h.CertFilePath}}" class="form-control" type="text" name="cert_file_path" placeholder="" langtag="info-unrestricted">
<textarea rows="6" class="form-control" type="text" name="cert_file_path" id="pemText"
placeholder="请将证书文件拖拽或将内容复制粘贴到此处,证书文件格式为:xxxx_example.com.pem。
或者配置证书文件路径。">{{.h.CertFilePath}}</textarea>
</div>
</div>
<div class="form-group" id="key_file">
<label class="control-label font-bold" langtag="word-httpskey"></label>
<div class="col-sm-10">
<input value="{{.h.KeyFilePath}}" class="form-control" type="text" name="key_file_path" placeholder="" langtag="info-unrestricted">
<textarea rows="6" class="form-control" type="text" name="key_file_path" id="pemKey"
placeholder="请将私钥文件拖拽或复制粘贴到此处,证书秘钥格式为:xxxx_example.com.key。
或者配置秘钥文件路径。">{{.h.KeyFilePath}}</textarea>
</div>
</div>
{{end}}
<div class="form-group">
<label class="control-label font-bold" langtag="word-urlroute"></label>
<div class="col-sm-10">
<input value="{{.h.Location}}" class="form-control" type="text" name="location" placeholder="" langtag="info-unrestricted">
<input value="{{.h.Location}}" class="form-control" type="text" name="location" placeholder="" langtag="info-unrestricted">
</div>
</div>
{{if eq true .allow_local_proxy}}
@@ -103,13 +116,66 @@
<script>
$(function () {
if ($("#scheme_select").val() == "all" || $("#scheme_select").val() == "https") {
$("#cert_file").css("display", "block")
$("#key_file").css("display", "block")
$("#AutoHttps").css("display", "block")
} else {
$("#cert_file").css("display", "none")
$("#key_file").css("display", "none")
$("#AutoHttps").css("display", "none")
}
const pemText = document.getElementById("pemText");
const pemKey = document.getElementById("pemKey");
// 阻止浏览器默认打开文件的行为
document.addEventListener("dragover", function(event) {
event.preventDefault();
});
pemText.addEventListener("drop", function(event) {
event.preventDefault();
const file = event.dataTransfer.files[0];
const reader = new FileReader();
reader.onload = function(e) {
pemText.value = e.target.result;
console.log("上传pem")
$('#edit_form').data('bootstrapValidator').updateStatus('pemText', 'NOT_VALIDATED');
$('#edit_form').data('bootstrapValidator').validateField('pemText');
}
reader.readAsText(file);
});
pemKey.addEventListener("drop", function(event) {
event.preventDefault();
const file = event.dataTransfer.files[0];
const reader = new FileReader();
reader.onload = function(e) {
pemKey.value = e.target.result;
$('#edit_form').data('bootstrapValidator').updateStatus('pemKey', 'NOT_VALIDATED');
$('#edit_form').data('bootstrapValidator').validateField('pemKey');
}
reader.readAsText(file);
});
$("#scheme_select").on("change", function () {
if ($("#scheme_select").val() == "all" || $("#scheme_select").val() == "https") {
$("#cert_file").css("display", "block")
$("#key_file").css("display", "block")
$("#AutoHttps").css("display", "block")
} else {
$("#cert_file").css("display", "none")
$("#key_file").css("display", "none")
$("#AutoHttps").css("display", "none")
}
})
})
+5 -2
View File
@@ -88,7 +88,7 @@
halign: 'center',
visible: true,//false表示不显示
formatter: function (value, row, index) {
return row.Client.Id
return row.Client.Id + '-' + row.Client.Remark
}
},
{
@@ -107,7 +107,10 @@
field: 'Host',//域值
title: '<span langtag="word-host"></span>',//标题
halign: 'center',
visible: true//false表示不显示
visible: true,//false表示不显示
formatter: function (value, row, index) {
return "<a href='http://" + row.Host + "' target='_blank'>" + row.Host + "</a>"
}
},
{
field: 'Scheme',//域值
+1 -1
View File
@@ -6,7 +6,7 @@
<h5 langtag="word-connectionport"></h5>
</div>
<div class="ibox-content">
<h1 class="no-margins">{{.p}}</h1>
<h1 class="no-margins">{{.p1}}</h1>
</div>
</div>
</div>
+29 -6
View File
@@ -49,7 +49,9 @@
"limit": params.limit,
"type":{{.type}},
"client_id":{{.client_id}},
"search": params.search
"search": params.search,
"sort": params.sort,
"order": params.order
}
},
search: true,
@@ -74,7 +76,7 @@
+ '<b langtag="word-compress"></b>: ' + row.Client.Cnf.Compress + '&emsp;'
+ '<b langtag="word-basicusername"></b>: ' + row.Client.Cnf.U + '&emsp;'
+ '<b langtag="word-basicpassword"></b>: ' + row.Client.Cnf.P + '&emsp;'
+ '<b langtag="word-ishttp"></b>: ' + row.IsHttp + '&emsp;'
+ '<b langtag="word-protoversion"></b>: ' + row.ProtoVersion + '&emsp;'
if (row.Mode == "p2p") {
return tmp + "<br/><br>"
+ '<b langtag="word-commandaccessp2p"></b>: ' + "<code>./npc{{.win}} -server={{.ip}}:{{.p}} -vkey=" + row.Client.VerifyKey
@@ -97,15 +99,17 @@
field: 'Id',//域值
title: '<span langtag="word-id"></span>',//标题
halign: 'center',
visible: true//false表示不显示
visible: true,//false表示不显示
sortable: true,//启用排序
},
{
field: 'Id',//域值
field: 'ClientId',//域值
title: '<span langtag="word-clientid"></span>',//标题
halign: 'center',
visible: true,//false表示不显示
sortable: true, //启用排序
formatter: function (value, row, index) {
return row.Client.Id
return row.Client.Id + '-' + row.Client.Remark
}
},
{
@@ -118,6 +122,7 @@
field: 'Client.VerifyKey',//域值
title: '<span langtag="word-verifykey"></span>',//标题
halign: 'center',
sortable: true, //启用排序
visible: true//false表示不显示
},
{
@@ -133,13 +138,26 @@
field: 'Port',//域值
title: '<span langtag="word-port"></span>',//标题
halign: 'center',
sortable: true, //启用排序
visible: true//false表示不显示
},
{
field: 'address',//域值
title: '<span langtag="word-accessaddress"></span>',//标题
halign: 'center',
sortable: false, //启用排序
visible: true,//false表示不显示
formatter: function (value, row, index) {
var address = {{.ip}} + ":" + row.Port
return "<a href='http://" + address + "' target='_blank'>" + address + "</a>"
}
},
{
field: 'Target',//域值
title: '<span langtag="word-target"></span>',//标题
halign: 'center',
visible: true,//false表示不显示
sortable: true, //启用排序
formatter: function (value, row, index) {
return row.Target.TargetStr
}
@@ -197,6 +215,7 @@
title: '<span langtag="word-option"></span>',//内容
align: 'center',
halign: 'center',
width: '200px',
visible: true,//false表示不显示
formatter: function (value, row, index) {
btn_group = '<div class="btn-group">'
@@ -209,8 +228,12 @@
}
btn_group += "<a onclick=\"submitform('delete', '{{.web_base_url}}/index/del', {'id':" + row.Id
btn_group += '})" class="btn btn-outline btn-danger"><i class="fa fa-trash"></i></a>'
btn_group += '<a href="{{.web_base_url}}/index/edit?id=' + row.Id
btn_group += '" class="btn btn-outline btn-success"><i class="fa fa-edit"></i></a></div>'
btn_group += '" class="btn btn-outline btn-success"><i class="fa fa-edit"></i></a>'
btn_group += "<a onclick=\"submitform('copy', '{{.web_base_url}}/index/copy', {'id':" + row.Id
btn_group += '})" class="btn btn-outline btn-primary"><i class="fa fa-copy"></i></a></div>'
return btn_group
}
}
+1 -1
View File
@@ -19,7 +19,7 @@
<script src="{{.web_base_url}}/static/js/jquery-3.4.1.min.js"></script>
<script src="{{.web_base_url}}/static/js/bootstrap.min.js"></script>
<!-- Latest compiled and minified Locales -->
<script src="{{.web_base_url}}/static/js/language.js" type="text/javascript"></script>
<script src="{{.web_base_url}}/static/js/language.js?v=20250528" type="text/javascript"></script>
</head>
+1 -1
View File
@@ -19,7 +19,7 @@
<script src="{{.web_base_url}}/static/js/jquery-3.4.1.min.js"></script>
<script src="{{.web_base_url}}/static/js/bootstrap.min.js"></script>
<!-- Latest compiled and minified Locales -->
<script src="{{.web_base_url}}/static/js/language.js" type="text/javascript"></script>
<script src="{{.web_base_url}}/static/js/language.js?v=20250528" type="text/javascript"></script>
</head>
+6 -2
View File
@@ -11,6 +11,7 @@
<!-- Mainly scripts -->
<!-- Latest compiled and minified CSS -->
<link href="{{.web_base_url}}/static/css/toastr.min.css" rel="stylesheet">
<link href="{{.web_base_url}}/static/css/fontawesome.min.css" rel="stylesheet">
<link href="{{.web_base_url}}/static/css/solid.min.css" rel="stylesheet">
<link href="{{.web_base_url}}/static/css/bootstrap.min.css" rel="stylesheet">
@@ -19,6 +20,8 @@
<!-- Latest compiled and minified JavaScript -->
<script src="{{.web_base_url}}/static/js/jquery-3.4.1.min.js"></script>
<script src="{{.web_base_url}}/static/js/clipboard.min.js"></script>
<script src="{{.web_base_url}}/static/js/toastr.min.js"></script>
<script src="{{.web_base_url}}/static/js/popper.min.js"></script>
<script src="{{.web_base_url}}/static/js/bootstrap.min.js"></script>
<script src="{{.web_base_url}}/static/js/bootstrap-table.min.js"></script>
@@ -26,7 +29,8 @@
<script src="{{.web_base_url}}/static/js/echarts.min.js"></script>
<script src="{{.web_base_url}}/static/js/inspinia.js"></script>
<!-- Latest compiled and minified Locales -->
<script src="{{.web_base_url}}/static/js/language.js" type="text/javascript"></script>
<script src="{{.web_base_url}}/static/js/language.js?v=20250528" type="text/javascript"></script>
</head>
@@ -116,7 +120,7 @@
<ul class="nav navbar-top-links navbar-right">
<li>
<span class="m-r-sm text-muted welcome-message"><span langtag="word-welcome"></span>
<a href="https://ehang.io/nps" langtag="application"></a></span>
<a href="https://github.com/yisier/nps" langtag="application"></a></span>
</li>
<li>
<span class="btn-group dropdown">