Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
268e17273e | ||
|
|
840dd2d344 | ||
|
|
3cf64596c6 | ||
|
|
35327cc9a5 | ||
|
|
4d8e4190ba | ||
|
|
2da08e1b55 | ||
|
|
8d9fc4cff6 | ||
|
|
4d380dbdf3 | ||
|
|
d5abf90954 | ||
|
|
e416c76ea8 | ||
|
|
33704b1694 | ||
|
|
491f042b2f | ||
|
|
fd306ce8c3 | ||
|
|
6880898321 | ||
|
|
5578874df7 | ||
|
|
67c362b423 | ||
|
|
b026b46647 | ||
|
|
bfe880a6c6 | ||
|
|
f46332db4a | ||
|
|
5b2fe447b2 | ||
|
|
0301f15628 | ||
|
|
4b278216e5 | ||
|
|
3610de97db | ||
|
|
40a03c1630 | ||
|
|
f1ea585cec | ||
|
|
9647006ed1 | ||
|
|
8c5a6b2f0d | ||
|
|
3991fcb91c | ||
|
|
93e8879bf5 | ||
|
|
0466710f73 | ||
|
|
ef8cab0a36 | ||
|
|
7a9e81c27a | ||
|
|
3f42b58471 | ||
|
|
323d86b49d | ||
|
|
e2226f7d0b | ||
|
|
5094700b66 | ||
|
|
b737535b0f | ||
|
|
7a95fbddbc | ||
|
|
f00d8d1479 | ||
|
|
4550a677db | ||
|
|
f604e8b011 | ||
|
|
a400fccf77 | ||
|
|
87e4af5ba5 | ||
|
|
1d11dd3f85 | ||
|
|
b3e85b6a65 | ||
|
|
c76c4d8257 | ||
|
|
64fcd43be5 | ||
|
|
a7b077af8c | ||
|
|
a4c2addb33 | ||
|
|
dd6493cc66 | ||
|
|
52ce6d265a | ||
|
|
eacc98d18f | ||
|
|
65af658be5 | ||
|
|
a7b2694204 | ||
|
|
abab45785b | ||
|
|
9da00e47bd | ||
|
|
4eea46fa46 | ||
|
|
b7518bfbeb | ||
|
|
a95b534701 | ||
|
|
0a5d50b84d | ||
|
|
22461066a4 | ||
|
|
cd4c9f2aae | ||
|
|
30b115610b | ||
|
|
c971bee96c | ||
|
|
7ea723b578 | ||
|
|
1625187bb1 | ||
|
|
934ceaadca | ||
|
|
bb7fe668b1 | ||
|
|
c385030fc4 | ||
|
|
767860643d | ||
|
|
c20a6db44a | ||
|
|
f423056361 | ||
|
|
86a3cf92b5 | ||
|
|
b28d476081 | ||
|
|
48c8df15e7 | ||
|
|
a31b0ebc95 | ||
|
|
fe86d786f4 | ||
|
|
c48404e3bb | ||
|
|
5daec7195f | ||
|
|
533675b367 | ||
|
|
e547895a9c | ||
|
|
42b7163f5b | ||
|
|
2ceacc6916 | ||
|
|
124273e8d7 | ||
|
|
5a36c88875 | ||
|
|
70e6d2ab45 | ||
|
|
2dc8965cdb | ||
|
|
0d997bbe92 | ||
|
|
f88bbb53cb | ||
|
|
2ae3267049 | ||
|
|
62bbd48b33 | ||
|
|
aa131b0705 | ||
|
|
1510e16e50 | ||
|
|
a3b324c72b | ||
|
|
c959ce13a3 | ||
|
|
4c828f814c | ||
|
|
5a65eebfd3 | ||
|
|
5a3375ce80 | ||
|
|
eb277b414a | ||
|
|
fc4097529f | ||
|
|
375687aa5f | ||
|
|
32504d33af | ||
|
|
bcd429d54f | ||
|
|
2ec87abda9 | ||
|
|
8c2e1b8f6c | ||
|
|
e2195ab966 | ||
|
|
2d0b9132e9 | ||
|
|
5a502115b1 | ||
|
|
a972e0f309 | ||
|
|
b52225937c | ||
|
|
98737f0e9d | ||
|
|
ea67c2bce0 | ||
|
|
7dda047d51 | ||
|
|
b518dbfd58 | ||
|
|
7054a1df0e | ||
|
|
da0d1946c6 | ||
|
|
afff036641 | ||
|
|
9944e60825 | ||
|
|
74ff0c3b44 | ||
|
|
5bb6a09ce2 | ||
|
|
3e9e7cb370 | ||
|
|
3cf6bcbe6e | ||
|
|
8f9375152e | ||
|
|
501012d9bc | ||
|
|
f2b560fa1f | ||
|
|
2b95967820 |
@@ -54,4 +54,7 @@ hs_err_pid*
|
||||
|
||||
**/memo/**
|
||||
|
||||
neutrino-proxy-vuepress/deploy.sh
|
||||
neutrino-proxy-vuepress/deploy.sh
|
||||
.NEUTRINO_PROXY_CLIENT_ID
|
||||
logs
|
||||
**/ixxxk.com/**
|
||||
|
||||
|
After Width: | Height: | Size: 12 KiB |
@@ -34,130 +34,19 @@
|
||||

|
||||

|
||||
|
||||
# 4、项目结构
|
||||
- neutrino-proxy
|
||||
- neutrino-proxy-core 与代理相关的公共常量、编解码器
|
||||
- neutrino-proxy-client 代理客户端项目
|
||||
- neutrino-proxy-server 代理服务端项目
|
||||
- neutrino-proxy-admin 代理监控项目(基于vue-element-admin开发)
|
||||
|
||||
# 5、运行
|
||||
## 5.1、使用keytool工具生成ssl证书, 若不需要ssl加密可跳过
|
||||
```shell
|
||||
keytool -genkey -alias test1 -keyalg RSA -keysize 1024 -validity 3650 -keypass 123456 -storepass 123456 -keystore "./test.jks"
|
||||
```
|
||||
|
||||
## 5.2、修改服务端配置(application.yml)
|
||||
```yml
|
||||
application:
|
||||
name: neutrino-proxy-server
|
||||
|
||||
proxy:
|
||||
protocol:
|
||||
max-frame-length: 2097152
|
||||
length-field-offset: 0
|
||||
length-field-length: 4
|
||||
initial-bytes-to-strip: 0
|
||||
length-adjustment: 0
|
||||
read-idle-time: 60
|
||||
write-idle-time: 40
|
||||
all-idle-time-seconds: 0
|
||||
server:
|
||||
# 服务端端口,用于保持与客户端的连接,非SSL
|
||||
port: 9000
|
||||
# 服务端端口,用于保持与客户端的连接,SSL,需要jks证书文件,若不需要ssl支持,可不配置
|
||||
ssl-port: 9002
|
||||
# 证书密码
|
||||
key-store-password: 123456
|
||||
key-manager-password: 123456
|
||||
# 证书存放路径,若不想打进jar包,可不带classpath:前缀
|
||||
jks-path: classpath:/test.jks
|
||||
data:
|
||||
# 数据库配置(支持mysql)
|
||||
type: sqlite
|
||||
url: jdbc:sqlite:data.db
|
||||
driver-class: org.sqlite.JDBC
|
||||
username:
|
||||
password:
|
||||
```
|
||||
|
||||
## 5.3、启动服务端
|
||||
> java -jar neutrino-proxy-server.jar
|
||||
|
||||
## 5.4、修改客户端配置
|
||||
```yml
|
||||
application:
|
||||
name: neutrino-proxy-client
|
||||
|
||||
proxy:
|
||||
protocol:
|
||||
max-frame-length: 2097152
|
||||
length-field-offset: 0
|
||||
length-field-length: 4
|
||||
initial-bytes-to-strip: 0
|
||||
length-adjustment: 0
|
||||
read-idle-time: 60
|
||||
write-idle-time: 30
|
||||
all-idle-time-seconds: 0
|
||||
client:
|
||||
# ssl证书密码
|
||||
key-store-password: 123456
|
||||
# ssl证书存放位置
|
||||
jks-path: classpath:/test.jks
|
||||
# 服务端ip,若部署到服务器,则配置服务器的ip
|
||||
server-ip: localhost
|
||||
# 服务端端口,若使用ssl,则需要配置为服务端的"ssl-port"
|
||||
server-port: 9000
|
||||
# 是否启用ssl,启用则必须配置ssl相关参数
|
||||
ssl-enable: false
|
||||
```
|
||||
## 5.5、代理示意图
|
||||
# 4、代理示意图
|
||||

|
||||
|
||||
## 5.6、启动客户端
|
||||
### 5.6.1、启动参数直接指定配置
|
||||
> java -jar neutrino-proxy-client.jar serverIp=localhost serverPort=9000 licenseKey=b0a907332b474b25897c4dcb31fc7eb6
|
||||
|
||||
### 5.6.2、启动参数指定外部配置文件
|
||||
> java -jar neutrino-proxy-client.jar config=app.properties
|
||||
|
||||
配置文件格式如下:
|
||||
```
|
||||
neutrino.proxy.client.server-ip=localhost
|
||||
neutrino.proxy.client.server-port=9002
|
||||
neutrino.proxy.client.ssl-enable=true
|
||||
neutrino.proxy.client.key-store-password=123456
|
||||
neutrino.proxy.client.jks-path=classpath:/test.jks
|
||||
neutrino.proxy.client.license-key=b0a907332b474b25897c4dcb31fc7eb6
|
||||
```
|
||||
|
||||
## 5.7、Docker快速启动
|
||||
```shell script
|
||||
# 一键部署前端和后端,客户端按上方部署即可
|
||||
docker run -it -p 9000-9200:9000-9200/tcp -p 8888:8888 -d --name neutrino registry.cn-hangzhou.aliyuncs.com/asgc/aoshiguchen-docker-images:1.64
|
||||
# 如没docker环境,可以一键部署docker环境(centos 7.8)系统
|
||||
curl http://www.wangke666.cn/static/createDocker.sh | bash
|
||||
```
|
||||
|
||||
# 6、演示环境
|
||||
# 5、演示环境
|
||||
> 可使用分配好的游客license试用。服务器带宽较低,仅供学习使用!
|
||||
- 管理后台地址:http://103.163.47.16:9527
|
||||
- 游客账号:visitor/123456
|
||||
|
||||
# 7、未来迭代方向
|
||||
- 优化代码、增强稳定性
|
||||
- 服务端增加管理页面,提供报表、授权、限流等功能
|
||||
- 从项目中分离、孵化出另一个开源项目(neutrino-framework)
|
||||
|
||||
# 8、技术文档
|
||||
- [Aop](./docs/Aop.MD)
|
||||
- [Channel](./docs/Channel.MD)
|
||||
|
||||
# 9、联系我们
|
||||
# 6、联系我们
|
||||
- 微信: yuyunshize
|
||||
- Gitee: https://gitee.com/asgc/neutrino-proxy
|
||||
|
||||
# 10、贡献者列表
|
||||
# 7、贡献者列表
|
||||
<p>
|
||||
<a href="https://gitee.com/zcans" target="_blank">
|
||||
<img src="assets/developer/zcans.png" width="12%">
|
||||
@@ -195,6 +84,12 @@ neutrino.proxy.client.license-key=b0a907332b474b25897c4dcb31fc7eb6
|
||||
<a href="https://gitee.com/zoo-plus" target="_blank">
|
||||
<img src="assets/developer/zoo-plus.png" width="12%">
|
||||
</a>
|
||||
<a href="https://gitee.com/MetalXingxing" target="_blank">
|
||||
<img src="assets/developer/metal.png" width="12%">
|
||||
</a>
|
||||
<a href="https://gitee.com/click33" target="_blank">
|
||||
<img src="assets/developer/click33.png" width="12%">
|
||||
</a>
|
||||
</p>
|
||||
|
||||
# ❤️ 感谢
|
||||
|
||||
|
After Width: | Height: | Size: 350 KiB |
|
After Width: | Height: | Size: 1.0 MiB |
|
After Width: | Height: | Size: 123 KiB |
|
After Width: | Height: | Size: 502 KiB |
@@ -0,0 +1,137 @@
|
||||
# 内网穿透神器NeutrinoProxy 1.9.0版本发布
|
||||
|
||||
## 更新内容
|
||||
> 与1.8.0版本对比,更新内容如下:
|
||||
- 核心功能
|
||||
- 域名映射支持HTTPS
|
||||
- 支持UDP协议代理
|
||||
- 客户端断开连接时,记录日志空指针异常问题修复
|
||||
- 基础优化
|
||||
- 客户端重连逻辑优化,支持配置文件指定重连间隔,是否开启无限重连
|
||||
- 增加对mariadb的支持
|
||||
- 服务端/客户端,支持配置文件、启动参数指定日志级别
|
||||
- 后台端口池管理支持批量删除
|
||||
- 后台下拉选择license、用户支持模糊搜索
|
||||
- 端口映射下拉选择端口支持搜索、分野
|
||||
- 客户端/服务端配置增加心跳日志开关,有需要时开启,方便排查问题
|
||||
- 端口映射HTTP(S)新增打开网页快捷操作,优先使用绑定域名打开
|
||||
|
||||
## 升级须知
|
||||
> 从1.9.0之前的版本升级需要注意:
|
||||
- 在项目`neutrino-proxy-server/src/main/resources/sql`目录下找到mysql/sqlite的增量sql文件`UPDATE-20230922.SQL`,执行更新自己的中微子代理数据库
|
||||
- 参照[官网服务端配置](https://dromara.gitee.io/neutrino-proxy/pages/f2d0f1)调整现有的服务端配置
|
||||
- 参照[官网客户端配置](https://dromara.gitee.io/neutrino-proxy/pages/50ce10)吊证现有的客户端配置
|
||||
- 从[仓库发行版](https://gitee.com/dromara/neutrino-proxy/releases)下载最新版本的客户端(neutrino-proxy-client.jar)、服务端(neutrino-proxy-server.jar、 neutrino-proxy-admin.zip)部署文件。若为服务端是docker镜像部署,则更新镜像重启即可
|
||||
|
||||
## 项目简介
|
||||
- [中微子代理(neutrino-proxy)](https://gitee.com/dromara/neutrino-proxy) 是一款基于netty的内网穿透神器。该项目采用最为宽松的MIT协议,因此您可以对它进行复制、修改、传播并用于任何个人或商业行为。
|
||||
- Gitee地址:https://gitee.com/dromara/neutrino-proxy
|
||||
- 官网地址:http://neutrino-proxy.dromara.org
|
||||
- 服务端管理后台截图:
|
||||
<img src="./home.png" width="100%"/>
|
||||
|
||||
## 主要特点:
|
||||
- 1、流量监控:首页图表、报表管理多维度流量监控。全方位掌握实时、历史代理数据。
|
||||
- 2、用户/License:支持多用户、多客户端使用。后台禁用实时生效。
|
||||
- 3、端口池:对外端口统一管理,支持用户、License独占端口。
|
||||
- 4、端口映射:新增、编辑、删除、禁用实时生效。
|
||||
- 5、Docker:服务端支持Docker一键部署。
|
||||
- 6、SSL证书:支持SSL,保护您的信息安全。
|
||||
- 7、域名映射:支持绑定子域名,方便本地调试三方回调
|
||||
- 8、多协议:支持代理TCP、HTTP(S)、UDP多种协议
|
||||
- 9、采用最为宽松的MIT协议,免去你的后顾之忧
|
||||
|
||||
## 快速使用
|
||||
> 更多使用姿势、细节请通过官网或结尾微信二维码加我备注"中微子代理"入群交流。
|
||||
|
||||
### 1、 部署服务端
|
||||
#### 1.1、 Docker一键部署
|
||||
> 当前最新版本为1.9.0,下面的脚本中,可以使用:`registry.cn-hangzhou.aliyuncs.com/asgc/neutrino-proxy:1.9.0` 指定版本安装,推荐使用`latest`直接安装最新版。
|
||||
|
||||
##### 使用默认sqlite数据库
|
||||
```shell
|
||||
docker run -it -p 9000-9200:9000-9200/tcp -p 8888:8888 \
|
||||
-d --restart=always --name neutrino-proxy \
|
||||
registry.cn-hangzhou.aliyuncs.com/asgc/neutrino-proxy:latest
|
||||
```
|
||||
|
||||
##### 指定自己的mysql数据库
|
||||
- 在服务器上创建目录:/root/neutrino-proxy/config
|
||||
- 在该目录下创建`app.yml`文本文件,并配置如下内容:
|
||||
```yml
|
||||
neutrino:
|
||||
data:
|
||||
db:
|
||||
type: mysql
|
||||
# 自己的数据库实例,创建一个空的名为'neutrino-proxy'的数据库即可,首次启动服务端会自动初始化
|
||||
url: jdbc:mysql://xxxx:3306/neutrino-proxy?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&useAffectedRows=true&useSSL=false
|
||||
driver-class: com.mysql.jdbc.Driver
|
||||
# 数据库帐号
|
||||
username: xxx
|
||||
# 数据库密码
|
||||
password: xxx
|
||||
```
|
||||
- 然后执行如下命令:
|
||||
```shell
|
||||
docker run -it -p 9000-9200:9000-9200/tcp -p 8888:8888 \
|
||||
-v /root/neutrino-proxy/config:/root/neutrino-proxy/config \
|
||||
-d --restart=always --name neutrino \
|
||||
registry.cn-hangzhou.aliyuncs.com/asgc/neutrino-proxy:latest
|
||||
```
|
||||
|
||||
#### 1.2、使用jar包自行部署
|
||||
- 首先确保服务器上已安装java8运行环境
|
||||
- 打开[发行版页面](https://gitee.com/dromara/neutrino-proxy/releases),下载最新的release包:`neutrino-proxy-server.jar`、`neutrino-proxy-admin.zip`
|
||||
- 在服务器上新建部署目录:`/work/projects/neutrino-proxy-server`
|
||||
- 将` neutrino-proxy-server.jar`、`neutrino-proxy-admin.zip`上传至服务器部署目录。
|
||||
- 解压`neutrino-proxy-admin.zip`文件
|
||||
- 执行命令`java -jar neutrino-proxy-server.jar`启动服务端完成部署,默认使用sqlite数据库。
|
||||
- 若需要指定自己的mysql数据库,同样的需要在当前目录下新建`app.yml`文件,文件内容同上。执行命令`java -jar neutrino-proxy-server.jar config=app.yml`启动服务端完成部署
|
||||
- 可参照 https://gitee.com/dromara/neutrino-proxy/blob/master/bin/server_start.sh 使用shell脚本启动服务端。
|
||||
|
||||
### 2、管理后台配置
|
||||
- 服务端部署成功后,访问`http://{服务端IP}:8888`打开后台管理页面。
|
||||
- 使用默认的管理员帐号登录:admin/123456
|
||||
- 打开`代理配置>License管理`页面,可以看到系统已经自动为管理员初始化了一条License记录,复制该`LicenseKey`备用,后续客户端配置需要。
|
||||
- 打开`代理配置>端口映射`页面,可以看到系统已经自动为初始化了几条端口映射。可根据需要自行添加、修改。这里我们以`9101 -> 127.0.0.1:8080`映射为例
|
||||
|
||||
### 3、启动客户端
|
||||
- 首先确保本地已安装java8运行环境
|
||||
- 打开[发行版页面](https://gitee.com/dromara/neutrino-proxy/releases),下载最新的release包:`neutrino-proxy-client.jar`
|
||||
- 在本地`neutrino-proxy-client.jar`同级别目录下新建`app.yml`文件,并配置如下内容:
|
||||
```yml
|
||||
neutrino:
|
||||
proxy:
|
||||
tunnel:
|
||||
# ssl证书密钥(使用jjar包内自带的证书,则此处无需修改)
|
||||
key-store-password: 123456
|
||||
# ssl证书管理密钥(使用jjar包内自带的证书,则此处无需修改。自定义证书,则此处配置对应的路径)
|
||||
jks-path: classpath:/test.jks
|
||||
# 代理服务端IP
|
||||
server-ip: localhost
|
||||
# 代理服务端IP, 若是非ssl端口,则ssl-enable需要配置为false
|
||||
server-port: 9002
|
||||
# 是否启用ssl
|
||||
ssl-enable: true
|
||||
# licenseKey,客户端凭证。此处需要配置刚刚从管理后台复制的LicenseKey
|
||||
license-key: xxxx
|
||||
```
|
||||
- 执行命令`java -jar neutrino-proxy-client.jar`启动客户端
|
||||
- 查看服务端License管理,刷新页面,对应的License在线状态为`在线`,则表明客户端已正常连接。
|
||||
|
||||
### 4、代理验证
|
||||
- 本地启动被代理服务,如:redis、本地web项目、本地mysql等等
|
||||
- 先确保本地能正常访问被代理服务,如果本地都不能访问,不用想代理更不可能!!!
|
||||
- 通过服务端IP+9101(上面License配置的端口映射重的服务端端口)访问本地被代理服务
|
||||
|
||||
## 联系我们
|
||||
笔者时间、能力有限,且开源项目非一朝一夕之事,存在众多问题亦在所难免。使用、学习过程中有任何问题欢迎大家与我联系。
|
||||
|
||||
对项目有什么想法或者建议,可以加我微信拉交流群,或者创建[issues](https://gitee.com/dromara/neutrino-proxy/issues),一起完善项目
|
||||
|
||||
- 微信号:yuyunshize
|
||||
- Email: aoshiguchen@dromara.org
|
||||
- 中微子代理官网:http://neutrino-proxy.dromara.org
|
||||
- 中微子代理仓库:https://gitee.com/dromara/neutrino-proxy
|
||||
- 微信二维码:
|
||||
<img src="MyWeChatQRCode.jpeg" width="100%"/>
|
||||
@@ -1,7 +1,7 @@
|
||||
module.exports = {
|
||||
NODE_ENV: '"development"',
|
||||
ENV_CONFIG: '"dev"',
|
||||
BASE_API: '"http://103.163.47.16:8888"',
|
||||
BASE_API: '"https://neutrino-proxy.asgc.fun/neutrino-proxy-server"',
|
||||
USER_NAME: '"visitor"',
|
||||
USER_PWD: '"123456"'
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
module.exports = {
|
||||
NODE_ENV: '"development"',
|
||||
ENV_CONFIG: '"docker"',
|
||||
BASE_API: '"/"'
|
||||
BASE_API: '"/neutrino-proxy-server"'
|
||||
}
|
||||
|
||||
@@ -14,13 +14,11 @@ export function portPoolList() {
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
export function availablePortList(licenseId) {
|
||||
export function availablePortList(query) {
|
||||
return request({
|
||||
url: '/port-pool/get-available-port-list',
|
||||
method: 'get',
|
||||
params: {
|
||||
licenseId: licenseId
|
||||
}
|
||||
params: query
|
||||
})
|
||||
}
|
||||
|
||||
@@ -60,3 +58,21 @@ export function deletePortPool(id) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export function deleteBatchPortPool(ids) {
|
||||
return request({
|
||||
url: '/port-pool/delete-batch',
|
||||
method: 'post',
|
||||
data: {
|
||||
ids: ids
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export function portAvailable(query) {
|
||||
return request({
|
||||
url: '/port-pool/port-available',
|
||||
method: 'get',
|
||||
params: query
|
||||
})
|
||||
}
|
||||
|
||||
@@ -8,60 +8,68 @@
|
||||
<el-button size="mini" @click="handleCancelClick">{{cancelText}}</el-button>
|
||||
<el-button type="primary" size="mini" @click="handleCommitClick">{{okText}}</el-button>
|
||||
</div>
|
||||
<el-button slot="reference" :type="type" :size="size">{{buttonText}}</el-button>
|
||||
<el-button slot="reference" :type="type" :size="size" :icon="icon" :disabled="disabled">{{buttonText}}</el-button>
|
||||
</el-popover>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
|
||||
export default {
|
||||
name: 'deleteButton',
|
||||
props: {
|
||||
width: {
|
||||
type: Number,
|
||||
default: 160
|
||||
export default {
|
||||
name: 'deleteButton',
|
||||
props: {
|
||||
width: {
|
||||
type: Number,
|
||||
default: 160
|
||||
},
|
||||
buttonText: {
|
||||
type: String,
|
||||
default: '删除'
|
||||
},
|
||||
type: {
|
||||
type: String,
|
||||
default: 'danger'
|
||||
},
|
||||
size: {
|
||||
type: String,
|
||||
default: 'mini'
|
||||
},
|
||||
icon: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
disabled: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
title: {
|
||||
type: String,
|
||||
default: '确定删除吗?'
|
||||
},
|
||||
okText: {
|
||||
type: String,
|
||||
default: '确定'
|
||||
},
|
||||
cancelText: {
|
||||
type: String,
|
||||
default: '取消'
|
||||
}
|
||||
},
|
||||
buttonText: {
|
||||
type: String,
|
||||
default: '删除'
|
||||
data() {
|
||||
return {
|
||||
visible: false
|
||||
}
|
||||
},
|
||||
type: {
|
||||
type: String,
|
||||
default: 'danger'
|
||||
},
|
||||
size: {
|
||||
type: String,
|
||||
default: 'mini'
|
||||
},
|
||||
title: {
|
||||
type: String,
|
||||
default: '确定删除吗?'
|
||||
},
|
||||
okText: {
|
||||
type: String,
|
||||
default: '确定'
|
||||
},
|
||||
cancelText: {
|
||||
type: String,
|
||||
default: '取消'
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
visible: false
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
handleCancelClick() {
|
||||
this.visible = false
|
||||
this.$emit('handleCancelClick')
|
||||
},
|
||||
handleCommitClick() {
|
||||
this.visible = false
|
||||
this.$emit('handleCommitClick')
|
||||
methods: {
|
||||
handleCancelClick() {
|
||||
this.visible = false
|
||||
this.$emit('handleCancelClick')
|
||||
},
|
||||
handleCommitClick() {
|
||||
this.visible = false
|
||||
this.$emit('handleCommitClick')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style rel="stylesheet/scss" lang="scss" scoped>
|
||||
|
||||
@@ -0,0 +1,168 @@
|
||||
<!--
|
||||
采用github上面的开源组件https://github.com/johnhom1024/vue-load-select
|
||||
不过有个bug,就是没办法展示下拉的箭头,目前修复的方式:等dom加载完毕后,补充箭头的class
|
||||
参考:https://blog.csdn.net/weixin_42381896/article/details/122258563
|
||||
-->
|
||||
<template>
|
||||
<el-select
|
||||
ref="selectLoadMore"
|
||||
:value="value"
|
||||
v-loadmore="loadMore"
|
||||
@focus="focus"
|
||||
@clear="clear"
|
||||
filterable
|
||||
remote
|
||||
:filter-method="handleSearch"
|
||||
:loading="loading"
|
||||
clearable
|
||||
v-bind="$attrs"
|
||||
v-on="$listeners"
|
||||
>
|
||||
<el-option
|
||||
v-for="option in data"
|
||||
:label="option[dictLabel]"
|
||||
:value="option[dictValue]"
|
||||
:key="option.value"
|
||||
></el-option>
|
||||
<!-- 此处加载中的value可以随便设置,只要不与其他数据重复即可 -->
|
||||
<el-option
|
||||
v-if="hasMore"
|
||||
disabled
|
||||
label="加载中..."
|
||||
value="-1" />
|
||||
<!--补充页面无数据时,显示无数据的效果-->
|
||||
<el-option
|
||||
v-if="!hasMore && data.length==0"
|
||||
disabled
|
||||
label="暂无数据"
|
||||
value="-2" />
|
||||
</el-select>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: "SelectLoadMore",
|
||||
props: {
|
||||
value: {
|
||||
default: null
|
||||
},
|
||||
// 列表数据
|
||||
data: {
|
||||
type: Array,
|
||||
default: () => []
|
||||
},
|
||||
dictLabel: {
|
||||
type: String,
|
||||
default: "label"
|
||||
},
|
||||
dictValue: {
|
||||
type: String,
|
||||
default: "value"
|
||||
},
|
||||
// 调用页数的接口
|
||||
request: {
|
||||
type: Function,
|
||||
default: () => {
|
||||
}
|
||||
},
|
||||
// 传入的页码
|
||||
page: {
|
||||
type: [Number, String],
|
||||
default: 1
|
||||
},
|
||||
// 是否还有更多数据
|
||||
hasMore: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
}
|
||||
},
|
||||
directives: {
|
||||
// 这里实现一个组件内部的自定义指令
|
||||
loadmore: {
|
||||
// 指令的定义
|
||||
bind(el, binding) {
|
||||
const SELECTWRAP = el.querySelector(
|
||||
".el-select-dropdown .el-select-dropdown__wrap"
|
||||
);
|
||||
if (!SELECTWRAP) {
|
||||
throw new Error('获取不到"el-select-dropdown__wrap"节点');
|
||||
}
|
||||
SELECTWRAP.addEventListener("scroll", () => {
|
||||
// scrollTop 这里可能因为浏览器缩放存在小数点的情况,导致了滚动到底部时
|
||||
// scrollHeight 减去滚动到底部时的scrollTop ,依然大于clientHeight 导致无法请求更多数据
|
||||
// 这里将scrollTop向上取整 保证滚到底部时,触发调用
|
||||
const CONDITION =
|
||||
SELECTWRAP.scrollHeight -
|
||||
Math.ceil(SELECTWRAP.scrollTop) <=
|
||||
SELECTWRAP.clientHeight;
|
||||
// el.scrollTop !== 0 当输入时,如果搜索结果很少,以至于没看到滚动条,那么此时的CONDITION计算结果是true,会执行bind.value(),此时不应该执行,否则搜索结果不匹配
|
||||
if (CONDITION && SELECTWRAP.scrollTop !== 0) {
|
||||
binding.value();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
keyword: "", // 存储关键字用
|
||||
loading: false
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
// 请求下一页的数据
|
||||
loadMore() {
|
||||
// 如果没有更多数据,则不请求
|
||||
if (!this.hasMore) {
|
||||
return;
|
||||
}
|
||||
// 如果intercept属性为true则不请求数据,
|
||||
if (this.loadMore.intercept) {
|
||||
return;
|
||||
}
|
||||
this.loadMore.intercept = true;
|
||||
this.request({
|
||||
page: this.page + 1,
|
||||
more: true,
|
||||
keyword: this.keyword
|
||||
}).then(() => {
|
||||
this.loadMore.intercept = false;
|
||||
});
|
||||
},
|
||||
// 选中下拉框没有数据时,自动请求第一页的数据
|
||||
focus() {
|
||||
if (!this.data.length) {
|
||||
this.request({page: 1});
|
||||
}
|
||||
},
|
||||
handleSearch(keyword) {
|
||||
this.keyword = keyword;
|
||||
this.loading = true;
|
||||
console.log(keyword);
|
||||
this.request({page: 1, keyword: keyword}).then(() => {
|
||||
this.loading = false;
|
||||
});
|
||||
},
|
||||
// 删除选中时,如果请求了关键字,则清除关键字再请求第一页的数据
|
||||
clear() {
|
||||
if (this.keyword) {
|
||||
this.keyword = "";
|
||||
this.request({page: 1});
|
||||
}
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.$nextTick(function () {
|
||||
// github代码有个bug,下拉的箭头无法加载的问题,需要等dom页面加载完毕后,添加箭头的class
|
||||
let rulesDom = this.$refs["selectLoadMore"].$el.querySelector(
|
||||
".el-input .el-input__suffix .el-input__suffix-inner .el-input__icon"
|
||||
);// 找到dom
|
||||
rulesDom.classList.add("el-icon-arrow-up");// 对dom新增class
|
||||
})
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
||||
@@ -97,10 +97,12 @@ export default {
|
||||
readings: 'Readings',
|
||||
status: 'Status',
|
||||
actions: 'Actions',
|
||||
access: 'Access',
|
||||
edit: 'Edit',
|
||||
publish: 'Publish',
|
||||
draft: 'Draft',
|
||||
delete: 'Delete',
|
||||
deleteBatch: 'DeleteBatch',
|
||||
cancel: 'Cancel',
|
||||
confirm: 'Confirm',
|
||||
portOrRange: 'example: 3306 or 1000-2000'
|
||||
|
||||
@@ -117,10 +117,13 @@ export default {
|
||||
readings: '阅读数',
|
||||
status: '状态',
|
||||
actions: '操作',
|
||||
access: '访问',
|
||||
openWebPage: '打开网页',
|
||||
edit: '编辑',
|
||||
publish: '发布',
|
||||
draft: '草稿',
|
||||
delete: '删除',
|
||||
deleteBatch: '批量删除',
|
||||
cancel: '取 消',
|
||||
confirm: '确 定',
|
||||
userId: '用户ID',
|
||||
|
||||
@@ -50,12 +50,11 @@ export default {
|
||||
this.chartDom = document.getElementById(this.chartId)
|
||||
this.myChart = echarts.init(this.chartDom)
|
||||
const seriesList = []
|
||||
const legendList = []
|
||||
this.data.list && this.data.list.forEach((item, index) => {
|
||||
seriesList.push({
|
||||
name: item.name,
|
||||
type: 'line',
|
||||
stack: 'Total',
|
||||
// stack: 'Total',
|
||||
data: item.value,
|
||||
areaStyle: {
|
||||
normal: {
|
||||
@@ -74,7 +73,6 @@ export default {
|
||||
},
|
||||
smooth: true
|
||||
})
|
||||
legendList.push(item.name)
|
||||
})
|
||||
|
||||
const option = {
|
||||
@@ -87,13 +85,13 @@ export default {
|
||||
formatter: (value) => {
|
||||
let title = this.data.text + '<br/>'
|
||||
value.forEach(item => {
|
||||
title = title + item.marker + item.seriesName + ' : ' + this.data.list[item.seriesIndex].label[item.dataIndex] + '<br/>'
|
||||
title = title + item.marker + item.seriesName + ' : ' + getSizeDescByByteCount(item.data) + '<br/>'
|
||||
})
|
||||
return title
|
||||
}
|
||||
},
|
||||
legend: {
|
||||
data: legendList,
|
||||
data: this.data.legendList,
|
||||
left: 'right'
|
||||
},
|
||||
grid: {
|
||||
|
||||
@@ -70,37 +70,19 @@ export default {
|
||||
})
|
||||
},
|
||||
getChartData(last7dFlow) {
|
||||
const title = []
|
||||
const downFlowDesc = []
|
||||
const totalFlowDesc = []
|
||||
const upFlowDesc = []
|
||||
last7dFlow.dataList.forEach(item => {
|
||||
title.push(item.dateStr)
|
||||
totalFlowDesc.push(item.totalFlowDesc)
|
||||
downFlowDesc.push(item.downFlowDesc)
|
||||
upFlowDesc.push(item.upFlowDesc)
|
||||
})
|
||||
const list = []
|
||||
last7dFlow.seriesList.forEach(item => {
|
||||
let label = []
|
||||
if (item.seriesName.indexOf('上') > -1) {
|
||||
label = upFlowDesc
|
||||
} else if (item.seriesName.indexOf('下') > -1) {
|
||||
label = downFlowDesc
|
||||
} else if (item.seriesName.indexOf('总') > -1) {
|
||||
label = totalFlowDesc
|
||||
}
|
||||
list.push({
|
||||
name: item.seriesName,
|
||||
value: item.seriesData,
|
||||
label: label
|
||||
value: item.seriesData
|
||||
})
|
||||
})
|
||||
return {
|
||||
text: '流量监控',
|
||||
subtext: `最近${last7dFlow.dataList.length || 0}天流量监控`,
|
||||
title: title,
|
||||
list: list
|
||||
title: last7dFlow.xDate,
|
||||
list: list,
|
||||
legendList: last7dFlow.legendData
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<div class="app-container calendar-list-container">
|
||||
<div class="filter-container">
|
||||
<el-select v-model="listQuery.userId" placeholder="请选择用户" clearable>
|
||||
<el-select v-model="listQuery.userId" placeholder="请选择用户" filterable clearable>
|
||||
<el-option v-for="item in userList" :key="item.id" :label="item.name" :value="item.id"/>
|
||||
</el-select>
|
||||
<el-select v-model="listQuery.isOnline" placeholder="请选择在线状态" clearable>
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
<template>
|
||||
<div class="app-container calendar-list-container">
|
||||
<div class="filter-container" style="display:flex">
|
||||
<el-select v-model="listQuery.userId" placeholder="请选择用户" clearable style="margin-right:10px;width: 120px;">
|
||||
<el-select v-model="listQuery.userId" placeholder="请选择用户" filterable clearable style="margin-right:10px;width: 120px;">
|
||||
<el-option v-for="item in userList" :key="item.loginName" :label="item.name" :value="item.id" />
|
||||
</el-select>
|
||||
<el-select v-model="listQuery.licenseId" placeholder="请选择license" clearable style="margin-right:10px;width: 135px;">
|
||||
<el-select v-model="listQuery.licenseId" placeholder="请选择license" filterable clearable style="margin-right:10px;width: 135px;">
|
||||
<el-option v-for="item in licenseList" :key="item.key" :label="item.name" :value="item.id" />
|
||||
</el-select>
|
||||
<el-select v-model="listQuery.protocal" placeholder="请选择协议" clearable style="margin-right:10px;width: 120px;">
|
||||
@@ -90,11 +90,15 @@
|
||||
<el-tag :type="scope.row.isOnline | statusFilter">{{ scope.row.isOnline | isOnlineName }}</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column align="center" :label="$t('table.actions')" width="230" class-name="small-padding fixed-width">
|
||||
<el-table-column class-name="status-col" :label="$t('table.access')" width="120">
|
||||
<template slot-scope="scope">
|
||||
<el-button size="mini" v-if="(scope.row.protocal === 'HTTP' || scope.row.protocal === 'HTTP(S)')" @click="handleOpenWebPage(scope.row)">{{$t('table.openWebPage')}}</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column align="center" :label="$t('table.actions')" width="320" class-name="small-padding fixed-width">
|
||||
<template slot-scope="scope">
|
||||
<el-button type="primary" size="mini" @click="handleUpdate(scope.row)">{{ $t('table.edit') }}</el-button>
|
||||
<el-button v-if="scope.row.enable == '1'" size="mini" type="danger" @click="handleModifyStatus(scope.row, 2)">{{
|
||||
$t('table.disable') }}</el-button>
|
||||
<el-button v-if="scope.row.enable == '1'" size="mini" type="danger" @click="handleModifyStatus(scope.row, 2)">{{$t('table.disable')}}</el-button>
|
||||
<el-button v-if="scope.row.enable == '2'" size="mini" type="success"
|
||||
@click="handleModifyStatus(scope.row, 1)">{{ $t('table.enable') }}</el-button>
|
||||
<!-- <el-button size="mini" type="danger" @click="handleDelete(scope.row,'deleted')">{{$t('table.delete')}}</el-button>-->
|
||||
@@ -142,11 +146,16 @@
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('服务端端口')" prop="serverPort">
|
||||
<el-select style="width: 280px;" class="filter-item" v-model="temp.serverPort" placeholder="请选择">
|
||||
<el-option v-for="item in serverPortList" :key="item.port" :label="item.port" :value="item.port">
|
||||
</el-option>
|
||||
</el-select>
|
||||
<el-form-item :label="$t('服务端端口')" prop="serverPort" >
|
||||
<load-select style="width: 280px;" class="filter-item"
|
||||
v-model="temp.serverPort"
|
||||
:data="serverPortList"
|
||||
:page="loadServerPortQuery.page"
|
||||
:hasMore="more"
|
||||
:clearable="false"
|
||||
:dictLabel="'port'"
|
||||
:dictValue="'port'"
|
||||
:request="loadServerPort"/>
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('客户端IP')" prop="clientIp">
|
||||
<el-input v-model="temp.clientIp"></el-input>
|
||||
@@ -154,11 +163,19 @@
|
||||
<el-form-item :label="$t('客户端端口')" prop="clientPort">
|
||||
<el-input v-model="temp.clientPort"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('域名')" prop="subdomain" v-if="temp.protocal === 'HTTP' && domainName && domainName != ''">
|
||||
<el-form-item :label="$t('域名')" prop="subdomain" v-if="(temp.protocal === 'HTTP' || temp.protocal === 'HTTP(S)') && domainName && domainName != ''">
|
||||
<el-input v-model="temp.subdomain">
|
||||
<template slot="append">.{{ domainName }}</template>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('响应数量')" prop="proxyResponses" v-if="temp.protocal === 'UDP'">
|
||||
<el-input v-model="temp.proxyResponses"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('超时时间')" prop="proxyTimeoutMs" v-if="temp.protocal === 'UDP'">
|
||||
<el-input v-model="temp.proxyTimeoutMs">
|
||||
<template slot="append">毫秒</template>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('描述')" prop="description">
|
||||
<el-input v-model="temp.description"></el-input>
|
||||
</el-form-item>
|
||||
@@ -187,7 +204,7 @@
|
||||
|
||||
<script>
|
||||
import { fetchList, createUserPortMapping, updateUserPortMapping, updateEnableStatus, deletePortMapping } from '@/api/portMapping'
|
||||
import { portPoolList, availablePortList } from '@/api/portPool'
|
||||
import { availablePortList, portAvailable } from '@/api/portPool'
|
||||
import { licenseList, licenseAuthList } from '@/api/license'
|
||||
import { protocalList } from '@/api/protocal'
|
||||
import { userList } from '@/api/user'
|
||||
@@ -196,6 +213,8 @@ import waves from '@/directive/waves' // 水波纹指令
|
||||
import { parseTime } from '@/utils'
|
||||
import ButtonPopover from '../../components/Button/buttonPopover'
|
||||
import DropdownTable from '../../components/Dropdown/DropdownTable'
|
||||
// 下拉选择加载组件
|
||||
import loadSelect from "@/components/Select/SelectLoadMore";
|
||||
|
||||
const calendarTypeOptions = [
|
||||
{ key: 'CN', display_name: 'China' },
|
||||
@@ -217,9 +236,22 @@ export default {
|
||||
},
|
||||
components: {
|
||||
DropdownTable,
|
||||
ButtonPopover
|
||||
ButtonPopover,
|
||||
loadSelect
|
||||
},
|
||||
data() {
|
||||
const isPortAvailable = (rule, value, callback) => {
|
||||
if (value != null) {
|
||||
const param = { port: value, portMappingId: this.temp.id }
|
||||
portAvailable(param).then(res => {
|
||||
if (!res.data.data) {
|
||||
return callback(new Error('该端口被占用'))
|
||||
} else {
|
||||
callback()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
return {
|
||||
tableKey: 0,
|
||||
list: null,
|
||||
@@ -257,7 +289,9 @@ export default {
|
||||
serverPort: undefined,
|
||||
clientIp: undefined,
|
||||
clientPort: undefined,
|
||||
protocal: undefined
|
||||
protocal: undefined,
|
||||
proxyResponses: undefined,
|
||||
proxyTimeoutMs: undefined
|
||||
},
|
||||
selectObj: {
|
||||
statusOptions: [{ label: '启用', value: 1 }, { label: '禁用', value: 2 }],
|
||||
@@ -273,7 +307,9 @@ export default {
|
||||
pvData: [],
|
||||
rules: {
|
||||
licenseId: [{ required: true, message: '请选择License', trigger: 'blur,change' }],
|
||||
serverPort: [{ required: true, message: '请输入服务端端口', trigger: 'blur' }],
|
||||
serverPort: [{ required: true, message: '请输入服务端端口', trigger: 'blur' },
|
||||
// { validator: isPortAvailable, trigger: 'change' }
|
||||
],
|
||||
clientIp: [{ required: true, message: '请输入客户端IP', trigger: 'blur' }],
|
||||
clientPort: [{ required: true, message: '请输入客户端端口', trigger: 'blur' }],
|
||||
protocal: [{ required: true, message: '请选择协议', trigger: 'blur' }]
|
||||
@@ -282,7 +318,13 @@ export default {
|
||||
countryColumns: [
|
||||
{ prop: 'userName', label: '用户名', align: 'center' },
|
||||
{ prop: 'name', label: 'License', align: 'center' }
|
||||
]
|
||||
],
|
||||
loadServerPortQuery:{ //下拉框加载数据请求参数
|
||||
page:1,
|
||||
size:50,
|
||||
licenseId:null,
|
||||
},
|
||||
more: true,
|
||||
}
|
||||
},
|
||||
filters: {
|
||||
@@ -343,15 +385,9 @@ export default {
|
||||
this.domainName = response.data.data
|
||||
})
|
||||
},
|
||||
getPortPoolList() {
|
||||
portPoolList().then(response => {
|
||||
this.serverPortList = response.data.data
|
||||
})
|
||||
},
|
||||
getAvailablePortList(licenseId) {
|
||||
availablePortList(licenseId).then(response => {
|
||||
this.serverPortList = response.data.data
|
||||
})
|
||||
this.loadServerPortQuery.licenseId = licenseId;
|
||||
this.serverPortList = []; //清掉数据
|
||||
},
|
||||
getAllUserList() {
|
||||
userList().then(response => {
|
||||
@@ -405,9 +441,13 @@ export default {
|
||||
serverPort: undefined,
|
||||
clientIp: '127.0.0.1',
|
||||
clientPort: undefined,
|
||||
userId: undefined
|
||||
userId: undefined,
|
||||
proxyResponses: undefined,
|
||||
proxyTimeoutMs: undefined
|
||||
}
|
||||
this.serverPortList = []
|
||||
this.loadServerPortQuery.licenseId = null;
|
||||
this.more = true;
|
||||
},
|
||||
handleCreate() {
|
||||
this.resetTemp()
|
||||
@@ -435,6 +475,13 @@ export default {
|
||||
}
|
||||
})
|
||||
},
|
||||
handleOpenWebPage(row) {
|
||||
let url = location.protocol + '//' + location.hostname + ':' + row.serverPort
|
||||
if (row.domain) {
|
||||
url = location.protocol + '//' + row.domain
|
||||
}
|
||||
open(url)
|
||||
},
|
||||
handleUpdate(row) {
|
||||
this.temp = Object.assign({}, row) // copy obj
|
||||
this.temp.timestamp = new Date(this.temp.timestamp)
|
||||
@@ -526,6 +573,36 @@ export default {
|
||||
return v[j]
|
||||
}
|
||||
}))
|
||||
},
|
||||
// 传入给load-select组件的函数
|
||||
loadServerPort({page = 1, more = false, keyword = ""} = {}) {
|
||||
if(this.loadServerPortQuery.licenseId==null || this.loadServerPortQuery.licenseId==''){
|
||||
this.more = false;
|
||||
this.$message({
|
||||
message: '请先选择License',
|
||||
type: 'warning'
|
||||
})
|
||||
return ;
|
||||
}
|
||||
return new Promise(resolve => {
|
||||
this.loadServerPortQuery.page = page;
|
||||
this.loadServerPortQuery.keyword = keyword;
|
||||
// 访问后端接口API
|
||||
availablePortList(this.loadServerPortQuery).then(res => {
|
||||
let result = res.data;
|
||||
if (more) {
|
||||
this.serverPortList = [...this.serverPortList, ...result.data.records];
|
||||
} else {
|
||||
this.serverPortList = result.data.records;
|
||||
}
|
||||
|
||||
// this.loadServerPortQuery.page = result.data.current;
|
||||
let {total, current, size} = result.data;
|
||||
this.more = page * size < total;
|
||||
this.loadServerPortQuery.page = current;
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,10 +6,13 @@
|
||||
</el-select>
|
||||
<el-button class="filter-item" type="primary" v-waves icon="el-icon-search" @click="handleFilter">{{$t('table.search')}}</el-button>
|
||||
<el-button class="filter-item" style="margin-left: 10px;" @click="handleCreate" type="primary" icon="el-icon-edit">{{$t('table.add')}}</el-button>
|
||||
<button-popover class="filter-item" style="margin-left: 10px;" size="medium" icon="el-icon-delete"
|
||||
:buttonText="$t('table.deleteBatch')" :disabled="checkBoxData.length==0" @handleCommitClick="handleDeleteBatch" />
|
||||
</div>
|
||||
|
||||
<el-table :key='tableKey' :data="list" v-loading="listLoading" element-loading-text="给我一点时间" border fit highlight-current-row
|
||||
style="width: 100%">
|
||||
style="width: 100%" @selection-change="onTableRowChange">
|
||||
<el-table-column align="center" width="40" type="selection" />
|
||||
<el-table-column align="center" :label="$t('table.id')" width="120">
|
||||
<template slot-scope="scope">
|
||||
<span>{{scope.row.id}}</span>
|
||||
@@ -92,7 +95,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { createPortPool, deletePortPool, fetchList, updateEnableStatus, updatePortPool } from '@/api/portPool'
|
||||
import { createPortPool, deletePortPool, deleteBatchPortPool, fetchList, updateEnableStatus, updatePortPool } from '@/api/portPool'
|
||||
import { portGroupList } from '@/api/portGroup'
|
||||
import waves from '@/directive/waves' // 水波纹指令
|
||||
import { parseTime } from '@/utils'
|
||||
@@ -157,7 +160,8 @@ const calendarTypeOptions = [
|
||||
rules: {
|
||||
port: [{ required: true, message: '端口必填', trigger: 'blur' }]
|
||||
},
|
||||
downloadLoading: false
|
||||
downloadLoading: false,
|
||||
checkBoxData:[], //表单勾选的行
|
||||
}
|
||||
},
|
||||
filters: {
|
||||
@@ -320,6 +324,24 @@ const calendarTypeOptions = [
|
||||
return v[j]
|
||||
}
|
||||
}))
|
||||
},
|
||||
onTableRowChange(val){ //表单勾选后赋值
|
||||
this.checkBoxData = val
|
||||
},
|
||||
handleDeleteBatch(){ //批量删除操作
|
||||
let ids = []
|
||||
this.checkBoxData.forEach(item => {ids.push(item.id)})
|
||||
deleteBatchPortPool(ids).then(response => {
|
||||
if (response.data.code === 0) {
|
||||
this.$notify({
|
||||
title: '成功',
|
||||
message: '删除成功',
|
||||
type: 'success',
|
||||
duration: 2000
|
||||
})
|
||||
this.getList()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
<filtering>false</filtering>
|
||||
|
||||
<excludes>
|
||||
<exclude>app-*.yml</exclude>
|
||||
<exclude>app-dev.yml</exclude>
|
||||
</excludes>
|
||||
</resource>
|
||||
</resources>
|
||||
|
||||
@@ -1,25 +1,35 @@
|
||||
package org.dromara.neutrinoproxy.client;
|
||||
|
||||
import ch.qos.logback.classic.Level;
|
||||
import ch.qos.logback.classic.Logger;
|
||||
import ch.qos.logback.classic.LoggerContext;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.noear.solon.Solon;
|
||||
import org.noear.solon.SolonApp;
|
||||
import org.noear.solon.annotation.SolonMain;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author: aoshiguchen
|
||||
* @date: 2022/6/16
|
||||
*/
|
||||
@Slf4j
|
||||
@SolonMain
|
||||
public class ProxyClient {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Solon.start(ProxyClient.class, args, app -> {
|
||||
setAlias("neutrino.proxy.client.serverIp", "serverIp");
|
||||
setAlias("neutrino.proxy.client.serverPort", "serverPort");
|
||||
setAlias("neutrino.proxy.client.sslEnable", "sslEnable");
|
||||
setAlias("neutrino.proxy.client.jksPath", "jksPath");
|
||||
setAlias("neutrino.proxy.client.keyStorePassword", "keyStorePassword");
|
||||
setAlias("neutrino.proxy.client.licenseKey", "licenseKey");
|
||||
setAlias("neutrino.proxy.tunnel.serverIp", "serverIp");
|
||||
setAlias("neutrino.proxy.tunnel.serverPort", "serverPort");
|
||||
setAlias("neutrino.proxy.tunnel.sslEnable", "sslEnable");
|
||||
setAlias("neutrino.proxy.tunnel.jksPath", "jksPath");
|
||||
setAlias("neutrino.proxy.tunnel.keyStorePassword", "keyStorePassword");
|
||||
setAlias("neutrino.proxy.tunnel.licenseKey", "licenseKey");
|
||||
// 设置日志级别
|
||||
setLogLevel(app);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -34,4 +44,21 @@ public class ProxyClient {
|
||||
Solon.cfg().put(key, val);
|
||||
}
|
||||
}
|
||||
|
||||
private static void setLogLevel(SolonApp app) {
|
||||
String loggerLevel = app.cfg().get("neutrino.proxy.logger.level");
|
||||
if (StringUtils.isBlank(loggerLevel)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
Level level = Level.toLevel(loggerLevel);
|
||||
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
|
||||
for (Logger logger : loggerContext.getLoggerList()) {
|
||||
logger.setLevel(level);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("logger level set failed", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2022 aoshiguchen
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package org.dromara.neutrinoproxy.client.config;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author: aoshiguchen
|
||||
* @date: 2022/10/18
|
||||
*/
|
||||
@Data
|
||||
public class CustomConfig {
|
||||
private String jksPath;
|
||||
private String serverIp;
|
||||
private Integer serverPort;
|
||||
private Boolean sslEnable;
|
||||
private String licenseKey;
|
||||
}
|
||||
@@ -14,6 +14,8 @@ import org.noear.solon.annotation.Inject;
|
||||
public class ProxyConfig {
|
||||
@Inject("${neutrino.proxy.protocol}")
|
||||
private Protocol protocol;
|
||||
@Inject("${neutrino.proxy.tunnel}")
|
||||
private Tunnel tunnel;
|
||||
@Inject("${neutrino.proxy.client}")
|
||||
private Client client;
|
||||
|
||||
@@ -30,7 +32,7 @@ public class ProxyConfig {
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Client {
|
||||
public static class Tunnel {
|
||||
private String keyStorePassword;
|
||||
private String jksPath;
|
||||
private String serverIp;
|
||||
@@ -39,5 +41,34 @@ public class ProxyConfig {
|
||||
private Integer obtainLicenseInterval;
|
||||
private String licenseKey;
|
||||
private Integer threadCount;
|
||||
private String clientId;
|
||||
private Boolean transferLogEnable;
|
||||
private Boolean heartbeatLogEnable;
|
||||
private Reconnection reconnection;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Client {
|
||||
// private Tcp tcp;
|
||||
private Udp udp;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Reconnection {
|
||||
private Integer intervalSeconds;
|
||||
private Boolean unlimited;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Tcp {
|
||||
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Udp {
|
||||
private Integer bossThreadCount;
|
||||
private Integer workThreadCount;
|
||||
private String puppetPortRange;
|
||||
private Boolean transferLogEnable;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,17 @@
|
||||
package org.dromara.neutrinoproxy.client.config;
|
||||
|
||||
import org.dromara.neutrinoproxy.core.ProxyDataTypeEnum;
|
||||
import org.dromara.neutrinoproxy.core.ProxyMessage;
|
||||
import org.dromara.neutrinoproxy.core.ProxyMessageHandler;
|
||||
import io.netty.channel.ChannelInitializer;
|
||||
import io.netty.channel.ChannelOption;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
import io.netty.channel.nio.NioEventLoopGroup;
|
||||
import io.netty.channel.socket.SocketChannel;
|
||||
import io.netty.channel.socket.nio.NioDatagramChannel;
|
||||
import io.netty.channel.socket.nio.NioSocketChannel;
|
||||
import io.netty.handler.logging.LoggingHandler;
|
||||
import io.netty.handler.timeout.IdleStateHandler;
|
||||
import org.dromara.neutrinoproxy.client.core.*;
|
||||
import org.dromara.neutrinoproxy.client.util.ProxyUtil;
|
||||
import org.dromara.neutrinoproxy.core.*;
|
||||
import org.dromara.neutrinoproxy.core.dispatcher.DefaultDispatcher;
|
||||
import org.dromara.neutrinoproxy.core.dispatcher.Dispatcher;
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
@@ -10,8 +19,10 @@ import io.netty.channel.ChannelHandlerContext;
|
||||
import org.noear.solon.Solon;
|
||||
import org.noear.solon.annotation.Bean;
|
||||
import org.noear.solon.annotation.Configuration;
|
||||
import org.noear.solon.annotation.Inject;
|
||||
import org.noear.solon.core.bean.LifecycleBean;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -25,20 +36,172 @@ public class ProxyConfiguration implements LifecycleBean {
|
||||
@Override
|
||||
public void start() throws Throwable {
|
||||
List<ProxyMessageHandler> list = Solon.context().getBeansOfType(ProxyMessageHandler.class);
|
||||
Dispatcher<ChannelHandlerContext, ProxyMessage> dispatcher = new DefaultDispatcher<>("消息调度器", list,
|
||||
Dispatcher<ChannelHandlerContext, ProxyMessage> dispatcher = new DefaultDispatcher<>("MessageDispatcher", list,
|
||||
proxyMessage -> ProxyDataTypeEnum.of((int)proxyMessage.getType()) == null ?
|
||||
null : ProxyDataTypeEnum.of((int)proxyMessage.getType()).getName());
|
||||
Solon.context().wrapAndPut(Dispatcher.class, dispatcher);
|
||||
}
|
||||
|
||||
@Bean("bootstrap")
|
||||
public Bootstrap bootstrap() {
|
||||
return new Bootstrap();
|
||||
@Bean("tunnelWorkGroup")
|
||||
public NioEventLoopGroup tunnelWorkGroup(@Inject ProxyConfig proxyConfig) {
|
||||
return new NioEventLoopGroup(proxyConfig.getTunnel().getThreadCount());
|
||||
}
|
||||
|
||||
@Bean("tcpRealServerWorkGroup")
|
||||
public NioEventLoopGroup tcpRealServerWorkGroup(@Inject ProxyConfig proxyConfig) {
|
||||
// 暂时先公用此配置
|
||||
return new NioEventLoopGroup(proxyConfig.getTunnel().getThreadCount());
|
||||
}
|
||||
|
||||
@Bean("udpServerGroup")
|
||||
public NioEventLoopGroup udpServerGroup(@Inject ProxyConfig proxyConfig) {
|
||||
// 暂时先公用此配置
|
||||
return new NioEventLoopGroup(proxyConfig.getClient().getUdp().getBossThreadCount());
|
||||
}
|
||||
|
||||
@Bean("udpWorkGroup")
|
||||
public NioEventLoopGroup udpWorkGroup(@Inject ProxyConfig proxyConfig) {
|
||||
// 暂时先公用此配置
|
||||
return new NioEventLoopGroup(proxyConfig.getClient().getUdp().getWorkThreadCount());
|
||||
}
|
||||
|
||||
@Bean("cmdTunnelBootstrap")
|
||||
public Bootstrap cmdTunnelBootstrap(@Inject ProxyConfig proxyConfig,
|
||||
@Inject("tunnelWorkGroup") NioEventLoopGroup tunnelWorkGroup) {
|
||||
Bootstrap bootstrap = new Bootstrap();
|
||||
bootstrap.group(tunnelWorkGroup);
|
||||
bootstrap.channel(NioSocketChannel.class);
|
||||
// bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 3000);
|
||||
// bootstrap.option(ChannelOption.SO_KEEPALIVE, true);
|
||||
// /**
|
||||
// * TCP/IP协议中,无论发送多少数据,总是要在数据前面加上协议头,同时,对方接收到数据,也需要发送ACK表示确认。为了尽可能的利用网络带宽,TCP总是希望尽可能的发送足够大的数据。(一个连接会设置MSS参数,因此,TCP/IP希望每次都能够以MSS尺寸的数据块来发送数据)。
|
||||
// * Nagle算法就是为了尽可能发送大块数据,避免网络中充斥着许多小数据块。
|
||||
// */
|
||||
// bootstrap.option(ChannelOption.TCP_NODELAY, true);
|
||||
bootstrap.remoteAddress(InetSocketAddress.createUnresolved(proxyConfig.getTunnel().getServerIp(), proxyConfig.getTunnel().getServerPort()));
|
||||
|
||||
bootstrap.handler(new ChannelInitializer<SocketChannel>() {
|
||||
|
||||
@Override
|
||||
public void initChannel(SocketChannel ch) throws Exception {
|
||||
if (proxyConfig.getTunnel().getSslEnable()) {
|
||||
ch.pipeline().addLast(ProxyUtil.createSslHandler(proxyConfig));
|
||||
}
|
||||
if (null != proxyConfig.getTunnel().getTransferLogEnable() && proxyConfig.getTunnel().getTransferLogEnable()) {
|
||||
ch.pipeline().addFirst(new LoggingHandler(CmdChannelHandler.class));
|
||||
}
|
||||
ch.pipeline().addLast(new ProxyMessageDecoder(proxyConfig.getProtocol().getMaxFrameLength(),
|
||||
proxyConfig.getProtocol().getLengthFieldOffset(), proxyConfig.getProtocol().getLengthFieldLength(),
|
||||
proxyConfig.getProtocol().getLengthAdjustment(), proxyConfig.getProtocol().getInitialBytesToStrip()));
|
||||
ch.pipeline().addLast(new ProxyMessageEncoder());
|
||||
ch.pipeline().addLast(new IdleStateHandler(proxyConfig.getProtocol().getReadIdleTime(), proxyConfig.getProtocol().getWriteIdleTime(), proxyConfig.getProtocol().getAllIdleTimeSeconds()));
|
||||
ch.pipeline().addLast(new CmdChannelHandler());
|
||||
}
|
||||
});
|
||||
return bootstrap;
|
||||
}
|
||||
|
||||
@Bean("tcpProxyTunnelBootstrap")
|
||||
public Bootstrap tcpProxyTunnelBootstrap(@Inject ProxyConfig proxyConfig,
|
||||
@Inject("tunnelWorkGroup") NioEventLoopGroup tunnelWorkGroup) {
|
||||
Bootstrap bootstrap = new Bootstrap();
|
||||
bootstrap.group(tunnelWorkGroup);
|
||||
bootstrap.channel(NioSocketChannel.class);
|
||||
bootstrap.remoteAddress(InetSocketAddress.createUnresolved(proxyConfig.getTunnel().getServerIp(), proxyConfig.getTunnel().getServerPort()));
|
||||
bootstrap.handler(new ChannelInitializer<SocketChannel>() {
|
||||
|
||||
@Override
|
||||
public void initChannel(SocketChannel ch) throws Exception {
|
||||
if (proxyConfig.getTunnel().getSslEnable()) {
|
||||
ch.pipeline().addLast(ProxyUtil.createSslHandler(proxyConfig));
|
||||
}
|
||||
if (null != proxyConfig.getTunnel().getTransferLogEnable() && proxyConfig.getTunnel().getTransferLogEnable()) {
|
||||
ch.pipeline().addFirst(new LoggingHandler(TcpProxyChannelHandler.class));
|
||||
}
|
||||
ch.pipeline().addLast(new ProxyMessageDecoder(proxyConfig.getProtocol().getMaxFrameLength(),
|
||||
proxyConfig.getProtocol().getLengthFieldOffset(), proxyConfig.getProtocol().getLengthFieldLength(),
|
||||
proxyConfig.getProtocol().getLengthAdjustment(), proxyConfig.getProtocol().getInitialBytesToStrip()));
|
||||
ch.pipeline().addLast(new ProxyMessageEncoder());
|
||||
ch.pipeline().addLast(new IdleStateHandler(proxyConfig.getProtocol().getReadIdleTime(), proxyConfig.getProtocol().getWriteIdleTime(), proxyConfig.getProtocol().getAllIdleTimeSeconds()));
|
||||
ch.pipeline().addLast(new TcpProxyChannelHandler());
|
||||
}
|
||||
});
|
||||
return bootstrap;
|
||||
}
|
||||
|
||||
@Bean("udpProxyTunnelBootstrap")
|
||||
private Bootstrap udpProxyTunnelBootstrap(@Inject ProxyConfig proxyConfig,
|
||||
@Inject("tunnelWorkGroup") NioEventLoopGroup tunnelWorkGroup) {
|
||||
Bootstrap bootstrap = new Bootstrap();
|
||||
bootstrap.group(tunnelWorkGroup);
|
||||
bootstrap.channel(NioSocketChannel.class);
|
||||
bootstrap.remoteAddress(InetSocketAddress.createUnresolved(proxyConfig.getTunnel().getServerIp(), proxyConfig.getTunnel().getServerPort()));
|
||||
bootstrap.handler(new ChannelInitializer<SocketChannel>() {
|
||||
|
||||
@Override
|
||||
public void initChannel(SocketChannel ch) throws Exception {
|
||||
if (proxyConfig.getTunnel().getSslEnable()) {
|
||||
ch.pipeline().addLast(ProxyUtil.createSslHandler(proxyConfig));
|
||||
}
|
||||
if (null != proxyConfig.getTunnel().getTransferLogEnable() && proxyConfig.getTunnel().getTransferLogEnable()) {
|
||||
ch.pipeline().addFirst(new LoggingHandler(TcpProxyChannelHandler.class));
|
||||
}
|
||||
ch.pipeline().addLast(new ProxyMessageDecoder(proxyConfig.getProtocol().getMaxFrameLength(),
|
||||
proxyConfig.getProtocol().getLengthFieldOffset(), proxyConfig.getProtocol().getLengthFieldLength(),
|
||||
proxyConfig.getProtocol().getLengthAdjustment(), proxyConfig.getProtocol().getInitialBytesToStrip()));
|
||||
ch.pipeline().addLast(new ProxyMessageEncoder());
|
||||
ch.pipeline().addLast(new IdleStateHandler(proxyConfig.getProtocol().getReadIdleTime(), proxyConfig.getProtocol().getWriteIdleTime(), proxyConfig.getProtocol().getAllIdleTimeSeconds()));
|
||||
ch.pipeline().addLast(new UdpProxyChannelHandler());
|
||||
}
|
||||
});
|
||||
return bootstrap;
|
||||
}
|
||||
|
||||
@Bean("realServerBootstrap")
|
||||
public Bootstrap realServerBootstrap() {
|
||||
return new Bootstrap();
|
||||
public Bootstrap realServerBootstrap(@Inject ProxyConfig proxyConfig,
|
||||
@Inject("tcpRealServerWorkGroup") NioEventLoopGroup tcpRealServerWorkGroup
|
||||
) {
|
||||
Bootstrap bootstrap = new Bootstrap();
|
||||
bootstrap.group(tcpRealServerWorkGroup);
|
||||
bootstrap.channel(NioSocketChannel.class);
|
||||
bootstrap.handler(new ChannelInitializer<SocketChannel>() {
|
||||
|
||||
@Override
|
||||
public void initChannel(SocketChannel ch) throws Exception {
|
||||
if (null != proxyConfig.getTunnel().getTransferLogEnable() && proxyConfig.getTunnel().getTransferLogEnable()) {
|
||||
ch.pipeline().addFirst(new LoggingHandler(RealServerChannelHandler.class));
|
||||
}
|
||||
ch.pipeline().addLast(new RealServerChannelHandler());
|
||||
}
|
||||
});
|
||||
return bootstrap;
|
||||
}
|
||||
|
||||
@Bean("udpServerBootstrap")
|
||||
public Bootstrap udpServerBootstrap(@Inject ProxyConfig proxyConfig,
|
||||
@Inject("udpServerGroup") NioEventLoopGroup udpServerGroup,
|
||||
@Inject("udpWorkGroup") NioEventLoopGroup udpWorkGroup) {
|
||||
Bootstrap bootstrap = new Bootstrap();
|
||||
bootstrap.group(udpServerGroup)
|
||||
// 主线程处理
|
||||
.channel(NioDatagramChannel.class)
|
||||
// 广播
|
||||
.option(ChannelOption.SO_BROADCAST, true)
|
||||
// 设置读缓冲区为2M
|
||||
.option(ChannelOption.SO_RCVBUF, 2048 * 1024)
|
||||
// 设置写缓冲区为1M
|
||||
.option(ChannelOption.SO_SNDBUF, 1024 * 1024)
|
||||
.handler(new ChannelInitializer<NioDatagramChannel>() {
|
||||
@Override
|
||||
protected void initChannel(NioDatagramChannel ch) {
|
||||
ChannelPipeline pipeline = ch.pipeline();
|
||||
if (null != proxyConfig.getClient().getUdp().getTransferLogEnable() && proxyConfig.getClient().getUdp().getTransferLogEnable()) {
|
||||
ch.pipeline().addFirst(new LoggingHandler(UdpRealServerHandler.class));
|
||||
}
|
||||
pipeline.addLast(udpWorkGroup, new UdpRealServerHandler());
|
||||
}
|
||||
});
|
||||
return bootstrap;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package org.dromara.neutrinoproxy.client.constant;
|
||||
|
||||
import io.netty.util.AttributeKey;
|
||||
import org.dromara.neutrinoproxy.client.util.UdpChannelBindInfo;
|
||||
|
||||
/**
|
||||
* @author: aoshiguchen
|
||||
* @date: 2023/9/21
|
||||
*/
|
||||
public interface Constants {
|
||||
AttributeKey<UdpChannelBindInfo> UDP_CHANNEL_BIND_KEY = AttributeKey.newInstance("udpChannelBindKey");
|
||||
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package org.dromara.neutrinoproxy.client.core;
|
||||
|
||||
import org.dromara.neutrinoproxy.client.config.ProxyConfig;
|
||||
import org.dromara.neutrinoproxy.client.util.ProxyUtil;
|
||||
import org.dromara.neutrinoproxy.core.Constants;
|
||||
import org.dromara.neutrinoproxy.core.ProxyMessage;
|
||||
import org.dromara.neutrinoproxy.core.dispatcher.Dispatcher;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelOption;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
import io.netty.handler.timeout.IdleStateEvent;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.noear.solon.Solon;
|
||||
|
||||
/**
|
||||
* 处理与服务端之间的数据传输
|
||||
* @author: aoshiguchen
|
||||
* @date: 2022/6/16
|
||||
*/
|
||||
@Slf4j
|
||||
public class CmdChannelHandler extends SimpleChannelInboundHandler<ProxyMessage> {
|
||||
private static volatile Boolean transferLogEnable = Boolean.FALSE;
|
||||
|
||||
public CmdChannelHandler() {
|
||||
ProxyConfig proxyConfig = Solon.context().getBean(ProxyConfig.class);
|
||||
if (null != proxyConfig.getClient() && null != proxyConfig.getTunnel().getHeartbeatLogEnable()) {
|
||||
transferLogEnable = proxyConfig.getTunnel().getHeartbeatLogEnable();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void channelRead0(ChannelHandlerContext ctx, ProxyMessage proxyMessage) throws Exception {
|
||||
if (ProxyMessage.TYPE_HEARTBEAT != proxyMessage.getType() || transferLogEnable) {
|
||||
log.debug("[CMD Channel]Client CmdChannel recieved proxy message, type is {}", proxyMessage.getType());
|
||||
}
|
||||
Solon.context().getBean(Dispatcher.class).dispatch(ctx, proxyMessage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception {
|
||||
Channel realServerChannel = ctx.channel().attr(Constants.NEXT_CHANNEL).get();
|
||||
if (realServerChannel != null) {
|
||||
realServerChannel.config().setOption(ChannelOption.AUTO_READ, ctx.channel().isWritable());
|
||||
}
|
||||
|
||||
super.channelWritabilityChanged(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
||||
log.info("[CMD Channel]Client CmdChannel disconnect");
|
||||
ProxyUtil.setCmdChannel(null);
|
||||
ProxyUtil.clearRealServerChannels();
|
||||
|
||||
super.channelInactive(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
||||
log.error("[CMD Channel]Client CmdChannel Error channelId:{}", ctx.channel().id().asLongText(), cause);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
|
||||
if(evt instanceof IdleStateEvent) {
|
||||
IdleStateEvent event = (IdleStateEvent)evt;
|
||||
switch (event.state()) {
|
||||
case READER_IDLE:
|
||||
// 读超时,断开连接
|
||||
log.error("[CMD Channel] Read timeout disconnect");
|
||||
ctx.channel().close();
|
||||
break;
|
||||
case WRITER_IDLE:
|
||||
ctx.channel().writeAndFlush(ProxyMessage.buildHeartbeatMessage());
|
||||
break;
|
||||
case ALL_IDLE:
|
||||
log.error("[CMD Channel] ReadWrite timeout disconnect");
|
||||
ctx.close();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,38 +1,24 @@
|
||||
package org.dromara.neutrinoproxy.client.core;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import io.netty.handler.logging.LoggingHandler;
|
||||
import org.dromara.neutrinoproxy.client.config.ProxyConfig;
|
||||
import org.dromara.neutrinoproxy.client.util.ProxyUtil;
|
||||
import org.dromara.neutrinoproxy.client.util.UdpServerUtil;
|
||||
import org.dromara.neutrinoproxy.core.ProxyMessage;
|
||||
import org.dromara.neutrinoproxy.core.ProxyMessageDecoder;
|
||||
import org.dromara.neutrinoproxy.core.ProxyMessageEncoder;
|
||||
import org.dromara.neutrinoproxy.core.util.FileUtil;
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
import io.netty.channel.*;
|
||||
import io.netty.channel.nio.NioEventLoopGroup;
|
||||
import io.netty.channel.socket.SocketChannel;
|
||||
import io.netty.channel.socket.nio.NioSocketChannel;
|
||||
import io.netty.handler.ssl.SslHandler;
|
||||
import io.netty.handler.timeout.IdleStateHandler;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.noear.solon.Solon;
|
||||
import org.noear.solon.annotation.Component;
|
||||
import org.noear.solon.annotation.Init;
|
||||
import org.noear.solon.annotation.Inject;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLEngine;
|
||||
import javax.net.ssl.TrustManager;
|
||||
import javax.net.ssl.TrustManagerFactory;
|
||||
import java.io.InputStream;
|
||||
import java.security.KeyStore;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 客户端服务
|
||||
* 代理客户端服务
|
||||
* @author: aoshiguchen
|
||||
* @date: 2022/6/16
|
||||
*/
|
||||
@@ -41,23 +27,15 @@ import java.util.concurrent.TimeUnit;
|
||||
public class ProxyClientService {
|
||||
@Inject
|
||||
private ProxyConfig proxyConfig;
|
||||
@Inject("bootstrap")
|
||||
private Bootstrap bootstrap;
|
||||
@Inject("realServerBootstrap")
|
||||
private Bootstrap realServerBootstrap;
|
||||
@Inject("cmdTunnelBootstrap")
|
||||
private Bootstrap cmdTunnelBootstrap;
|
||||
@Inject("udpServerBootstrap")
|
||||
private Bootstrap udpServerBootstrap;
|
||||
private volatile Channel channel;
|
||||
/**
|
||||
* 重连间隔(秒)
|
||||
*/
|
||||
private static final long RECONNECT_INTERVAL_SECONDS = 5;
|
||||
/**
|
||||
* 重连次数
|
||||
*/
|
||||
private volatile int reconnectCount = 0;
|
||||
/**
|
||||
* 启用重连服务
|
||||
*/
|
||||
private volatile boolean reconnectServiceEnable = false;
|
||||
/**
|
||||
* 重连服务执行器
|
||||
*/
|
||||
@@ -65,58 +43,35 @@ public class ProxyClientService {
|
||||
|
||||
@Init
|
||||
public void init() {
|
||||
this.reconnectExecutor.scheduleWithFixedDelay(this::reconnect, 0, RECONNECT_INTERVAL_SECONDS, TimeUnit.SECONDS);
|
||||
this.reconnectExecutor.scheduleWithFixedDelay(this::reconnect, 10, proxyConfig.getTunnel().getReconnection().getIntervalSeconds(), TimeUnit.SECONDS);
|
||||
|
||||
NioEventLoopGroup workerGroup = new NioEventLoopGroup(proxyConfig.getClient().getThreadCount());
|
||||
realServerBootstrap.group(workerGroup);
|
||||
realServerBootstrap.channel(NioSocketChannel.class);
|
||||
realServerBootstrap.handler(new ChannelInitializer<SocketChannel>() {
|
||||
|
||||
@Override
|
||||
public void initChannel(SocketChannel ch) throws Exception {
|
||||
ch.pipeline().addLast(new RealServerChannelHandler());
|
||||
}
|
||||
});
|
||||
|
||||
bootstrap.group(workerGroup);
|
||||
bootstrap.channel(NioSocketChannel.class);
|
||||
bootstrap.handler(new ChannelInitializer<SocketChannel>() {
|
||||
|
||||
@Override
|
||||
public void initChannel(SocketChannel ch) throws Exception {
|
||||
if (proxyConfig.getClient().getSslEnable()) {
|
||||
ch.pipeline().addLast(createSslHandler());
|
||||
}
|
||||
// ch.pipeline().addFirst(new LoggingHandler(ProxyClientService.class));
|
||||
ch.pipeline().addLast(new ProxyMessageDecoder(proxyConfig.getProtocol().getMaxFrameLength(),
|
||||
proxyConfig.getProtocol().getLengthFieldOffset(), proxyConfig.getProtocol().getLengthFieldLength(),
|
||||
proxyConfig.getProtocol().getLengthAdjustment(), proxyConfig.getProtocol().getInitialBytesToStrip()));
|
||||
ch.pipeline().addLast(new ProxyMessageEncoder());
|
||||
ch.pipeline().addLast(new IdleStateHandler(proxyConfig.getProtocol().getReadIdleTime(), proxyConfig.getProtocol().getWriteIdleTime(), proxyConfig.getProtocol().getAllIdleTimeSeconds()));
|
||||
ch.pipeline().addLast(new ClientChannelHandler());
|
||||
}
|
||||
});
|
||||
this.start();
|
||||
try {
|
||||
this.start();
|
||||
UdpServerUtil.initCache(proxyConfig, udpServerBootstrap);
|
||||
} catch (Exception e) {
|
||||
// 启动连不上也做一下重连,因此先catch异常
|
||||
log.error("[CmdChannel] start error", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void start() {
|
||||
if (StrUtil.isEmpty(proxyConfig.getClient().getServerIp())) {
|
||||
if (StrUtil.isEmpty(proxyConfig.getTunnel().getServerIp())) {
|
||||
log.error("not found server-ip config.");
|
||||
Solon.stop();
|
||||
return;
|
||||
}
|
||||
if (null == proxyConfig.getClient().getServerPort()) {
|
||||
if (null == proxyConfig.getTunnel().getServerPort()) {
|
||||
log.error("not found server-port config.");
|
||||
Solon.stop();
|
||||
return;
|
||||
}
|
||||
if (null != proxyConfig.getClient().getSslEnable() && proxyConfig.getClient().getSslEnable()
|
||||
&& StrUtil.isEmpty(proxyConfig.getClient().getJksPath())) {
|
||||
if (null != proxyConfig.getTunnel().getSslEnable() && proxyConfig.getTunnel().getSslEnable()
|
||||
&& StrUtil.isEmpty(proxyConfig.getTunnel().getJksPath())) {
|
||||
log.error("not found jks-path config.");
|
||||
Solon.stop();
|
||||
return;
|
||||
}
|
||||
if (StrUtil.isEmpty(proxyConfig.getClient().getLicenseKey())) {
|
||||
if (StrUtil.isEmpty(proxyConfig.getTunnel().getLicenseKey())) {
|
||||
log.error("not found license-key config.");
|
||||
Solon.stop();
|
||||
return;
|
||||
@@ -128,7 +83,7 @@ public class ProxyClientService {
|
||||
log.error("client start error", e);
|
||||
}
|
||||
} else {
|
||||
channel.writeAndFlush(ProxyMessage.buildAuthMessage(proxyConfig.getClient().getLicenseKey()));
|
||||
channel.writeAndFlush(ProxyMessage.buildAuthMessage(proxyConfig.getTunnel().getLicenseKey(), ProxyUtil.getClientId()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,7 +91,7 @@ public class ProxyClientService {
|
||||
* 连接代理服务器
|
||||
*/
|
||||
private void connectProxyServer() throws InterruptedException {
|
||||
bootstrap.connect(proxyConfig.getClient().getServerIp(), proxyConfig.getClient().getServerPort())
|
||||
cmdTunnelBootstrap.connect()
|
||||
.addListener(new ChannelFutureListener() {
|
||||
|
||||
@Override
|
||||
@@ -145,53 +100,31 @@ public class ProxyClientService {
|
||||
channel = future.channel();
|
||||
// 连接成功,向服务器发送客户端认证信息(licenseKey)
|
||||
ProxyUtil.setCmdChannel(future.channel());
|
||||
future.channel().writeAndFlush(ProxyMessage.buildAuthMessage(proxyConfig.getClient().getLicenseKey()));
|
||||
log.info("连接代理服务成功. channelId:{}", future.channel().id().asLongText());
|
||||
future.channel().writeAndFlush(ProxyMessage.buildAuthMessage(proxyConfig.getTunnel().getLicenseKey(), ProxyUtil.getClientId()));
|
||||
log.info("[CmdChannel] connect proxy server success. channelId:{}", future.channel().id().asLongText());
|
||||
|
||||
reconnectServiceEnable = true;
|
||||
// reconnectServiceEnable = true;
|
||||
reconnectCount = 0;
|
||||
} else {
|
||||
log.info("连接代理服务失败!");
|
||||
log.info("[CmdChannel] connect proxy server failed!");
|
||||
}
|
||||
}
|
||||
}).sync();
|
||||
}
|
||||
|
||||
private ChannelHandler createSslHandler() {
|
||||
try {
|
||||
InputStream jksInputStream = FileUtil.getInputStream(proxyConfig.getClient().getJksPath());
|
||||
|
||||
SSLContext clientContext = SSLContext.getInstance("TLS");
|
||||
final KeyStore ks = KeyStore.getInstance("JKS");
|
||||
ks.load(jksInputStream, proxyConfig.getClient().getKeyStorePassword().toCharArray());
|
||||
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
|
||||
tmf.init(ks);
|
||||
TrustManager[] trustManagers = tmf.getTrustManagers();
|
||||
clientContext.init(null, trustManagers, null);
|
||||
|
||||
SSLEngine sslEngine = clientContext.createSSLEngine();
|
||||
sslEngine.setUseClientMode(true);
|
||||
|
||||
return new SslHandler(sslEngine);
|
||||
} catch (Exception e) {
|
||||
log.error("创建SSL处理器失败", e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected synchronized void reconnect() {
|
||||
if (!reconnectServiceEnable) {
|
||||
return;
|
||||
if (null != channel) {
|
||||
if (channel.isActive()) {
|
||||
return;
|
||||
}
|
||||
channel.close();
|
||||
}
|
||||
if (null != channel && channel.isActive()) {
|
||||
return;
|
||||
}
|
||||
log.info("客户端重连 seq:{}", ++reconnectCount);
|
||||
|
||||
log.info("[CmdChannel] client reconnect seq:{}", ++reconnectCount);
|
||||
try {
|
||||
connectProxyServer();
|
||||
} catch (Exception e) {
|
||||
log.error("重连异常", e);
|
||||
log.error("[CmdChannel] reconnect error", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
package org.dromara.neutrinoproxy.client.core;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.neutrinoproxy.client.util.ProxyUtil;
|
||||
import org.dromara.neutrinoproxy.core.Constants;
|
||||
import org.dromara.neutrinoproxy.core.ProxyMessage;
|
||||
@@ -36,6 +37,7 @@ import io.netty.channel.SimpleChannelInboundHandler;
|
||||
* @author: aoshiguchen
|
||||
* @date: 2022/6/16
|
||||
*/
|
||||
@Slf4j
|
||||
public class RealServerChannelHandler extends SimpleChannelInboundHandler<ByteBuf> {
|
||||
|
||||
|
||||
@@ -47,6 +49,17 @@ public class RealServerChannelHandler extends SimpleChannelInboundHandler<ByteBu
|
||||
// 代理客户端连接断开
|
||||
ctx.channel().close();
|
||||
} else {
|
||||
|
||||
if (proxyChannel.isWritable()) {
|
||||
if (!realServerChannel.config().isAutoRead()) {
|
||||
realServerChannel.config().setAutoRead(true);
|
||||
}
|
||||
} else {
|
||||
if (realServerChannel.config().isAutoRead()) {
|
||||
realServerChannel.config().setAutoRead(false);
|
||||
}
|
||||
}
|
||||
|
||||
byte[] bytes = new byte[buf.readableBytes()];
|
||||
buf.readBytes(bytes);
|
||||
String visitorId = ProxyUtil.getVisitorIdByRealServerChannel(realServerChannel);
|
||||
@@ -85,6 +98,6 @@ public class RealServerChannelHandler extends SimpleChannelInboundHandler<ByteBu
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
||||
super.exceptionCaught(ctx, cause);
|
||||
log.error("Client ProxyChannel Error", cause);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
package org.dromara.neutrinoproxy.client.core;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelOption;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
import io.netty.handler.timeout.IdleStateEvent;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.neutrinoproxy.client.util.ProxyUtil;
|
||||
import org.dromara.neutrinoproxy.core.Constants;
|
||||
import org.dromara.neutrinoproxy.core.ProxyMessage;
|
||||
import org.dromara.neutrinoproxy.core.dispatcher.Dispatcher;
|
||||
import org.noear.solon.Solon;
|
||||
|
||||
/**
|
||||
* 处理与服务端之间的数据传输
|
||||
* @author: aoshiguchen
|
||||
* @date: 2022/6/16
|
||||
*/
|
||||
@Slf4j
|
||||
public class TcpProxyChannelHandler extends SimpleChannelInboundHandler<ProxyMessage> {
|
||||
|
||||
|
||||
@Override
|
||||
protected void channelRead0(ChannelHandlerContext ctx, ProxyMessage proxyMessage) throws Exception {
|
||||
if (ProxyMessage.TYPE_HEARTBEAT != proxyMessage.getType()) {
|
||||
log.debug("[TCP Proxy Channel]Client ProxyChannel recieved proxy message, type is {}", proxyMessage.getType());
|
||||
}
|
||||
Solon.context().getBean(Dispatcher.class).dispatch(ctx, proxyMessage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception {
|
||||
Channel realServerChannel = ctx.channel().attr(Constants.NEXT_CHANNEL).get();
|
||||
if (realServerChannel != null) {
|
||||
realServerChannel.config().setOption(ChannelOption.AUTO_READ, ctx.channel().isWritable());
|
||||
}
|
||||
|
||||
super.channelWritabilityChanged(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
||||
// 数据传输连接
|
||||
Channel realServerChannel = ctx.channel().attr(Constants.NEXT_CHANNEL).get();
|
||||
if (realServerChannel != null && realServerChannel.isActive()) {
|
||||
realServerChannel.close();
|
||||
}
|
||||
|
||||
ProxyUtil.removeTcpProxyChanel(ctx.channel());
|
||||
super.channelInactive(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
||||
log.error("[TCP Proxy Channel]Client ProxyChannel Error channelId:{}", ctx.channel().id().asLongText(), cause);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
|
||||
if(evt instanceof IdleStateEvent) {
|
||||
IdleStateEvent event = (IdleStateEvent)evt;
|
||||
switch (event.state()) {
|
||||
case READER_IDLE:
|
||||
if (ctx.channel().isWritable()) {
|
||||
// 读超时,断开连接
|
||||
log.info("[TCP Proxy Channel]Read timeout");
|
||||
ctx.channel().close();
|
||||
}
|
||||
break;
|
||||
case WRITER_IDLE:
|
||||
ctx.channel().writeAndFlush(ProxyMessage.buildHeartbeatMessage());
|
||||
break;
|
||||
case ALL_IDLE:
|
||||
// log.debug("[TCP Proxy Channel]ReadWrite timeout");
|
||||
// ctx.close();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,15 @@
|
||||
package org.dromara.neutrinoproxy.client.core;
|
||||
|
||||
import org.dromara.neutrinoproxy.client.util.ProxyUtil;
|
||||
import org.dromara.neutrinoproxy.core.Constants;
|
||||
import org.dromara.neutrinoproxy.core.ProxyMessage;
|
||||
import org.dromara.neutrinoproxy.core.dispatcher.Dispatcher;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelOption;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
import io.netty.handler.timeout.IdleStateEvent;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.neutrinoproxy.client.util.ProxyUtil;
|
||||
import org.dromara.neutrinoproxy.core.Constants;
|
||||
import org.dromara.neutrinoproxy.core.ProxyMessage;
|
||||
import org.dromara.neutrinoproxy.core.dispatcher.Dispatcher;
|
||||
import org.noear.solon.Solon;
|
||||
|
||||
/**
|
||||
@@ -18,13 +18,13 @@ import org.noear.solon.Solon;
|
||||
* @date: 2022/6/16
|
||||
*/
|
||||
@Slf4j
|
||||
public class ClientChannelHandler extends SimpleChannelInboundHandler<ProxyMessage> {
|
||||
public class UdpProxyChannelHandler extends SimpleChannelInboundHandler<ProxyMessage> {
|
||||
|
||||
|
||||
@Override
|
||||
protected void channelRead0(ChannelHandlerContext ctx, ProxyMessage proxyMessage) throws Exception {
|
||||
if (ProxyMessage.TYPE_HEARTBEAT != proxyMessage.getType()) {
|
||||
log.info("recieved proxy message, type is {}", proxyMessage.getType());
|
||||
log.debug("[UDP Proxy Channel]Client ProxyChannel recieved proxy message, type is {}", proxyMessage.getType());
|
||||
}
|
||||
Solon.context().getBean(Dispatcher.class).dispatch(ctx, proxyMessage);
|
||||
}
|
||||
@@ -41,29 +41,20 @@ public class ClientChannelHandler extends SimpleChannelInboundHandler<ProxyMessa
|
||||
|
||||
@Override
|
||||
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
||||
// 控制连接
|
||||
if (ProxyUtil.getCmdChannel() == ctx.channel()) {
|
||||
log.info("与服务端断开连接");
|
||||
ProxyUtil.setCmdChannel(null);
|
||||
ProxyUtil.clearRealServerChannels();
|
||||
} else {
|
||||
// 数据传输连接
|
||||
Channel realServerChannel = ctx.channel().attr(Constants.NEXT_CHANNEL).get();
|
||||
if (realServerChannel != null && realServerChannel.isActive()) {
|
||||
realServerChannel.close();
|
||||
}
|
||||
// 数据传输连接
|
||||
Channel realServerChannel = ctx.channel().attr(Constants.NEXT_CHANNEL).get();
|
||||
if (realServerChannel != null && realServerChannel.isActive()) {
|
||||
realServerChannel.close();
|
||||
}
|
||||
|
||||
ProxyUtil.removeProxyChanel(ctx.channel());
|
||||
ProxyUtil.removeTcpProxyChanel(ctx.channel());
|
||||
super.channelInactive(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
||||
super.exceptionCaught(ctx, cause);
|
||||
if (ctx.channel().isActive()) {
|
||||
ctx.channel().close();
|
||||
}
|
||||
log.error("[UDP Proxy Channel]Client ProxyChannel Error channelId:{}", ctx.channel().id().asLongText(), cause);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -73,13 +64,15 @@ public class ClientChannelHandler extends SimpleChannelInboundHandler<ProxyMessa
|
||||
switch (event.state()) {
|
||||
case READER_IDLE:
|
||||
// 读超时,断开连接
|
||||
log.info("读超时");
|
||||
log.info("[UDP Proxy Channel]Read timeout");
|
||||
ctx.channel().close();
|
||||
break;
|
||||
case WRITER_IDLE:
|
||||
ctx.channel().writeAndFlush(ProxyMessage.buildHeartbeatMessage());
|
||||
break;
|
||||
case ALL_IDLE:
|
||||
log.debug("[UDP Proxy Channel]ReadWrite timeout");
|
||||
ctx.close();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package org.dromara.neutrinoproxy.client.core;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
import io.netty.channel.socket.DatagramPacket;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.neutrinoproxy.client.constant.Constants;
|
||||
import org.dromara.neutrinoproxy.client.util.UdpChannelBindInfo;
|
||||
import org.dromara.neutrinoproxy.core.ProxyMessage;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
/**
|
||||
* @author: aoshiguchen
|
||||
* @date: 2023/9/21
|
||||
*/
|
||||
@Slf4j
|
||||
public class UdpRealServerHandler extends SimpleChannelInboundHandler<DatagramPacket> {
|
||||
|
||||
@Override
|
||||
protected void channelRead0(ChannelHandlerContext ctx, DatagramPacket datagramPacket) throws Exception {
|
||||
log.debug("chid---<:{} port:{}", ctx.channel().id().asLongText(), ((InetSocketAddress)ctx.channel().localAddress()).getPort());
|
||||
UdpChannelBindInfo udpChannelBindInfo = ctx.channel().attr(Constants.UDP_CHANNEL_BIND_KEY).get();
|
||||
if (null != udpChannelBindInfo) {
|
||||
byte[] bytes = new byte[datagramPacket.content().readableBytes()];
|
||||
datagramPacket.content().readBytes(bytes);
|
||||
|
||||
udpChannelBindInfo.getTunnelChannel().writeAndFlush(ProxyMessage.buildUdpTransferMessage(new ProxyMessage.UdpBaseInfo()
|
||||
.setVisitorId(udpChannelBindInfo.getVisitorId())
|
||||
.setVisitorIp(udpChannelBindInfo.getVisitorIp())
|
||||
.setVisitorPort(udpChannelBindInfo.getVisitorPort())
|
||||
.setServerPort(udpChannelBindInfo.getServerPort())
|
||||
.setTargetIp(udpChannelBindInfo.getTargetIp())
|
||||
.setTargetPort(udpChannelBindInfo.getTargetPort()))
|
||||
.setData(bytes)
|
||||
);
|
||||
|
||||
udpChannelBindInfo.getLockChannel().setResponseCount(udpChannelBindInfo.getLockChannel().getResponseCount() + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,17 @@
|
||||
package org.dromara.neutrinoproxy.client.handler;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.dromara.neutrinoproxy.client.config.ProxyConfig;
|
||||
import org.dromara.neutrinoproxy.core.Constants;
|
||||
import org.dromara.neutrinoproxy.core.ExceptionEnum;
|
||||
import org.dromara.neutrinoproxy.core.ProxyMessage;
|
||||
import org.dromara.neutrinoproxy.core.ProxyMessageHandler;
|
||||
import org.dromara.neutrinoproxy.core.dispatcher.Match;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.noear.solon.Solon;
|
||||
import org.noear.solon.annotation.Component;
|
||||
import org.noear.solon.annotation.Inject;
|
||||
|
||||
/**
|
||||
* 认证信息处理器
|
||||
@@ -18,11 +22,25 @@ import org.noear.solon.annotation.Component;
|
||||
@Match(type = Constants.ProxyDataTypeName.AUTH)
|
||||
@Component
|
||||
public class ProxyMessageAuthHandler implements ProxyMessageHandler {
|
||||
@Inject
|
||||
private ProxyConfig proxyConfig;
|
||||
@Override
|
||||
public void handle(ChannelHandlerContext context, ProxyMessage proxyMessage) {
|
||||
String info = proxyMessage.getInfo();
|
||||
JSONObject data = JSONObject.parseObject(info);
|
||||
Integer code = data.getInteger("code");
|
||||
log.info("认证结果:{}", info);
|
||||
log.info("Auth result:{}", info);
|
||||
if (ExceptionEnum.AUTH_FAILED.getCode().equals(code)) {
|
||||
// 客户端认证失败,直接停止服务
|
||||
log.info("client auth failed , client stop.");
|
||||
context.channel().close();
|
||||
if (!proxyConfig.getTunnel().getReconnection().getUnlimited()) {
|
||||
Solon.stop();
|
||||
}
|
||||
} else if (ExceptionEnum.CONNECT_FAILED.getCode().equals(code) ||
|
||||
ExceptionEnum.LICENSE_CANNOT_REPEAT_CONNECT.getCode().equals(code)
|
||||
){
|
||||
context.channel().close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,8 +21,8 @@ import org.noear.solon.annotation.Inject;
|
||||
@Match(type = Constants.ProxyDataTypeName.CONNECT)
|
||||
@Component
|
||||
public class ProxyMessageConnectHandler implements ProxyMessageHandler {
|
||||
@Inject("bootstrap")
|
||||
private Bootstrap bootstrap;
|
||||
@Inject("tcpProxyTunnelBootstrap")
|
||||
private Bootstrap tcpProxyTunnelBootstrap;
|
||||
@Inject("realServerBootstrap")
|
||||
private Bootstrap realServerBootstrap;
|
||||
@Inject
|
||||
@@ -48,7 +48,7 @@ public class ProxyMessageConnectHandler implements ProxyMessageHandler {
|
||||
realServerChannel.config().setOption(ChannelOption.AUTO_READ, false);
|
||||
|
||||
// 获取连接
|
||||
ProxyUtil.borrowProxyChanel(bootstrap, new ProxyChannelBorrowListener() {
|
||||
ProxyUtil.borrowTcpProxyChanel(tcpProxyTunnelBootstrap, new ProxyChannelBorrowListener() {
|
||||
|
||||
@Override
|
||||
public void success(Channel channel) {
|
||||
@@ -57,7 +57,7 @@ public class ProxyMessageConnectHandler implements ProxyMessageHandler {
|
||||
realServerChannel.attr(Constants.NEXT_CHANNEL).set(channel);
|
||||
|
||||
// 远程绑定
|
||||
channel.writeAndFlush(ProxyMessage.buildConnectMessage(visitorId + "@" + proxyConfig.getClient().getLicenseKey()));
|
||||
channel.writeAndFlush(ProxyMessage.buildConnectMessage(visitorId + "@" + proxyConfig.getTunnel().getLicenseKey()));
|
||||
|
||||
realServerChannel.config().setOption(ChannelOption.AUTO_READ, true);
|
||||
ProxyUtil.addRealServerChannel(visitorId, realServerChannel);
|
||||
|
||||
@@ -26,9 +26,10 @@ public class ProxyMessageDisconnectHandler implements ProxyMessageHandler {
|
||||
Channel realServerChannel = ctx.channel().attr(Constants.NEXT_CHANNEL).get();
|
||||
if (null != realServerChannel) {
|
||||
ctx.channel().attr(Constants.NEXT_CHANNEL).remove();
|
||||
ProxyUtil.returnProxyChanel(ctx.channel());
|
||||
ProxyUtil.returnTcpProxyChanel(ctx.channel());
|
||||
realServerChannel.writeAndFlush(Unpooled.EMPTY_BUFFER).addListener(ChannelFutureListener.CLOSE);
|
||||
}
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -20,7 +20,7 @@ public class ProxyMessageErrorHandler implements ProxyMessageHandler {
|
||||
|
||||
@Override
|
||||
public void handle(ChannelHandlerContext ctx, ProxyMessage proxyMessage) {
|
||||
log.info("异常信息: {}", proxyMessage.getInfo());
|
||||
log.info("error: {}", proxyMessage.getInfo());
|
||||
JSONObject data = JSONObject.parseObject(proxyMessage.getInfo());
|
||||
Integer code = data.getInteger("code");
|
||||
if (ExceptionEnum.AUTH_FAILED.getCode().equals(code)) {
|
||||
|
||||
@@ -23,6 +23,10 @@ public class ProxyMessageTransferHandler implements ProxyMessageHandler {
|
||||
public void handle(ChannelHandlerContext ctx, ProxyMessage proxyMessage) {
|
||||
Channel realServerChannel = ctx.channel().attr(Constants.NEXT_CHANNEL).get();
|
||||
if (realServerChannel != null) {
|
||||
|
||||
// 自己可写,则设置来源可读。自己不可写,则设置来源不可读
|
||||
realServerChannel.config().setAutoRead(ctx.channel().isWritable());
|
||||
|
||||
ByteBuf buf = ctx.alloc().buffer(proxyMessage.getData().length);
|
||||
buf.writeBytes(proxyMessage.getData());
|
||||
realServerChannel.writeAndFlush(buf);
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
package org.dromara.neutrinoproxy.client.handler;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.neutrinoproxy.client.config.ProxyConfig;
|
||||
import org.dromara.neutrinoproxy.client.core.ProxyChannelBorrowListener;
|
||||
import org.dromara.neutrinoproxy.client.util.ProxyUtil;
|
||||
import org.dromara.neutrinoproxy.core.Constants;
|
||||
import org.dromara.neutrinoproxy.core.ProxyDataTypeEnum;
|
||||
import org.dromara.neutrinoproxy.core.ProxyMessage;
|
||||
import org.dromara.neutrinoproxy.core.ProxyMessageHandler;
|
||||
import org.dromara.neutrinoproxy.core.dispatcher.Match;
|
||||
import org.noear.solon.annotation.Component;
|
||||
import org.noear.solon.annotation.Inject;
|
||||
|
||||
/**
|
||||
* @author: aoshiguchen
|
||||
* @date: 2023/9/19
|
||||
*/
|
||||
@Slf4j
|
||||
@Match(type = Constants.ProxyDataTypeName.UDP_CONNECT)
|
||||
@Component
|
||||
public class UdpProxyMessageConnectHandler implements ProxyMessageHandler {
|
||||
@Inject
|
||||
private ProxyConfig proxyConfig;
|
||||
@Inject("udpProxyTunnelBootstrap")
|
||||
private Bootstrap udpProxyTunnelBootstrap;
|
||||
|
||||
@Override
|
||||
public void handle(ChannelHandlerContext ctx, ProxyMessage proxyMessage) {
|
||||
final Channel cmdChannel = ctx.channel();
|
||||
final ProxyMessage.UdpBaseInfo udpBaseInfo = JSONObject.parseObject(proxyMessage.getInfo(), ProxyMessage.UdpBaseInfo.class);
|
||||
log.info("[UDP connect]info:{}", proxyMessage.getInfo());
|
||||
|
||||
// 获取连接
|
||||
ProxyUtil.borrowUdpProxyChanel(udpProxyTunnelBootstrap, new ProxyChannelBorrowListener() {
|
||||
|
||||
@Override
|
||||
public void success(Channel channel) {
|
||||
channel.writeAndFlush(ProxyMessage.buildUdpConnectMessage(new ProxyMessage.UdpBaseInfo()
|
||||
.setVisitorId(udpBaseInfo.getVisitorId())
|
||||
.setServerPort(udpBaseInfo.getServerPort())
|
||||
.setTargetIp(udpBaseInfo.getTargetIp())
|
||||
.setTargetPort(udpBaseInfo.getTargetPort())
|
||||
).setData(proxyConfig.getTunnel().getLicenseKey().getBytes()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(Throwable cause) {
|
||||
cmdChannel.writeAndFlush(ProxyMessage.buildDisconnectMessage(udpBaseInfo.toJsonString()));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return ProxyDataTypeEnum.UDP_CONNECT.getDesc();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package org.dromara.neutrinoproxy.client.handler;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.socket.DatagramPacket;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.neutrinoproxy.client.util.UdpServerUtil;
|
||||
import org.dromara.neutrinoproxy.core.Constants;
|
||||
import org.dromara.neutrinoproxy.core.ProxyDataTypeEnum;
|
||||
import org.dromara.neutrinoproxy.core.ProxyMessage;
|
||||
import org.dromara.neutrinoproxy.core.ProxyMessageHandler;
|
||||
import org.dromara.neutrinoproxy.core.dispatcher.Match;
|
||||
import org.noear.solon.annotation.Component;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
* @author: aoshiguchen
|
||||
* @date: 2023/9/20
|
||||
*/
|
||||
@Slf4j
|
||||
@Match(type = Constants.ProxyDataTypeName.UDP_TRANSFER)
|
||||
@Component
|
||||
public class UdpProxyMessageTransferHandler implements ProxyMessageHandler {
|
||||
|
||||
@Override
|
||||
public void handle(ChannelHandlerContext ctx, ProxyMessage proxyMessage) {
|
||||
final ProxyMessage.UdpBaseInfo udpBaseInfo = JSONObject.parseObject(proxyMessage.getInfo(), ProxyMessage.UdpBaseInfo.class);
|
||||
log.debug("[UDP transfer]info:{} data:{}", proxyMessage.getInfo(), new String(proxyMessage.getData()));
|
||||
Channel channel = UdpServerUtil.takeChannel(udpBaseInfo, ctx.channel());
|
||||
if (null == channel) {
|
||||
log.error("[UDP transfer] take udp channel failed.");
|
||||
return;
|
||||
}
|
||||
log.debug("chid--->:{} port:{}", ctx.channel().id().asLongText(), ((InetSocketAddress)channel.localAddress()).getPort());
|
||||
InetSocketAddress address = new InetSocketAddress(udpBaseInfo.getTargetIp(), udpBaseInfo.getTargetPort());
|
||||
ByteBuf byteBuf = Unpooled.copiedBuffer(proxyMessage.getData());
|
||||
channel.writeAndFlush(new DatagramPacket(byteBuf, address));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return ProxyDataTypeEnum.UDP_TRANSFER.getDesc();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package org.dromara.neutrinoproxy.client.util;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author: aoshiguchen
|
||||
* @date: 2023/9/21
|
||||
*/
|
||||
@Accessors(chain = true)
|
||||
@Data
|
||||
public class LockChannel {
|
||||
// 端口号
|
||||
private int port;
|
||||
// 通道
|
||||
private Channel channel;
|
||||
// 期望的响应次数
|
||||
private int proxyResponses;
|
||||
// 超时时间(毫秒)
|
||||
private long proxyTimeoutMs;
|
||||
// 被获取的时间
|
||||
private Date takeTime;
|
||||
// 已经响应的次数
|
||||
private int responseCount;
|
||||
}
|
||||
@@ -21,6 +21,11 @@
|
||||
*/
|
||||
package org.dromara.neutrinoproxy.client.util;
|
||||
|
||||
import io.netty.channel.ChannelHandler;
|
||||
import io.netty.handler.ssl.SslHandler;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.dromara.neutrinoproxy.client.config.ProxyConfig;
|
||||
import org.dromara.neutrinoproxy.client.core.ProxyChannelBorrowListener;
|
||||
import org.dromara.neutrinoproxy.core.Constants;
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
@@ -29,10 +34,18 @@ import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelFutureListener;
|
||||
import io.netty.channel.ChannelOption;
|
||||
import io.netty.util.AttributeKey;
|
||||
import org.dromara.neutrinoproxy.core.util.FileUtil;
|
||||
import org.noear.solon.Solon;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLEngine;
|
||||
import javax.net.ssl.TrustManager;
|
||||
import javax.net.ssl.TrustManagerFactory;
|
||||
import java.io.InputStream;
|
||||
import java.security.KeyStore;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
@@ -41,6 +54,7 @@ import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
* @author: aoshiguchen
|
||||
* @date: 2022/8/31
|
||||
*/
|
||||
@Slf4j
|
||||
public class ProxyUtil {
|
||||
private static final AttributeKey<Boolean> USER_CHANNEL_WRITEABLE = AttributeKey.newInstance("user_channel_writeable");
|
||||
|
||||
@@ -50,20 +64,22 @@ public class ProxyUtil {
|
||||
|
||||
private static Map<String, Channel> realServerChannels = new ConcurrentHashMap<String, Channel>();
|
||||
|
||||
private static ConcurrentLinkedQueue<Channel> proxyChannelPool = new ConcurrentLinkedQueue<Channel>();
|
||||
private static ConcurrentLinkedQueue<Channel> tcpProxyChannelPool = new ConcurrentLinkedQueue<Channel>();
|
||||
private static ConcurrentLinkedQueue<Channel> udpProxyChannelPool = new ConcurrentLinkedQueue<>();
|
||||
|
||||
private static volatile Channel cmdChannel;
|
||||
|
||||
public static void borrowProxyChanel(Bootstrap bootstrap, final ProxyChannelBorrowListener borrowListener) {
|
||||
Channel channel = proxyChannelPool.poll();
|
||||
private static String clientId;
|
||||
private static final String CLIENT_ID_FILE = ".NEUTRINO_PROXY_CLIENT_ID";
|
||||
|
||||
public static void borrowTcpProxyChanel(Bootstrap tcpProxyTunnelBootstrap, final ProxyChannelBorrowListener borrowListener) {
|
||||
Channel channel = tcpProxyChannelPool.poll();
|
||||
if (null != channel) {
|
||||
borrowListener.success(channel);
|
||||
return;
|
||||
}
|
||||
|
||||
String serverIp = Solon.cfg().get("neutrino.proxy.client.server-ip");
|
||||
Integer serverPort = Solon.cfg().getInt("neutrino.proxy.client.server-port", 9000);
|
||||
bootstrap.connect(serverIp, serverPort).addListener((ChannelFutureListener) future -> {
|
||||
tcpProxyTunnelBootstrap.connect().addListener((ChannelFutureListener) future -> {
|
||||
if (future.isSuccess()) {
|
||||
borrowListener.success(future.channel());
|
||||
} else {
|
||||
@@ -72,18 +88,52 @@ public class ProxyUtil {
|
||||
});
|
||||
}
|
||||
|
||||
public static void returnProxyChanel(Channel proxyChanel) {
|
||||
if (proxyChannelPool.size() > MAX_POOL_SIZE) {
|
||||
public static void returnTcpProxyChanel(Channel proxyChanel) {
|
||||
if (tcpProxyChannelPool.size() > MAX_POOL_SIZE) {
|
||||
proxyChanel.close();
|
||||
} else {
|
||||
proxyChanel.config().setOption(ChannelOption.AUTO_READ, true);
|
||||
proxyChanel.attr(Constants.NEXT_CHANNEL).remove();
|
||||
proxyChannelPool.offer(proxyChanel);
|
||||
tcpProxyChannelPool.offer(proxyChanel);
|
||||
}
|
||||
}
|
||||
|
||||
public static void removeProxyChanel(Channel proxyChanel) {
|
||||
proxyChannelPool.remove(proxyChanel);
|
||||
|
||||
|
||||
public static void removeTcpProxyChanel(Channel proxyChanel) {
|
||||
tcpProxyChannelPool.remove(proxyChanel);
|
||||
}
|
||||
|
||||
public static void borrowUdpProxyChanel(Bootstrap tcpProxyTunnelBootstrap, final ProxyChannelBorrowListener borrowListener) {
|
||||
Channel channel = udpProxyChannelPool.poll();
|
||||
if (null != channel) {
|
||||
borrowListener.success(channel);
|
||||
return;
|
||||
}
|
||||
|
||||
tcpProxyTunnelBootstrap.connect().addListener((ChannelFutureListener) future -> {
|
||||
if (future.isSuccess()) {
|
||||
borrowListener.success(future.channel());
|
||||
} else {
|
||||
borrowListener.error(future.cause());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void returnUdpProxyChanel(Channel proxyChanel) {
|
||||
if (udpProxyChannelPool.size() > MAX_POOL_SIZE) {
|
||||
proxyChanel.close();
|
||||
} else {
|
||||
proxyChanel.config().setOption(ChannelOption.AUTO_READ, true);
|
||||
proxyChanel.attr(Constants.NEXT_CHANNEL).remove();
|
||||
udpProxyChannelPool.offer(proxyChanel);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void removeUdpProxyChanel(Channel proxyChanel) {
|
||||
udpProxyChannelPool.remove(proxyChanel);
|
||||
}
|
||||
|
||||
public static void setCmdChannel(Channel cmdChannel) {
|
||||
@@ -129,4 +179,48 @@ public class ProxyUtil {
|
||||
|
||||
realServerChannels.clear();
|
||||
}
|
||||
|
||||
public static String getClientId() {
|
||||
if (StringUtils.isNotBlank(clientId)) {
|
||||
return clientId;
|
||||
}
|
||||
ProxyConfig proxyConfig = Solon.context().getBean(ProxyConfig.class);
|
||||
if (StringUtils.isNotBlank(proxyConfig.getTunnel().getClientId())) {
|
||||
clientId = proxyConfig.getTunnel().getClientId();
|
||||
return clientId;
|
||||
}
|
||||
String id = FileUtil.readContentAsString(CLIENT_ID_FILE);
|
||||
if (StringUtils.isNotBlank(id)) {
|
||||
clientId = id;
|
||||
return id;
|
||||
}
|
||||
id = UUID.randomUUID().toString().replace("-", "");
|
||||
FileUtil.write(CLIENT_ID_FILE, id);
|
||||
clientId = id;
|
||||
return id;
|
||||
}
|
||||
|
||||
public static ChannelHandler createSslHandler(ProxyConfig proxyConfig) {
|
||||
try {
|
||||
InputStream jksInputStream = FileUtil.getInputStream(proxyConfig.getTunnel().getJksPath());
|
||||
|
||||
SSLContext clientContext = SSLContext.getInstance("TLS");
|
||||
final KeyStore ks = KeyStore.getInstance("JKS");
|
||||
ks.load(jksInputStream, proxyConfig.getTunnel().getKeyStorePassword().toCharArray());
|
||||
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
|
||||
tmf.init(ks);
|
||||
TrustManager[] trustManagers = tmf.getTrustManagers();
|
||||
clientContext.init(null, trustManagers, null);
|
||||
|
||||
SSLEngine sslEngine = clientContext.createSSLEngine();
|
||||
sslEngine.setUseClientMode(true);
|
||||
|
||||
return new SslHandler(sslEngine);
|
||||
} catch (Exception e) {
|
||||
log.error("create SSL handler failed", e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package org.dromara.neutrinoproxy.client.util;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* @author: aoshiguchen
|
||||
* @date: 2023/9/21
|
||||
*/
|
||||
@Accessors(chain = true)
|
||||
@Data
|
||||
public class UdpChannelBindInfo {
|
||||
private Channel tunnelChannel;
|
||||
private LockChannel lockChannel;
|
||||
private String visitorId;
|
||||
private String visitorIp;
|
||||
private int visitorPort;
|
||||
private int serverPort;
|
||||
private String targetIp;
|
||||
private int targetPort;
|
||||
}
|
||||
@@ -0,0 +1,196 @@
|
||||
package org.dromara.neutrinoproxy.client.util;
|
||||
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelFuture;
|
||||
import io.netty.channel.ChannelFutureListener;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.dromara.neutrinoproxy.client.config.ProxyConfig;
|
||||
import org.dromara.neutrinoproxy.client.constant.Constants;
|
||||
import org.dromara.neutrinoproxy.client.core.CustomThreadFactory;
|
||||
import org.dromara.neutrinoproxy.core.ProxyMessage;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
/**
|
||||
* @author: aoshiguchen
|
||||
* @date: 2023/9/21
|
||||
*/
|
||||
@Slf4j
|
||||
public class UdpServerUtil {
|
||||
private static final Boolean isSupportUdp = Boolean.FALSE;
|
||||
private static int udpServerPortMin = 0;
|
||||
private static int udpServerPortMax = 0;
|
||||
private static int nextUdpServerPort = 0;
|
||||
private static Bootstrap udpServerBootstrap;
|
||||
private static int defaultUdpServerPort;
|
||||
private static Channel defaultUdpServerChannel;
|
||||
private static Map<Integer, Channel> portToChannelMap = new ConcurrentHashMap<>();
|
||||
/**
|
||||
* udp服务空闲端口池
|
||||
*/
|
||||
private static ConcurrentLinkedQueue<Integer> udpServerFreePortPool = new ConcurrentLinkedQueue<>();
|
||||
private static List<LockChannel> lockChannelList = new ArrayList<>();
|
||||
/**
|
||||
* lockChannel扫描器
|
||||
*/
|
||||
private static final ScheduledExecutorService lockChannelScanner = Executors.newSingleThreadScheduledExecutor(new CustomThreadFactory("lockChannelScanner"));
|
||||
|
||||
/**
|
||||
* 初始化UDP缓存
|
||||
* 1、初始化一个基础UDP服务,用于不需要响应的UDP转发
|
||||
* 2、维护一个UDP服务池,用于需要响应的UDP转发
|
||||
* @param proxyConfig
|
||||
*/
|
||||
public static void initCache(ProxyConfig proxyConfig, Bootstrap udpServerBootstrap) {
|
||||
if (null == proxyConfig.getClient().getUdp() || StringUtils.isEmpty(proxyConfig.getClient().getUdp().getPuppetPortRange())) {
|
||||
return;
|
||||
}
|
||||
ProxyConfig.Udp udpConfig = proxyConfig.getClient().getUdp();
|
||||
if (StringUtils.isEmpty(udpConfig.getPuppetPortRange())) {
|
||||
return;
|
||||
}
|
||||
String[] tmp = udpConfig.getPuppetPortRange().split("-");
|
||||
if (null == tmp || tmp.length != 2) {
|
||||
log.error("client udp config error!");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
udpServerPortMin = Integer.parseInt(tmp[0]);
|
||||
udpServerPortMax = Integer.parseInt(tmp[1]);
|
||||
if (udpServerPortMax <= udpServerPortMin) {
|
||||
// 至少得给1个udp端口,一个用于基础无响应UDP转发
|
||||
throw new RuntimeException("client udp config error!");
|
||||
}
|
||||
nextUdpServerPort = udpServerPortMin;
|
||||
UdpServerUtil.udpServerBootstrap = udpServerBootstrap;
|
||||
log.info("udp proxy server port: {} ~ {}", udpServerPortMin, udpServerPortMax);
|
||||
// 初始化udp服务
|
||||
initUdpServer();
|
||||
// 初始化lockChannel扫描器
|
||||
lockChannelScanner.scheduleWithFixedDelay(UdpServerUtil::lockChannelScan, 5, 3, TimeUnit.SECONDS);
|
||||
} catch (Exception e) {
|
||||
log.error("client udp config error!", e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化udp服务
|
||||
*/
|
||||
private static void initUdpServer() {
|
||||
defaultUdpServerPort = nextUdpServerPort();
|
||||
defaultUdpServerChannel = bindPort(defaultUdpServerPort);
|
||||
// 初始化默认最多额外开启5个udp服务,其他的需要时再启动
|
||||
for (int i = 0; i < 5; i++) {
|
||||
if (!hasNextUdpServerPort()) {
|
||||
return;
|
||||
}
|
||||
int port = nextUdpServerPort();
|
||||
Channel ch = bindPort(port);
|
||||
portToChannelMap.put(port, ch);
|
||||
udpServerFreePortPool.offer(port);
|
||||
}
|
||||
while (hasNextUdpServerPort()) {
|
||||
udpServerFreePortPool.offer(nextUdpServerPort());
|
||||
}
|
||||
}
|
||||
|
||||
private static Channel bindPort(int port) {
|
||||
try {
|
||||
ChannelFuture channelFuture = udpServerBootstrap.bind(port).sync();
|
||||
log.info("[udp server] bind port:{} success!", port);
|
||||
return channelFuture.channel();
|
||||
} catch (InterruptedException e) {
|
||||
log.error("[udp server] bind port:{} error!", port);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static Boolean hasNextUdpServerPort() {
|
||||
return nextUdpServerPort <= udpServerPortMax;
|
||||
}
|
||||
|
||||
public static synchronized int nextUdpServerPort() {
|
||||
return nextUdpServerPort++;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取一个可用的udp通道
|
||||
* 1、如果期待的响应为0,或者超时时间<=0,则认为不需要响应,直接返回默认的udp服务,否则继续下一步
|
||||
* 2、从可用端口队列中找到一个可用端口,若不存在可用端口,则降级为不需要响应,返回默认的udp服务。否则继续下一步
|
||||
* 3、根据该端口找到udp服务通道,找不到则绑定端口开启一个通道并返回。将该端口添加到锁定列表
|
||||
* 4、维护一个定时器的,定时扫描锁定列表,及时释放锁定的端口
|
||||
* @param info
|
||||
* @return
|
||||
*/
|
||||
public static synchronized Channel takeChannel(ProxyMessage.UdpBaseInfo info, Channel tunnelChannel) {
|
||||
if (info.getProxyResponses() <= 0 || info.getProxyTimeoutMs() <= 0) {
|
||||
return defaultUdpServerChannel;
|
||||
}
|
||||
Integer port = udpServerFreePortPool.poll();
|
||||
if (null == port) {
|
||||
return defaultUdpServerChannel;
|
||||
}
|
||||
Channel channel = portToChannelMap.get(port);
|
||||
if (null == channel) {
|
||||
channel = bindPort(port);
|
||||
portToChannelMap.put(port, channel);
|
||||
}
|
||||
// 添加到锁定队列
|
||||
LockChannel lockChannel = new LockChannel()
|
||||
.setPort(port)
|
||||
.setChannel(channel)
|
||||
.setProxyResponses(info.getProxyResponses())
|
||||
.setProxyTimeoutMs(info.getProxyTimeoutMs())
|
||||
.setTakeTime(new Date())
|
||||
.setResponseCount(0);
|
||||
lockChannelList.add(lockChannel);
|
||||
channel.attr(Constants.UDP_CHANNEL_BIND_KEY).set(new UdpChannelBindInfo()
|
||||
.setTunnelChannel(tunnelChannel)
|
||||
.setVisitorId(info.getVisitorId())
|
||||
.setVisitorIp(info.getVisitorIp())
|
||||
.setVisitorPort(info.getVisitorPort())
|
||||
.setServerPort(info.getServerPort())
|
||||
.setTargetIp(info.getTargetIp())
|
||||
.setTargetPort(info.getTargetPort())
|
||||
.setLockChannel(lockChannel)
|
||||
);
|
||||
return channel;
|
||||
}
|
||||
|
||||
/**
|
||||
* lockChannel扫描
|
||||
*/
|
||||
public static synchronized void lockChannelScan() {
|
||||
if (lockChannelList.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
Iterator<LockChannel> iter = lockChannelList.iterator();
|
||||
if (iter.hasNext()) {
|
||||
LockChannel lockChannel = iter.next();
|
||||
if (lockChannel.getResponseCount() >= lockChannel.getProxyResponses() ||
|
||||
System.currentTimeMillis() - lockChannel.getTakeTime().getTime() >= lockChannel.getProxyTimeoutMs()
|
||||
) {
|
||||
iter.remove();
|
||||
UdpChannelBindInfo udpChannelBindInfo = lockChannel.getChannel().attr(Constants.UDP_CHANNEL_BIND_KEY).get();
|
||||
// 此处必须释放代理隧道
|
||||
closeChannel(udpChannelBindInfo.getTunnelChannel());
|
||||
lockChannel.getChannel().attr(Constants.UDP_CHANNEL_BIND_KEY).set(null);
|
||||
udpServerFreePortPool.offer(lockChannel.getPort());
|
||||
log.debug("[udp channel]release udp channel port:{}", lockChannel.getPort());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void closeChannel(Channel channel) {
|
||||
try {
|
||||
channel.writeAndFlush(Unpooled.EMPTY_BUFFER).addListener(ChannelFutureListener.CLOSE);
|
||||
} catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,15 +9,44 @@ neutrino:
|
||||
length-field-length: 4
|
||||
initial-bytes-to-strip: 0
|
||||
length-adjustment: 0
|
||||
read-idle-time: 40
|
||||
write-idle-time: 8
|
||||
read-idle-time: 120
|
||||
write-idle-time: 20
|
||||
all-idle-time-seconds: 0
|
||||
client:
|
||||
logger:
|
||||
# 日志级别
|
||||
level: ${LOG_LEVEL:info}
|
||||
tunnel:
|
||||
# 线程池相关配置,用于技术调优,可忽略
|
||||
thread-count: 50
|
||||
# 隧道SSL证书配置
|
||||
key-store-password: ${STORE_PASS:123456}
|
||||
jks-path: ${JKS_PATH:classpath:/test.jks}
|
||||
# 服务端IP
|
||||
server-ip: ${SERVER_IP:localhost}
|
||||
# 服务端端口(对应服务端app.yml中的tunnel.port、tunnel.ssl-port)
|
||||
server-port: ${SERVER_PORT:9002}
|
||||
# 是否启用SSL(注意:该配置必须和server-port对应上)
|
||||
ssl-enable: ${SSL_ENABLE:true}
|
||||
obtain-license-interval: 5
|
||||
license-key: ${LICENSE_KEY:b0a907332b474b25897c4dcb31fc7eb6}
|
||||
# 客户端连接唯一凭证
|
||||
license-key: ${LICENSE_KEY:}
|
||||
# 客户端唯一身份标识(可忽略,若不设置首次启动会自动生成)
|
||||
client-id: ${CLIENT_ID:}
|
||||
# 是否开启隧道传输报文日志(日志级别为debug时开启才有效)
|
||||
transfer-log-enable: ${CLIENT_LOG:false}
|
||||
# 是否开启心跳日志
|
||||
heartbeat-log-enable: ${HEARTBEAT_LOG:false}
|
||||
# 重连设置
|
||||
reconnection:
|
||||
# 重连间隔(秒)
|
||||
interval-seconds: 10
|
||||
# 是否开启无限重连(未开启时,客户端license不合法会自动停止应用,开启了则不会,请谨慎开启)
|
||||
unlimited: false
|
||||
client:
|
||||
udp:
|
||||
# 线程池相关配置,用于技术调优,可忽略
|
||||
boss-thread-count: 5
|
||||
work-thread-count: 20
|
||||
# udp傀儡端口范围
|
||||
puppet-port-range: 10000-10500
|
||||
# 是否开启隧道传输报文日志(日志级别为debug时开启才有效)
|
||||
transfer-log-enable: ${CLIENT_LOG:false}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
<property name="LOG_FILE" value="/work/projects/neutrino-proxy-client/app.log"/>
|
||||
<property name="LOG_FILE" value="./logs/neutrino-proxy-client.log"/>
|
||||
<property name="LOG_PATTERN" value="%d{yyyy-MM-dd HH:mm:ss.SSS} %contextName [%thread] %-5level %logger{50} - %msg%n"/>
|
||||
<!-- <property name="ENCODE" value="utf8" />-->
|
||||
|
||||
|
||||
@@ -25,6 +25,8 @@ package org.dromara.neutrinoproxy.core;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.util.AttributeKey;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author: aoshiguchen
|
||||
@@ -38,6 +40,16 @@ public interface Constants {
|
||||
|
||||
AttributeKey<Integer> LICENSE_ID = AttributeKey.newInstance("license_id");
|
||||
|
||||
AttributeKey<String> TARGET_IP = AttributeKey.newInstance("targetIp");
|
||||
AttributeKey<Integer> TARGET_PORT = AttributeKey.newInstance("targetPort");
|
||||
AttributeKey<Integer> PROXY_RESPONSES = AttributeKey.newInstance("proxyResponses");
|
||||
AttributeKey<Long> PROXY_TIMEOUT_MS = AttributeKey.newInstance("proxyTimeoutMs");
|
||||
|
||||
// 临时解决 udp channel被close的问题
|
||||
AttributeKey<Boolean> IS_UDP_KEY = AttributeKey.newInstance("isUdp");
|
||||
AttributeKey<InetSocketAddress> SENDER = AttributeKey.newInstance("sender");
|
||||
|
||||
|
||||
int HEADER_SIZE = 4;
|
||||
int TYPE_SIZE = 1;
|
||||
int SERIAL_NUMBER_SIZE = 8;
|
||||
@@ -49,6 +61,9 @@ public interface Constants {
|
||||
String CONNECT = "CONNECT";
|
||||
String DISCONNECT = "DISCONNECT";
|
||||
String TRANSFER = "TRANSFER";
|
||||
String UDP_CONNECT = "UDP_CONNECT";
|
||||
String UDP_DISCONNECT = "UDP_DISCONNECT";
|
||||
String UDP_TRANSFER = "UDP_TRANSFER";
|
||||
String ERROR = "ERROR";
|
||||
String PORT_MAPPING_SYNC = "PORT_MAPPING_SYNC";
|
||||
}
|
||||
|
||||
@@ -33,9 +33,12 @@ import lombok.Getter;
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum ExceptionEnum {
|
||||
SUCCESS(0, "成功"),
|
||||
AUTH_FAILED(1, "认证失败"),
|
||||
CONNECT_FAILED(2, "连接失败");
|
||||
SUCCESS(0, "success"),
|
||||
AUTH_FAILED(1, "auth failed"),
|
||||
CONNECT_FAILED(2, "connect failed"),
|
||||
@Deprecated
|
||||
LICENSE_CANNOT_REPEAT_CONNECT(3, "license cannot multiple client simultaneous use"),
|
||||
;
|
||||
|
||||
private Integer code;
|
||||
private String msg;
|
||||
|
||||
@@ -38,13 +38,16 @@ import java.util.stream.Stream;
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum ProxyDataTypeEnum {
|
||||
HEARTBEAT(0x01, Constants.ProxyDataTypeName.HEARTBEAT, "心跳"),
|
||||
AUTH(0x02, Constants.ProxyDataTypeName.AUTH,"认证"),
|
||||
CONNECT(0x03, Constants.ProxyDataTypeName.CONNECT,"连接"),
|
||||
DISCONNECT(0x04, Constants.ProxyDataTypeName.DISCONNECT,"断开连接"),
|
||||
TRANSFER(0x05, Constants.ProxyDataTypeName.TRANSFER,"数据传输"),
|
||||
ERROR(0x06, Constants.ProxyDataTypeName.ERROR,"异常"),
|
||||
PORT_MAPPING_SYNC(0x07, Constants.ProxyDataTypeName.PORT_MAPPING_SYNC, "端口映射同步");
|
||||
HEARTBEAT(0x01, Constants.ProxyDataTypeName.HEARTBEAT, "HEARTBEAT"),
|
||||
AUTH(0x02, Constants.ProxyDataTypeName.AUTH,"AUTH"),
|
||||
CONNECT(0x03, Constants.ProxyDataTypeName.CONNECT,"CONNECT"),
|
||||
DISCONNECT(0x04, Constants.ProxyDataTypeName.DISCONNECT,"DISCONNECT"),
|
||||
TRANSFER(0x05, Constants.ProxyDataTypeName.TRANSFER,"TRANSFER"),
|
||||
ERROR(0x06, Constants.ProxyDataTypeName.ERROR,"ERROR"),
|
||||
PORT_MAPPING_SYNC(0x07, Constants.ProxyDataTypeName.PORT_MAPPING_SYNC, "PORT_MAPPING_SYNC"),
|
||||
UDP_CONNECT(0x08, Constants.ProxyDataTypeName.UDP_CONNECT,"UDP_CONNECT"),
|
||||
UDP_DISCONNECT(0x09, Constants.ProxyDataTypeName.UDP_DISCONNECT,"UDP_DISCONNECT"),
|
||||
UDP_TRANSFER(0x10, Constants.ProxyDataTypeName.UDP_TRANSFER,"UDP_TRANSFER");
|
||||
private static Map<Integer,ProxyDataTypeEnum> cache = Stream.of(values()).collect(Collectors.toMap(ProxyDataTypeEnum::getType, Function.identity()));
|
||||
|
||||
private int type;
|
||||
|
||||
@@ -66,6 +66,18 @@ public class ProxyMessage {
|
||||
* 通用异常信息
|
||||
*/
|
||||
public static final byte TYPE_ERROR = 0x06;
|
||||
/**
|
||||
* UDP代理隧道连接
|
||||
*/
|
||||
public static final byte TYPE_UDP_CONNECT = 0x08;
|
||||
/**
|
||||
* UDP代理隧道断开连接
|
||||
*/
|
||||
public static final byte TYPE_UDP_DISCONNECT = 0x09;
|
||||
/**
|
||||
* UDP数据传输
|
||||
*/
|
||||
public static final byte TYPE_UDP_TRANSFER = 0x10;
|
||||
|
||||
/**
|
||||
* 消息类型
|
||||
@@ -100,9 +112,9 @@ public class ProxyMessage {
|
||||
return create().setType(TYPE_HEARTBEAT);
|
||||
}
|
||||
|
||||
public static ProxyMessage buildAuthMessage(String info) {
|
||||
public static ProxyMessage buildAuthMessage(String info, String clientId) {
|
||||
return create().setType(TYPE_AUTH)
|
||||
.setInfo(info);
|
||||
.setInfo(info + "," + clientId);
|
||||
}
|
||||
|
||||
public static ProxyMessage buildAuthResultMessage(Integer code, String msg, String licenseKey) {
|
||||
@@ -130,6 +142,21 @@ public class ProxyMessage {
|
||||
.setData(data);
|
||||
}
|
||||
|
||||
|
||||
public static ProxyMessage buildUdpConnectMessage(UdpBaseInfo info) {
|
||||
return create().setType(TYPE_UDP_CONNECT)
|
||||
.setInfo(info.toJsonString());
|
||||
}
|
||||
|
||||
public static ProxyMessage buildUdpDisconnectMessage() {
|
||||
return create().setType(TYPE_UDP_DISCONNECT);
|
||||
}
|
||||
|
||||
public static ProxyMessage buildUdpTransferMessage(UdpBaseInfo info) {
|
||||
return create().setType(TYPE_UDP_TRANSFER)
|
||||
.setInfo(info.toJsonString());
|
||||
}
|
||||
|
||||
public static ProxyMessage buildErrMessage(ExceptionEnum exceptionEnum, String info) {
|
||||
JSONObject data = new JSONObject();
|
||||
data.put("code", exceptionEnum.getCode());
|
||||
@@ -142,4 +169,26 @@ public class ProxyMessage {
|
||||
public static ProxyMessage buildErrMessage(ExceptionEnum exceptionEnum) {
|
||||
return buildErrMessage(exceptionEnum, null);
|
||||
}
|
||||
|
||||
@Accessors(chain = true)
|
||||
@Data
|
||||
public static class UdpBaseInfo {
|
||||
private String visitorId;
|
||||
private String visitorIp;
|
||||
private int visitorPort;
|
||||
private int serverPort;
|
||||
private String targetIp;
|
||||
private int targetPort;
|
||||
/**
|
||||
* 期待的响应数
|
||||
*/
|
||||
private int proxyResponses;
|
||||
/**
|
||||
* 超时时间(<=0时,相当于不需要响应)
|
||||
*/
|
||||
private long proxyTimeoutMs;
|
||||
public String toJsonString() {
|
||||
return JSONObject.toJSONString(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,10 +35,10 @@ public class DefaultDispatcher<Context, Data> implements Dispatcher<Context, Dat
|
||||
private Function<Data,String> matcher;
|
||||
|
||||
public DefaultDispatcher(String name, List<? extends Handler<Context,Data>> handlerList, Function<Data,String> matcher) {
|
||||
Assert.notNull(name, "名称不能为空!");
|
||||
Assert.notNull(matcher, "匹配器不能为空!");
|
||||
Assert.notNull(name, "name cannot empty!");
|
||||
Assert.notNull(matcher, "matcher cannot empty!");
|
||||
if (CollectionUtil.isEmpty(handlerList)) {
|
||||
log.error("{} 处理器列表为空.", name);
|
||||
log.error("{} handler list empty.", name);
|
||||
return;
|
||||
}
|
||||
this.name = name == null ? "" : name;
|
||||
@@ -48,20 +48,20 @@ public class DefaultDispatcher<Context, Data> implements Dispatcher<Context, Dat
|
||||
for (Handler handler : handlerList) {
|
||||
Match match = handler.getClass().getAnnotation(Match.class);
|
||||
if (null == match) {
|
||||
log.warn("{} 类: {} 缺失Match注解", this.name, handler.getClass().getName());
|
||||
log.warn("{} class: {} notfound Match annotation", this.name, handler.getClass().getName());
|
||||
continue;
|
||||
}
|
||||
if (StrUtil.isEmpty(match.type())) {
|
||||
log.warn("{} 类: {} match注解缺失type参数!", this.name, handler.getClass().getName());
|
||||
log.warn("{} class: {} match annotation notfound type param!", this.name, handler.getClass().getName());
|
||||
continue;
|
||||
}
|
||||
if (handlerMap.containsKey(match.type())) {
|
||||
log.warn("{} 类: {} match注解type值{} 存在重复!", this.name, handler.getClass().getName(), match.type());
|
||||
log.warn("{} class: {} match annotation type value {} repeat!", this.name, handler.getClass().getName(), match.type());
|
||||
continue;
|
||||
}
|
||||
handlerMap.put(match.type(), handler);
|
||||
}
|
||||
log.info("{} 处理器初始化完成", this.name);
|
||||
log.info("{} dispatcher init success", this.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -71,19 +71,18 @@ public class DefaultDispatcher<Context, Data> implements Dispatcher<Context, Dat
|
||||
}
|
||||
String type = matcher.apply(data);
|
||||
if (null == type) {
|
||||
log.warn("{} 获取匹配类型失败 data:{}", this.name, JSONObject.toJSONString(data));
|
||||
log.warn("{} get match type failed data:{}", this.name, JSONObject.toJSONString(data));
|
||||
return;
|
||||
}
|
||||
Handler<Context,Data> handler = handlerMap.get(type);
|
||||
if (null == handler) {
|
||||
// log.debug("{} 找不到匹配的处理器 type:{}", this.name, type);
|
||||
return;
|
||||
}
|
||||
String handlerName = handler.name();
|
||||
if (StrUtil.isEmpty(handlerName)) {
|
||||
handlerName = TypeUtil.getSimpleName(handler.getClass());
|
||||
}
|
||||
log.debug("{} 处理器[{}]执行.", this.name, handlerName);
|
||||
log.debug("{} handler[{}]execute.", this.name, handlerName);
|
||||
handler.handle(context, data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,6 +51,10 @@
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mariadb.jdbc</groupId>
|
||||
<artifactId>mariadb-java-client</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zaxxer</groupId>
|
||||
<artifactId>HikariCP</artifactId>
|
||||
@@ -66,7 +70,7 @@
|
||||
<filtering>false</filtering>
|
||||
|
||||
<excludes>
|
||||
<exclude>app-*.yml</exclude>
|
||||
<exclude>app-dev.yml</exclude>
|
||||
</excludes>
|
||||
</resource>
|
||||
</resources>
|
||||
|
||||
@@ -1,15 +1,25 @@
|
||||
package org.dromara.neutrinoproxy.server;
|
||||
|
||||
import ch.qos.logback.classic.Level;
|
||||
import ch.qos.logback.classic.Logger;
|
||||
import ch.qos.logback.classic.LoggerContext;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.dromara.solonplugins.job.annotation.EnableJob;
|
||||
import org.noear.solon.Solon;
|
||||
import org.noear.solon.SolonApp;
|
||||
import org.noear.solon.annotation.SolonMain;
|
||||
import org.noear.solon.web.cors.CrossFilter;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author: aoshiguchen
|
||||
* @date: 2022/6/16
|
||||
*/
|
||||
@Slf4j
|
||||
@EnableJob
|
||||
@SolonMain
|
||||
public class ProxyServer {
|
||||
@@ -18,6 +28,25 @@ public class ProxyServer {
|
||||
Solon.start(ProxyServer.class, args, app -> {
|
||||
// 跨域支持。加-1 优先级更高
|
||||
app.filter(-1, new CrossFilter().allowedOrigins("*"));
|
||||
// 设置日志级别
|
||||
setLogLevel(app);
|
||||
});
|
||||
}
|
||||
|
||||
private static void setLogLevel(SolonApp app) {
|
||||
String loggerLevel = app.cfg().get("neutrino.proxy.logger.level");
|
||||
if (StringUtils.isBlank(loggerLevel)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
Level level = Level.toLevel(loggerLevel);
|
||||
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
|
||||
for (Logger logger : loggerContext.getLoggerList()) {
|
||||
logger.setLevel(level);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("logger level set failed", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,15 +57,14 @@ public class DBInitialize implements EventListener<AppLoadEndEvent> {
|
||||
dbTypeEnum = DbTypeEnum.of(dbConfig.getType());
|
||||
Assert.notNull(dbTypeEnum, "neutrino.data.db.type取值异常!");
|
||||
|
||||
log.info("{}数据库初始化...", dbConfig.getType());
|
||||
log.info("{} database init...", dbConfig.getType());
|
||||
initDBStructure();
|
||||
initDBData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEvent(AppLoadEndEvent appLoadEndEvent) throws Throwable {
|
||||
// TODO 该事件有50%的概率不触发
|
||||
System.out.println("11");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -83,7 +82,7 @@ public class DBInitialize implements EventListener<AppLoadEndEvent> {
|
||||
}
|
||||
sql += "\r\n" + line.trim();
|
||||
if (sql.endsWith(";")) {
|
||||
log.debug("初始化数据库表 sql:{}", sql);
|
||||
log.debug("init database table sql:{}", sql);
|
||||
Db.update(sql);
|
||||
sql = "";
|
||||
}
|
||||
@@ -117,7 +116,7 @@ public class DBInitialize implements EventListener<AppLoadEndEvent> {
|
||||
}
|
||||
sql += "\r\n" + line.trim();
|
||||
if (sql.endsWith(";")) {
|
||||
log.debug("初始化数据[table={}] sql:{}", tableName, sql);
|
||||
log.debug("init database data[table={}] sql:{}", tableName, sql);
|
||||
Db.update(sql);
|
||||
sql = "";
|
||||
}
|
||||
|
||||
@@ -31,7 +31,6 @@ public class DbConfiguration {
|
||||
dataSource.setJournalMode(SQLiteConfig.JournalMode.WAL.getValue());
|
||||
return dataSource;
|
||||
} else if (DbTypeEnum.MYSQL == dbTypeEnum) {
|
||||
HikariDataSource dataSource = new HikariDataSource();
|
||||
String driver = "com.mysql.cj.jdbc.Driver";
|
||||
try {
|
||||
Class.forName(driver);
|
||||
@@ -39,24 +38,26 @@ public class DbConfiguration {
|
||||
// 对类名的判断,异常则说明不存在:
|
||||
driver = "com.mysql.jdbc.Driver";
|
||||
}
|
||||
dataSource.setDriverClassName(driver);
|
||||
dataSource.setJdbcUrl(dbConfig.getUrl());
|
||||
dataSource.setMinimumIdle(5);
|
||||
dataSource.setMaximumPoolSize(20);
|
||||
dataSource.setMaxLifetime(60000);
|
||||
// dataSource.setInitialSize(5);
|
||||
// dataSource.setMinIdle(5);
|
||||
// dataSource.setMaxActive(20);
|
||||
// dataSource.setMaxWait(60000);
|
||||
// dataSource.setPoolPreparedStatements(true);
|
||||
dataSource.setUsername(dbConfig.getUsername());
|
||||
dataSource.setPassword(dbConfig.getPassword());
|
||||
return dataSource;
|
||||
return newHikariDataSource(dbConfig, driver);
|
||||
} else if (DbTypeEnum.MARIADB == dbTypeEnum) {
|
||||
return newHikariDataSource(dbConfig, "org.mariadb.jdbc.Driver");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private HikariDataSource newHikariDataSource(DbConfig dbConfig, String driverClass) {
|
||||
HikariDataSource dataSource = new HikariDataSource();
|
||||
dataSource.setDriverClassName(driverClass);
|
||||
dataSource.setJdbcUrl(dbConfig.getUrl());
|
||||
dataSource.setMinimumIdle(5);
|
||||
dataSource.setMaximumPoolSize(20);
|
||||
dataSource.setMaxLifetime(60000);
|
||||
dataSource.setUsername(dbConfig.getUsername());
|
||||
dataSource.setPassword(dbConfig.getPassword());
|
||||
return dataSource;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public void db1_ext(@Db("db") GlobalConfig globalConfig) {
|
||||
MetaObjectHandler metaObjectHandler = new MetaObjectHandlerImpl();
|
||||
|
||||
@@ -18,10 +18,15 @@ public class ProxyConfig {
|
||||
@Inject("${neutrino.proxy.protocol}")
|
||||
private Protocol protocol;
|
||||
/**
|
||||
* 服务端配置
|
||||
* 代理服务配置
|
||||
*/
|
||||
@Inject("${neutrino.proxy.server}")
|
||||
private Server server;
|
||||
/**
|
||||
* 代理隧道配置
|
||||
*/
|
||||
@Inject("${neutrino.proxy.tunnel}")
|
||||
private Tunnel tunnel;
|
||||
|
||||
@Data
|
||||
public static class Protocol {
|
||||
@@ -37,15 +42,39 @@ public class ProxyConfig {
|
||||
|
||||
@Data
|
||||
public static class Server {
|
||||
private Tcp tcp;
|
||||
private Udp udp;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Tunnel {
|
||||
private Integer bossThreadCount;
|
||||
private Integer workThreadCount;
|
||||
private Integer port;
|
||||
private Integer sslPort;
|
||||
private String keyStorePassword;
|
||||
private String keyManagerPassword;
|
||||
private String jksPath;
|
||||
private Boolean transferLogEnable;
|
||||
private Boolean heartbeatLogEnable;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Tcp {
|
||||
private Integer bossThreadCount;
|
||||
private Integer workThreadCount;
|
||||
private String domainName;
|
||||
private Integer httpProxyPort;
|
||||
private Integer httpsProxyPort;
|
||||
private String keyStorePassword;
|
||||
private String jksPath;
|
||||
private Boolean transferLogEnable;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Udp {
|
||||
private Integer bossThreadCount;
|
||||
private Integer workThreadCount;
|
||||
private Boolean transferLogEnable;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,14 @@
|
||||
package org.dromara.neutrinoproxy.server.base.proxy;
|
||||
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
import io.netty.bootstrap.ServerBootstrap;
|
||||
import io.netty.channel.ChannelInitializer;
|
||||
import io.netty.channel.ChannelOption;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
import io.netty.channel.socket.SocketChannel;
|
||||
import io.netty.channel.socket.nio.NioDatagramChannel;
|
||||
import io.netty.channel.socket.nio.NioServerSocketChannel;
|
||||
import io.netty.handler.logging.LoggingHandler;
|
||||
import org.dromara.neutrinoproxy.core.ProxyDataTypeEnum;
|
||||
import org.dromara.neutrinoproxy.core.ProxyMessage;
|
||||
import org.dromara.neutrinoproxy.core.ProxyMessageHandler;
|
||||
@@ -7,6 +16,9 @@ import org.dromara.neutrinoproxy.core.dispatcher.DefaultDispatcher;
|
||||
import org.dromara.neutrinoproxy.core.dispatcher.Dispatcher;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.nio.NioEventLoopGroup;
|
||||
import org.dromara.neutrinoproxy.server.proxy.core.BytesMetricsHandler;
|
||||
import org.dromara.neutrinoproxy.server.proxy.core.TcpVisitorChannelHandler;
|
||||
import org.dromara.neutrinoproxy.server.proxy.core.UdpVisitorChannelHandler;
|
||||
import org.noear.solon.Solon;
|
||||
import org.noear.solon.annotation.Bean;
|
||||
import org.noear.solon.annotation.Configuration;
|
||||
@@ -26,21 +38,89 @@ public class ProxyConfiguration implements LifecycleBean {
|
||||
@Override
|
||||
public void start() throws Throwable {
|
||||
List<ProxyMessageHandler> list = Solon.context().getBeansOfType(ProxyMessageHandler.class);
|
||||
Dispatcher<ChannelHandlerContext, ProxyMessage> dispatcher = new DefaultDispatcher<>("消息调度器", list,
|
||||
proxyMessage -> ProxyDataTypeEnum.of((int)proxyMessage.getType()) == null ?
|
||||
null : ProxyDataTypeEnum.of((int)proxyMessage.getType()).getName());
|
||||
Dispatcher<ChannelHandlerContext, ProxyMessage> dispatcher = new DefaultDispatcher<>("MessageDispatcher", list,
|
||||
proxyMessage -> ProxyDataTypeEnum.of((int)proxyMessage.getType()) == null ?
|
||||
null : ProxyDataTypeEnum.of((int)proxyMessage.getType()).getName());
|
||||
|
||||
Solon.context().wrapAndPut(Dispatcher.class, dispatcher);
|
||||
}
|
||||
|
||||
@Bean("serverBossGroup")
|
||||
public NioEventLoopGroup serverBossGroup(@Inject ProxyConfig proxyConfig) {
|
||||
return new NioEventLoopGroup(proxyConfig.getServer().getBossThreadCount());
|
||||
@Bean("tcpServerBossGroup")
|
||||
public NioEventLoopGroup tcpServerBossGroup(@Inject ProxyConfig proxyConfig) {
|
||||
return new NioEventLoopGroup(proxyConfig.getServer().getTcp().getBossThreadCount());
|
||||
}
|
||||
|
||||
@Bean("serverWorkerGroup")
|
||||
public NioEventLoopGroup serverWorkerGroup(@Inject ProxyConfig proxyConfig) {
|
||||
return new NioEventLoopGroup(proxyConfig.getServer().getWorkThreadCount());
|
||||
@Bean("tcpServerWorkerGroup")
|
||||
public NioEventLoopGroup tcpServerWorkerGroup(@Inject ProxyConfig proxyConfig) {
|
||||
return new NioEventLoopGroup(proxyConfig.getServer().getTcp().getWorkThreadCount());
|
||||
}
|
||||
|
||||
@Bean("tcpServerBootstrap")
|
||||
public ServerBootstrap tcpServerBootstrap(@Inject("tcpServerBossGroup") NioEventLoopGroup tcpServerBossGroup,
|
||||
@Inject("tcpServerWorkerGroup") NioEventLoopGroup tcpServerWorkerGroup,
|
||||
@Inject ProxyConfig proxyConfig
|
||||
) {
|
||||
ServerBootstrap bootstrap = new ServerBootstrap();
|
||||
bootstrap.group(tcpServerBossGroup, tcpServerWorkerGroup)
|
||||
.channel(NioServerSocketChannel.class)
|
||||
.childHandler(new ChannelInitializer<SocketChannel>() {
|
||||
@Override
|
||||
public void initChannel(SocketChannel ch) throws Exception {
|
||||
if (null != proxyConfig.getServer().getTcp().getTransferLogEnable() && proxyConfig.getServer().getTcp().getTransferLogEnable()) {
|
||||
ch.pipeline().addFirst(new LoggingHandler(TcpVisitorChannelHandler.class));
|
||||
}
|
||||
ch.pipeline().addFirst(new BytesMetricsHandler());
|
||||
ch.pipeline().addLast(new TcpVisitorChannelHandler());
|
||||
}
|
||||
});
|
||||
return bootstrap;
|
||||
}
|
||||
|
||||
@Bean("udpServerBossGroup")
|
||||
private NioEventLoopGroup udpServerBossGroup(@Inject ProxyConfig proxyConfig) {
|
||||
return new NioEventLoopGroup(proxyConfig.getServer().getUdp().getBossThreadCount());
|
||||
}
|
||||
|
||||
@Bean("udpServerWorkerGroup")
|
||||
private NioEventLoopGroup udpServerWorkerGroup(@Inject ProxyConfig proxyConfig) {
|
||||
return new NioEventLoopGroup(proxyConfig.getServer().getUdp().getWorkThreadCount());
|
||||
}
|
||||
|
||||
@Bean("udpServerBootstrap")
|
||||
public Bootstrap udpServerBootstrap(@Inject("udpServerBossGroup") NioEventLoopGroup udpServerBossGroup,
|
||||
@Inject("udpServerWorkerGroup") NioEventLoopGroup udpServerWorkerGroup,
|
||||
@Inject ProxyConfig proxyConfig) {
|
||||
Bootstrap bootstrap = new Bootstrap();
|
||||
bootstrap.group(udpServerBossGroup)
|
||||
// 主线程处理
|
||||
.channel(NioDatagramChannel.class)
|
||||
// 广播
|
||||
.option(ChannelOption.SO_BROADCAST, true)
|
||||
// 设置读缓冲区为2M
|
||||
.option(ChannelOption.SO_RCVBUF, 2048 * 1024)
|
||||
// 设置写缓冲区为1M
|
||||
.option(ChannelOption.SO_SNDBUF, 1024 * 1024)
|
||||
.handler(new ChannelInitializer<NioDatagramChannel>() {
|
||||
@Override
|
||||
protected void initChannel(NioDatagramChannel ch) {
|
||||
ChannelPipeline pipeline = ch.pipeline();
|
||||
if (null != proxyConfig.getServer().getUdp().getTransferLogEnable() && proxyConfig.getServer().getUdp().getTransferLogEnable()) {
|
||||
ch.pipeline().addFirst(new LoggingHandler(UdpVisitorChannelHandler.class));
|
||||
}
|
||||
pipeline.addLast(udpServerWorkerGroup, new UdpVisitorChannelHandler());
|
||||
}
|
||||
});
|
||||
return bootstrap;
|
||||
}
|
||||
|
||||
@Bean("tunnelBossGroup")
|
||||
public NioEventLoopGroup tunnelBossGroup(@Inject ProxyConfig proxyConfig) {
|
||||
return new NioEventLoopGroup(proxyConfig.getTunnel().getBossThreadCount());
|
||||
}
|
||||
|
||||
@Bean("tunnelWorkerGroup")
|
||||
public NioEventLoopGroup tunnelWorkerGroup(@Inject ProxyConfig proxyConfig) {
|
||||
return new NioEventLoopGroup(proxyConfig.getTunnel().getWorkThreadCount());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ public class ServiceException extends RuntimeException {
|
||||
private String msg;
|
||||
|
||||
public ServiceException(int code, String msg) {
|
||||
super(msg);
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ public class BaseAuthInterceptor implements RouterInterceptor {
|
||||
}
|
||||
|
||||
if (result instanceof Throwable) {
|
||||
log.error("全局异常", (Throwable) result);
|
||||
log.error("global error", (Throwable) result);
|
||||
|
||||
if (result instanceof ServiceException) {
|
||||
ServiceException exception = (ServiceException) result;
|
||||
|
||||
@@ -23,7 +23,7 @@ public class GlobalExceptionFilter implements Filter {
|
||||
try {
|
||||
chain.doFilter(ctx);
|
||||
} catch (Throwable e) {
|
||||
log.error("全局异常", e);
|
||||
log.error("global error", e);
|
||||
|
||||
if (e instanceof ServiceException) {
|
||||
ServiceException serviceException = (ServiceException) e;
|
||||
|
||||
@@ -31,7 +31,7 @@ public class VisitLogInterceptor implements RouterInterceptor {
|
||||
} finally {
|
||||
Date now = new Date();
|
||||
long elapsedTime = now.getTime() - startTime.getTime();
|
||||
log.info("\n-----------------------------------------------------------------接口请求日志:\n{} url:{} 执行耗时:{}\n请求体参数:{}\n响应结果:{}\n客户端IP:{}\n",
|
||||
log.debug("\n-----------------------------------------------------------------interface request log:\n{} url:{} elapsed time:{}\nrequest:{}\nresponse:{}\nclient ip:{}\n",
|
||||
ctx.method(), ctx.path(), getElapsedTimeStr(elapsedTime),
|
||||
JSONObject.toJSONString(ctx.paramMap()),
|
||||
JSONObject.toJSONString(JSONObject.toJSONString(ctx.result)),
|
||||
@@ -47,11 +47,11 @@ public class VisitLogInterceptor implements RouterInterceptor {
|
||||
*/
|
||||
private static String getElapsedTimeStr(long elapsedTime) {
|
||||
if (elapsedTime < 1000) {
|
||||
return String.format("%s毫秒", elapsedTime);
|
||||
return String.format("%sms", elapsedTime);
|
||||
} else if (elapsedTime < 60000) {
|
||||
return String.format("%.2f秒", (elapsedTime * 1.0) / 1000);
|
||||
return String.format("%.2fs", (elapsedTime * 1.0) / 1000);
|
||||
}
|
||||
return String.format("%.2f分钟", (elapsedTime * 1.0) / 1000 / 60);
|
||||
return String.format("%.2fm", (elapsedTime * 1.0) / 1000 / 60);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -38,7 +38,9 @@ import java.util.stream.Stream;
|
||||
@AllArgsConstructor
|
||||
public enum DbTypeEnum {
|
||||
SQLITE("sqlite"),
|
||||
MYSQL("mysql");
|
||||
MYSQL("mysql"),
|
||||
MARIADB("mariadb"),
|
||||
;
|
||||
|
||||
private String type;
|
||||
|
||||
|
||||
@@ -50,6 +50,7 @@ public enum ExceptionConstant {
|
||||
ORIGIN_PASSWORD_CHECK_FAIL(12002, "原密码验证失败"),
|
||||
LOGIN_PASSWORD_LENGTH_CHECK_FAIL(12003, "登录密码不能小于6位数"),
|
||||
LOGIN_PASSWORD_NO_CHANGE_MODIFY_FAIL(12004, "密码没有变化,修改失败"),
|
||||
LICENSE_CANNOT_BE_DELETED(12005, "license下存在[{}]个端口映射!"),
|
||||
// 端口池管理(13000)
|
||||
PORT_CANNOT_REPEAT(13000,"端口不能重复"),
|
||||
PORT_NOT_EXIST(13001, "该端口在端口池中不存在"),
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.dromara.neutrinoproxy.server.constant;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
@@ -15,14 +16,26 @@ import java.util.stream.Stream;
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum NetworkProtocolEnum {
|
||||
TCP("TCP"),
|
||||
UDP("UDP"),
|
||||
HTTP("HTTP"),
|
||||
TCP("TCP", "TCP"),
|
||||
UDP("UDP", "UDP"),
|
||||
HTTP("HTTP", "TCP"),
|
||||
;
|
||||
private String desc;
|
||||
private String baseProtocol;
|
||||
private static final Map<String, NetworkProtocolEnum> map = Stream.of(NetworkProtocolEnum.values()).collect(Collectors.toMap(NetworkProtocolEnum::getDesc, Function.identity()));
|
||||
|
||||
public static NetworkProtocolEnum of(String desc) {
|
||||
if (StringUtils.isBlank(desc)) {
|
||||
return null;
|
||||
}
|
||||
if (desc.startsWith("HTTP")) {
|
||||
return NetworkProtocolEnum.HTTP;
|
||||
}
|
||||
return map.get(desc);
|
||||
}
|
||||
|
||||
public static Boolean isHttp(String desc) {
|
||||
NetworkProtocolEnum networkProtocolEnum = of(desc);
|
||||
return NetworkProtocolEnum.HTTP == networkProtocolEnum;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ public class DomainNameController {
|
||||
@Get
|
||||
@Mapping("/bind-info")
|
||||
public String bindInfo () {
|
||||
return proxyConfig.getServer().getDomainName();
|
||||
return proxyConfig.getServer().getTcp().getDomainName();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ public class PortMappingController {
|
||||
ParamCheckUtil.checkNotNull(req.getServerPort(), "serverPort");
|
||||
ParamCheckUtil.checkNotNull(req.getClientPort(), "clientPort");
|
||||
ParamCheckUtil.checkNotEmpty(req.getProtocal(), "protocal");
|
||||
ParamCheckUtil.checkMaxLength(req.getDescription(), 50, "描述", "50");
|
||||
ParamCheckUtil.checkMaxLength(req.getDescription(), 50, "描述", "50");
|
||||
if (StringUtils.isBlank(req.getClientIp())) {
|
||||
// 没传客户端ip,默认为127.0.0.1
|
||||
req.setClientIp("127.0.0.1");
|
||||
@@ -51,6 +51,13 @@ public class PortMappingController {
|
||||
// 目前仅HTTP支持绑定域名
|
||||
req.setSubdomain(null);
|
||||
}
|
||||
req.setProtocal(networkProtocolEnum.getDesc());
|
||||
if (null == req.getProxyResponses()) {
|
||||
req.setProxyResponses(0);
|
||||
}
|
||||
if (null == req.getProxyTimeoutMs()) {
|
||||
req.setProxyTimeoutMs(0L);
|
||||
}
|
||||
|
||||
return portMappingService.create(req);
|
||||
}
|
||||
@@ -74,6 +81,13 @@ public class PortMappingController {
|
||||
// 目前仅HTTP支持绑定域名
|
||||
req.setSubdomain(null);
|
||||
}
|
||||
req.setProtocal(networkProtocolEnum.getDesc());
|
||||
if (null == req.getProxyResponses()) {
|
||||
req.setProxyResponses(0);
|
||||
}
|
||||
if (null == req.getProxyTimeoutMs()) {
|
||||
req.setProxyTimeoutMs(0L);
|
||||
}
|
||||
|
||||
return portMappingService.update(req);
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ public class PortPoolController {
|
||||
|
||||
@Get
|
||||
@Mapping("/get-available-port-list")
|
||||
public List<PortPoolListRes> getAvailablePortList(AvailablePortListReq req) {
|
||||
public PageInfo<PortPoolListRes> getAvailablePortList(AvailablePortListReq req) {
|
||||
ParamCheckUtil.checkNotNull(req, "req");
|
||||
ParamCheckUtil.checkNotNull(req.getLicenseId(), "licenseId");
|
||||
return portPoolService.getAvailablePortList(req);
|
||||
@@ -123,4 +123,22 @@ public class PortPoolController {
|
||||
ParamCheckUtil.checkNotEmpty(req.getPortIdList(), "portIdList");
|
||||
return portPoolService.updateGroup(req);
|
||||
}
|
||||
|
||||
@Post
|
||||
@Mapping("/delete-batch")
|
||||
@Authorization(onlyAdmin = true)
|
||||
public void deleteBatch(PortPoolDeleteBatchReq req) {
|
||||
ParamCheckUtil.checkNotNull(req, "req");
|
||||
ParamCheckUtil.checkNotNull(req.getIds(), "ids");
|
||||
|
||||
portPoolService.deleteBatch(req.getIds());
|
||||
}
|
||||
|
||||
@Get
|
||||
@Mapping("/port-available")
|
||||
public boolean portAvailable(Integer port, Integer portMappingId) {
|
||||
ParamCheckUtil.checkNotNull(port, "port");
|
||||
|
||||
return portPoolService.portAvailable(port, portMappingId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,8 +30,16 @@ import lombok.Data;
|
||||
*/
|
||||
@Data
|
||||
public class LicenseListReq {
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
private Integer userId;
|
||||
/**
|
||||
* 是否在线
|
||||
*/
|
||||
private Integer isOnline;
|
||||
/**
|
||||
* 启动状态 1启用 2禁用
|
||||
*/
|
||||
private Integer enable;
|
||||
}
|
||||
|
||||
@@ -54,6 +54,14 @@ public class PortMappingCreateReq {
|
||||
* 客户端端口
|
||||
*/
|
||||
private Integer clientPort;
|
||||
/**
|
||||
* 代理响应数量(响应数据包数量,如果没有拆包则等于数据条数)
|
||||
*/
|
||||
private Integer proxyResponses;
|
||||
/**
|
||||
* 代理超时时间
|
||||
*/
|
||||
private Long proxyTimeoutMs;
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
|
||||
@@ -58,6 +58,14 @@ public class PortMappingUpdateReq {
|
||||
* 客户端端口
|
||||
*/
|
||||
private Integer clientPort;
|
||||
/**
|
||||
* 代理响应数量(响应数据包数量,如果没有拆包则等于数据条数)
|
||||
*/
|
||||
private Integer proxyResponses;
|
||||
/**
|
||||
* 代理超时时间
|
||||
*/
|
||||
private Long proxyTimeoutMs;
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
|
||||
@@ -12,4 +12,18 @@ public class AvailablePortListReq {
|
||||
* licenseId
|
||||
*/
|
||||
private Integer licenseId;
|
||||
|
||||
/**
|
||||
* 当前页
|
||||
*/
|
||||
private int page = 1;
|
||||
/**
|
||||
* 分页大小
|
||||
*/
|
||||
private int size = 10;
|
||||
|
||||
/**
|
||||
* 搜索关键字
|
||||
*/
|
||||
private String keyword;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package org.dromara.neutrinoproxy.server.controller.req.system;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author: Metal
|
||||
* @date: 2023/7/3
|
||||
*/
|
||||
@Data
|
||||
public class PortPoolDeleteBatchReq {
|
||||
private List<Integer> ids;
|
||||
}
|
||||
@@ -49,6 +49,14 @@ public class PortMappingDetailRes {
|
||||
* {@link OnlineStatusEnum}
|
||||
*/
|
||||
private Integer isOnline;
|
||||
/**
|
||||
* 代理响应数量(响应数据包数量,如果没有拆包则等于数据条数)
|
||||
*/
|
||||
private Integer proxyResponses;
|
||||
/**
|
||||
* 代理超时时间
|
||||
*/
|
||||
private Long proxyTimeoutMs;
|
||||
/**
|
||||
* 启用状态
|
||||
* {@link EnableStatusEnum}
|
||||
|
||||
@@ -89,6 +89,14 @@ public class PortMappingListRes {
|
||||
* {@link EnableStatusEnum}
|
||||
*/
|
||||
private Integer enable;
|
||||
/**
|
||||
* 代理响应数量(响应数据包数量,如果没有拆包则等于数据条数)
|
||||
*/
|
||||
private Integer proxyResponses;
|
||||
/**
|
||||
* 代理超时时间
|
||||
*/
|
||||
private Long proxyTimeoutMs;
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
|
||||
@@ -74,6 +74,14 @@ public interface PortMappingMapper extends BaseMapper<PortMappingDO> {
|
||||
);
|
||||
}
|
||||
|
||||
default PortMappingDO findByLicenseIdAndServerPort(Integer licenseId, Integer serverPort) {
|
||||
return this.selectOne(new LambdaQueryWrapper<PortMappingDO>()
|
||||
.eq(PortMappingDO::getLicenseId, licenseId)
|
||||
.eq(PortMappingDO::getServerPort, serverPort)
|
||||
.last("limit 1")
|
||||
);
|
||||
}
|
||||
|
||||
default void updateOnlineStatus(Integer licenseId,Integer serverPort, Integer isOnline, Date updateTime) {
|
||||
this.update(null, new LambdaUpdateWrapper<PortMappingDO>()
|
||||
.eq(PortMappingDO::getLicenseId, licenseId)
|
||||
|
||||
@@ -67,5 +67,5 @@ public interface PortPoolMapper extends BaseMapper<PortPoolDO> {
|
||||
|
||||
List<PortPoolListRes> selectResList(@Param("req") PortPoolListReq req);
|
||||
|
||||
List<PortPoolListRes> getAvailablePortList(@Param("licenseId") Integer licenseId,@Param("userId") Integer userId);
|
||||
List<PortPoolListRes> getAvailablePortList(@Param("licenseId") Integer licenseId,@Param("userId") Integer userId, @Param("keyword") String keyword);
|
||||
}
|
||||
|
||||
@@ -78,6 +78,14 @@ public class PortMappingDO {
|
||||
* {@link OnlineStatusEnum}
|
||||
*/
|
||||
private Integer isOnline;
|
||||
/**
|
||||
* 代理响应数量(响应数据包数量,如果没有拆包则等于数据条数)
|
||||
*/
|
||||
private Integer proxyResponses;
|
||||
/**
|
||||
* 代理超时时间
|
||||
*/
|
||||
private Long proxyTimeoutMs;
|
||||
/**
|
||||
* 启用状态
|
||||
* {@link EnableStatusEnum}
|
||||
|
||||
@@ -70,37 +70,37 @@ public class DataCleanJob implements IJobHandler {
|
||||
|
||||
{
|
||||
Date date = DateUtil.addDate(new Date(), Calendar.DATE, -1 * jobParams.getJobLogKeepDays());
|
||||
log.info("清理调度管理日志 date:{}", sdf.format(date));
|
||||
log.info("clean job log date:{}", sdf.format(date));
|
||||
jobLogMapper.clean(date);
|
||||
}
|
||||
|
||||
{
|
||||
Date date = DateUtil.addDate(new Date(), Calendar.DATE, -1 * jobParams.getUserLoginRecordKeepDays());
|
||||
log.info("清理用户登录日志 date:{}", sdf.format(date));
|
||||
log.info("clean user login record date:{}", sdf.format(date));
|
||||
userLoginRecordMapper.clean(date);
|
||||
}
|
||||
|
||||
{
|
||||
Date date = DateUtil.addDate(new Date(), Calendar.DATE, -1 * jobParams.getClientConnectRecordKeepDays());
|
||||
log.info("清理客户端连接日志 date:{}", sdf.format(date));
|
||||
log.info("clean client connect record date:{}", sdf.format(date));
|
||||
clientConnectRecordMapper.clean(date);
|
||||
}
|
||||
|
||||
{
|
||||
Date date = DateUtil.addDate(new Date(), Calendar.DATE, -1 * jobParams.getFlowMinuteReportKeepDays());
|
||||
log.info("清理流通统计分钟报表日志 date:{}", sdf.format(date));
|
||||
log.info("clean flow report minute record date:{}", sdf.format(date));
|
||||
flowReportMinuteMapper.clean(date);
|
||||
}
|
||||
|
||||
{
|
||||
Date date = DateUtil.addDate(new Date(), Calendar.DATE, -1 * jobParams.getFlowHourReportKeepDays());
|
||||
log.info("清理流通统计小时报表日志 date:{}", sdf.format(date));
|
||||
log.info("clean flow report hour record date:{}", sdf.format(date));
|
||||
flowReportHourMapper.clean(date);
|
||||
}
|
||||
|
||||
{
|
||||
Date date = DateUtil.addDate(new Date(), Calendar.DATE, -1 * jobParams.getFlowDayReportKeepDays());
|
||||
log.info("清理流通统计日报表日志 date:{}", sdf.format(date));
|
||||
log.info("clean flow report day record date:{}", sdf.format(date));
|
||||
flowReportDayMapper.clean(date);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,6 @@ public class DemoJob implements IJobHandler {
|
||||
|
||||
@Override
|
||||
public void execute(String param) throws Exception {
|
||||
System.out.println("DemoJob execute param:" + param);
|
||||
log.debug("DemoJob execute param: {}", param);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,204 +0,0 @@
|
||||
package org.dromara.neutrinoproxy.server.proxy.core;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import io.netty.bootstrap.ServerBootstrap;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.*;
|
||||
import io.netty.channel.nio.NioEventLoopGroup;
|
||||
import io.netty.channel.socket.SocketChannel;
|
||||
import io.netty.channel.socket.nio.NioServerSocketChannel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.dromara.neutrinoproxy.core.Constants;
|
||||
import org.dromara.neutrinoproxy.core.ProxyMessage;
|
||||
import org.dromara.neutrinoproxy.server.base.proxy.ProxyConfig;
|
||||
import org.dromara.neutrinoproxy.server.proxy.domain.ProxyAttachment;
|
||||
import org.dromara.neutrinoproxy.server.proxy.domain.VisitorChannelAttachInfo;
|
||||
import org.dromara.neutrinoproxy.server.service.FlowReportService;
|
||||
import org.dromara.neutrinoproxy.server.util.ProxyUtil;
|
||||
import org.noear.solon.Solon;
|
||||
import org.noear.solon.annotation.Component;
|
||||
import org.noear.solon.annotation.Inject;
|
||||
import org.noear.solon.core.event.AppLoadEndEvent;
|
||||
import org.noear.solon.core.event.EventListener;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
/**
|
||||
* @author: aoshiguchen
|
||||
* @date: 2023/4/2
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class HttpProxy implements EventListener<AppLoadEndEvent> {
|
||||
@Inject("serverBossGroup")
|
||||
private NioEventLoopGroup serverBossGroup;
|
||||
@Inject("serverWorkerGroup")
|
||||
private NioEventLoopGroup serverWorkerGroup;
|
||||
@Inject
|
||||
private ProxyConfig proxyConfig;
|
||||
@Override
|
||||
public void onEvent(AppLoadEndEvent appLoadEndEvent) throws Throwable {
|
||||
if (StrUtil.isBlank(proxyConfig.getServer().getDomainName()) || null == proxyConfig.getServer().getHttpProxyPort()) {
|
||||
log.info("no config domain name,nonsupport http proxy.");
|
||||
return;
|
||||
}
|
||||
this.start();
|
||||
}
|
||||
|
||||
private void start() {
|
||||
try {
|
||||
ServerBootstrap bootstrap = new ServerBootstrap();
|
||||
bootstrap.group(serverBossGroup, serverWorkerGroup)
|
||||
.channel(NioServerSocketChannel.class).childHandler(new ChannelInitializer<SocketChannel>() {
|
||||
@Override
|
||||
public void initChannel(SocketChannel ch) throws Exception {
|
||||
ch.pipeline().addFirst(new BytesMetricsHandler());
|
||||
ch.pipeline().addLast(new VisitorChannelHandler());
|
||||
}
|
||||
});
|
||||
bootstrap.bind("0.0.0.0", proxyConfig.getServer().getHttpProxyPort()).sync();
|
||||
log.info("Http代理服务启动成功!");
|
||||
} catch (Exception e) {
|
||||
log.error("http proxy start err!", e);
|
||||
}
|
||||
}
|
||||
|
||||
private class VisitorChannelHandler extends SimpleChannelInboundHandler<ByteBuf> {
|
||||
|
||||
@Override
|
||||
protected void channelRead0(ChannelHandlerContext ctx, ByteBuf byteBuf) throws Exception {
|
||||
if (StrUtil.isBlank(proxyConfig.getServer().getDomainName())) {
|
||||
ctx.channel().close();
|
||||
return;
|
||||
}
|
||||
|
||||
byte[] bytes = new byte[byteBuf.readableBytes()];
|
||||
byteBuf.readBytes(bytes);
|
||||
byteBuf.resetReaderIndex();
|
||||
ProxyAttachment proxyAttachment = new ProxyAttachment(ctx.channel(), bytes, (channel, buf) -> {
|
||||
Channel proxyChannel = channel.attr(Constants.NEXT_CHANNEL).get();
|
||||
if (null == proxyChannel) {
|
||||
// 该端口还没有代理客户端
|
||||
ctx.channel().close();
|
||||
return;
|
||||
}
|
||||
|
||||
proxyChannel.writeAndFlush(ProxyMessage.buildTransferMessage(ProxyUtil.getVisitorIdByChannel(channel), bytes));
|
||||
|
||||
// 增加流量计数
|
||||
VisitorChannelAttachInfo visitorChannelAttachInfo = ProxyUtil.getAttachInfo(channel);
|
||||
Solon.context().getBean(FlowReportService.class).addWriteByte(visitorChannelAttachInfo.getLicenseId(), bytes.length);
|
||||
});
|
||||
|
||||
String visitorId = ProxyUtil.getVisitorIdByChannel(ctx.channel());
|
||||
if (StringUtils.isNotBlank(visitorId)) {
|
||||
proxyAttachment.execute();
|
||||
return;
|
||||
}
|
||||
|
||||
// 用户连接到代理服务器时,设置用户连接不可读,等待代理后端服务器连接成功后再改变为可读状态
|
||||
ctx.channel().config().setOption(ChannelOption.AUTO_READ, false);
|
||||
|
||||
String host = getHost(bytes);
|
||||
if (StringUtils.isBlank(host)) {
|
||||
ctx.channel().close();
|
||||
return;
|
||||
}
|
||||
log.debug("HttpProxy host: {}", host);
|
||||
if (!host.endsWith(proxyConfig.getServer().getDomainName())) {
|
||||
ctx.channel().close();
|
||||
return;
|
||||
}
|
||||
int index = host.lastIndexOf("." + proxyConfig.getServer().getDomainName());
|
||||
String subdomain = host.substring(0, index);
|
||||
|
||||
// 根据域名拿到绑定的映射对应的cmdChannel
|
||||
Integer serverPort = ProxyUtil.getServerPortBySubdomain(subdomain);
|
||||
if (null == serverPort) {
|
||||
ctx.channel().close();
|
||||
return;
|
||||
}
|
||||
Channel cmdChannel = ProxyUtil.getCmdChannelByServerPort(serverPort);
|
||||
if (null == cmdChannel) {
|
||||
ctx.channel().close();
|
||||
return;
|
||||
}
|
||||
String lanInfo = ProxyUtil.getClientLanInfoByServerPort(serverPort);
|
||||
if (StringUtils.isBlank(lanInfo)) {
|
||||
ctx.channel().close();
|
||||
return;
|
||||
}
|
||||
|
||||
visitorId = ProxyUtil.newVisitorId();
|
||||
ProxyUtil.addVisitorChannelToCmdChannel(cmdChannel, visitorId, ctx.channel(), serverPort);
|
||||
ProxyUtil.addProxyConnectAttachment(visitorId, proxyAttachment);
|
||||
cmdChannel.writeAndFlush(ProxyMessage.buildConnectMessage(visitorId).setData(lanInfo.getBytes()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
||||
|
||||
// 通知代理客户端
|
||||
Channel visitorChannel = ctx.channel();
|
||||
InetSocketAddress sa = (InetSocketAddress) visitorChannel.localAddress();
|
||||
Channel cmdChannel = ProxyUtil.getCmdChannelByServerPort(sa.getPort());
|
||||
|
||||
if (cmdChannel == null) {
|
||||
// 该端口还没有代理客户端
|
||||
ctx.channel().close();
|
||||
} else {
|
||||
|
||||
// 用户连接断开,从控制连接中移除
|
||||
String visitorId = ProxyUtil.getVisitorIdByChannel(visitorChannel);
|
||||
ProxyUtil.removeVisitorChannelFromCmdChannel(cmdChannel, visitorId);
|
||||
|
||||
// 删除代理附加对象
|
||||
ProxyUtil.remoteProxyConnectAttachment(visitorId);
|
||||
|
||||
Channel proxyChannel = visitorChannel.attr(Constants.NEXT_CHANNEL).get();
|
||||
if (proxyChannel != null && proxyChannel.isActive()) {
|
||||
proxyChannel.attr(Constants.NEXT_CHANNEL).remove();
|
||||
proxyChannel.attr(Constants.LICENSE_ID).remove();
|
||||
proxyChannel.attr(Constants.VISITOR_ID).remove();
|
||||
|
||||
proxyChannel.config().setOption(ChannelOption.AUTO_READ, true);
|
||||
// 通知客户端,用户连接已经断开
|
||||
proxyChannel.writeAndFlush(ProxyMessage.buildDisconnectMessage(visitorId));
|
||||
}
|
||||
}
|
||||
|
||||
super.channelInactive(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
||||
super.channelActive(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
|
||||
// 当出现异常就关闭连接
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
private String getHost(byte[] buf) {
|
||||
String req = new String(buf);
|
||||
String[] lines = req.split("\r\n");
|
||||
String firstLine = lines[0];
|
||||
if (!(firstLine.endsWith("HTTP/1.1") || firstLine.endsWith("HTTP/1.0"))) {
|
||||
return null;
|
||||
}
|
||||
for (int i = 1; i < lines.length; i++) {
|
||||
String line = lines[i];
|
||||
if (!line.startsWith("Host: ")) {
|
||||
continue;
|
||||
}
|
||||
// 域名
|
||||
String domain = line.substring(6);
|
||||
return domain;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,7 @@ package org.dromara.neutrinoproxy.server.proxy.core;
|
||||
import org.dromara.neutrinoproxy.core.Constants;
|
||||
import org.dromara.neutrinoproxy.core.ProxyMessage;
|
||||
import org.dromara.neutrinoproxy.core.dispatcher.Dispatcher;
|
||||
import org.dromara.neutrinoproxy.server.base.proxy.ProxyConfig;
|
||||
import org.dromara.neutrinoproxy.server.constant.ClientConnectTypeEnum;
|
||||
import org.dromara.neutrinoproxy.server.constant.SuccessCodeEnum;
|
||||
import org.dromara.neutrinoproxy.server.dal.entity.ClientConnectRecordDO;
|
||||
@@ -47,47 +48,68 @@ import java.util.Date;
|
||||
* @date: 2022/6/16
|
||||
*/
|
||||
@Slf4j
|
||||
public class ServerChannelHandler extends SimpleChannelInboundHandler<ProxyMessage> {
|
||||
public class ProxyTunnelChannelHandler extends SimpleChannelInboundHandler<ProxyMessage> {
|
||||
private static volatile Dispatcher<ChannelHandlerContext, ProxyMessage> dispatcher;
|
||||
private static volatile Boolean transferLogEnable = Boolean.FALSE;
|
||||
|
||||
public ServerChannelHandler() {
|
||||
public ProxyTunnelChannelHandler() {
|
||||
dispatcher = Solon.context().getBean(Dispatcher.class);
|
||||
ProxyConfig proxyConfig = Solon.context().getBean(ProxyConfig.class);
|
||||
if (null != proxyConfig.getTunnel() && null != proxyConfig.getTunnel().getHeartbeatLogEnable()) {
|
||||
transferLogEnable = proxyConfig.getTunnel().getHeartbeatLogEnable();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void channelRead0(ChannelHandlerContext ctx, ProxyMessage proxyMessage) throws Exception {
|
||||
if (ProxyMessage.TYPE_HEARTBEAT != proxyMessage.getType() || transferLogEnable) {
|
||||
log.debug("Server CmdChannel recieved proxy message, type is {}", proxyMessage.getType());
|
||||
}
|
||||
dispatcher.dispatch(ctx, proxyMessage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception {
|
||||
Channel userChannel = ctx.channel().attr(Constants.NEXT_CHANNEL).get();
|
||||
if (userChannel != null) {
|
||||
userChannel.config().setOption(ChannelOption.AUTO_READ, ctx.channel().isWritable());
|
||||
}
|
||||
// Channel userChannel = ctx.channel().attr(Constants.NEXT_CHANNEL).get();
|
||||
// if (userChannel != null) {
|
||||
// userChannel.config().setOption(ChannelOption.AUTO_READ, ctx.channel().isWritable());
|
||||
// }
|
||||
|
||||
super.channelWritabilityChanged(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
||||
Channel userChannel = ctx.channel().attr(Constants.NEXT_CHANNEL).get();
|
||||
if (userChannel != null && userChannel.isActive()) {
|
||||
Channel visitorChannel = ctx.channel().attr(Constants.NEXT_CHANNEL).get();
|
||||
if (null != visitorChannel) {
|
||||
Integer licenseId = ctx.channel().attr(Constants.LICENSE_ID).get();
|
||||
String visitorId = ctx.channel().attr(Constants.VISITOR_ID).get();
|
||||
Channel cmdChannel = ProxyUtil.getCmdChannelByLicenseId(licenseId);
|
||||
|
||||
if (cmdChannel != null) {
|
||||
if (null != cmdChannel) {
|
||||
ProxyUtil.removeVisitorChannelFromCmdChannel(cmdChannel, visitorId);
|
||||
}
|
||||
ProxyUtil.remoteProxyConnectAttachment(visitorId);
|
||||
|
||||
// 数据发送完成后再关闭连接,解决http1.0数据传输问题
|
||||
userChannel.writeAndFlush(Unpooled.EMPTY_BUFFER).addListener(ChannelFutureListener.CLOSE);
|
||||
userChannel.close();
|
||||
// 此处如果时UDP的 visitorChannel,则不能close,先临时判断一下
|
||||
Boolean isUdp = visitorChannel.attr(Constants.IS_UDP_KEY).get();
|
||||
if (visitorChannel.isActive() && null == isUdp) {
|
||||
// 数据发送完成后再关闭连接,解决http1.0数据传输问题
|
||||
visitorChannel.writeAndFlush(Unpooled.EMPTY_BUFFER).addListener(ChannelFutureListener.CLOSE);
|
||||
visitorChannel.close();
|
||||
}
|
||||
} else {
|
||||
CmdChannelAttachInfo cmdChannelAttachInfo = ProxyUtil.getAttachInfo(ctx.channel());
|
||||
if (null != cmdChannelAttachInfo) {
|
||||
Solon.context().getBean(ProxyMutualService.class).offline(cmdChannelAttachInfo);
|
||||
Channel curCmdChannel = ProxyUtil.getCmdChannelByLicenseId(cmdChannelAttachInfo.getLicenseId());
|
||||
// 客户端切换网络后,连接断开,但服务端还未触发断开事件。此时客户端重连上了,然后服务端触发了断开,此时不应该更新在线状态
|
||||
if (curCmdChannel == ctx.channel()) {
|
||||
Solon.context().getBean(ProxyMutualService.class).offline(cmdChannelAttachInfo);
|
||||
ProxyUtil.removeCmdChannel(ctx.channel());
|
||||
// 防止下次换一个客户端,无法连接的情况
|
||||
ProxyUtil.removeClientIdByLicenseId(cmdChannelAttachInfo.getLicenseId());
|
||||
}
|
||||
// 即便是因为上述原因断开,断开的日志依然要记录,方便排查问题
|
||||
Solon.context().getBean(ClientConnectRecordService.class).add(new ClientConnectRecordDO()
|
||||
.setIp(((InetSocketAddress)ctx.channel().remoteAddress()).getAddress().getHostAddress())
|
||||
.setLicenseId(cmdChannelAttachInfo.getLicenseId())
|
||||
@@ -97,7 +119,6 @@ public class ServerChannelHandler extends SimpleChannelInboundHandler<ProxyMessa
|
||||
.setCreateTime(new Date())
|
||||
);
|
||||
}
|
||||
ProxyUtil.removeCmdChannel(ctx.channel());
|
||||
}
|
||||
|
||||
super.channelInactive(ctx);
|
||||
@@ -105,10 +126,11 @@ public class ServerChannelHandler extends SimpleChannelInboundHandler<ProxyMessa
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
||||
super.exceptionCaught(ctx, cause);
|
||||
if (ctx.channel().isActive()) {
|
||||
ctx.channel().close();
|
||||
}
|
||||
// super.exceptionCaught(ctx, cause);
|
||||
// if (ctx.channel().isActive()) {
|
||||
// ctx.channel().close();
|
||||
// }
|
||||
log.error("[Tunnel Channel] error", cause);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -117,12 +139,14 @@ public class ServerChannelHandler extends SimpleChannelInboundHandler<ProxyMessa
|
||||
IdleStateEvent event = (IdleStateEvent)evt;
|
||||
switch (event.state()) {
|
||||
case READER_IDLE:
|
||||
// 读超时,断开连接
|
||||
log.info("读超时");
|
||||
ctx.channel().close();
|
||||
if (ctx.channel().isWritable()) {
|
||||
// 读超时,断开连接
|
||||
log.warn("[Tunnel Channel]Read timeout");
|
||||
ctx.channel().close();
|
||||
}
|
||||
break;
|
||||
case WRITER_IDLE:
|
||||
log.info("写超时");
|
||||
ctx.channel().writeAndFlush(ProxyMessage.buildHeartbeatMessage());
|
||||
break;
|
||||
case ALL_IDLE:
|
||||
break;
|
||||
@@ -27,29 +27,19 @@ import java.io.InputStream;
|
||||
import java.security.KeyStore;
|
||||
|
||||
/**
|
||||
*
|
||||
* 代理隧道服务
|
||||
* @author: aoshiguchen
|
||||
* @date: 2022/6/16
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class ProxyServerRunner implements EventListener<AppLoadEndEvent> {
|
||||
public class ProxyTunnelServer implements EventListener<AppLoadEndEvent> {
|
||||
@Inject
|
||||
private ProxyConfig proxyConfig;
|
||||
@Inject("serverBossGroup")
|
||||
@Inject("tunnelBossGroup")
|
||||
private NioEventLoopGroup serverBossGroup;
|
||||
@Inject("serverWorkerGroup")
|
||||
@Inject("tunnelWorkerGroup")
|
||||
private NioEventLoopGroup serverWorkerGroup;
|
||||
@Inject("${neutrino.proxy.server.port}")
|
||||
private Integer port;
|
||||
@Inject("${neutrino.proxy.server.ssl-port}")
|
||||
private Integer sslPort;
|
||||
@Inject("${neutrino.proxy.server.jks-path}")
|
||||
private String jksPath;
|
||||
@Inject("${neutrino.proxy.server.key-store-password}")
|
||||
private String keyStorePassword;
|
||||
@Inject("${neutrino.proxy.server.key-manager-password}")
|
||||
private String keyManagerPassword;
|
||||
@Override
|
||||
public void onEvent(AppLoadEndEvent appLoadEndEvent) throws Throwable {
|
||||
startProxyServer();
|
||||
@@ -68,15 +58,15 @@ public class ProxyServerRunner implements EventListener<AppLoadEndEvent> {
|
||||
}
|
||||
});
|
||||
try {
|
||||
bootstrap.bind(port).sync();
|
||||
log.info("代理服务启动,端口:{}", port);
|
||||
bootstrap.bind(proxyConfig.getTunnel().getPort()).sync();
|
||||
log.info("proxy server started,port:{}", proxyConfig.getTunnel().getPort());
|
||||
} catch (Exception e) {
|
||||
log.error("代理服务异常", e);
|
||||
log.error("proxy server error", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void startProxyServerForSSL() {
|
||||
if (null == sslPort) {
|
||||
if (null == proxyConfig.getTunnel().getSslPort()) {
|
||||
return;
|
||||
}
|
||||
ServerBootstrap bootstrap = new ServerBootstrap();
|
||||
@@ -89,22 +79,22 @@ public class ProxyServerRunner implements EventListener<AppLoadEndEvent> {
|
||||
}
|
||||
});
|
||||
try {
|
||||
bootstrap.bind(sslPort).sync();
|
||||
log.info("代理服务启动,SSL端口: {}", sslPort);
|
||||
bootstrap.bind(proxyConfig.getTunnel().getSslPort()).sync();
|
||||
log.info("proxy server started,SSL port: {}", proxyConfig.getTunnel().getSslPort());
|
||||
} catch (Exception e) {
|
||||
log.error("代理服务异常", e);
|
||||
log.error("proxy server error", e);
|
||||
}
|
||||
}
|
||||
|
||||
private ChannelHandler createSslHandler() {
|
||||
try {
|
||||
InputStream jksInputStream = FileUtil.getInputStream(jksPath);
|
||||
InputStream jksInputStream = FileUtil.getInputStream(proxyConfig.getTunnel().getJksPath());
|
||||
SSLContext serverContext = SSLContext.getInstance("TLS");
|
||||
final KeyStore ks = KeyStore.getInstance("JKS");
|
||||
|
||||
ks.load(jksInputStream, keyStorePassword.toCharArray());
|
||||
ks.load(jksInputStream, proxyConfig.getTunnel().getKeyStorePassword().toCharArray());
|
||||
final KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||
kmf.init(ks, keyManagerPassword.toCharArray());
|
||||
kmf.init(ks, proxyConfig.getTunnel().getKeyManagerPassword().toCharArray());
|
||||
TrustManager[] trustManagers = null;
|
||||
|
||||
serverContext.init(kmf.getKeyManagers(), trustManagers, null);
|
||||
@@ -115,19 +105,21 @@ public class ProxyServerRunner implements EventListener<AppLoadEndEvent> {
|
||||
|
||||
return new SslHandler(sslEngine);
|
||||
} catch (Exception e) {
|
||||
log.error("创建SSL处理器失败", e);
|
||||
log.error("create SSL handler error", e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void proxyServerCommonInitHandler(SocketChannel ch) {
|
||||
// ch.pipeline().addFirst(new LoggingHandler(ProxyServerRunner.class));
|
||||
if (null != proxyConfig.getTunnel().getTransferLogEnable() && proxyConfig.getTunnel().getTransferLogEnable()) {
|
||||
ch.pipeline().addFirst(new LoggingHandler(ProxyTunnelServer.class));
|
||||
}
|
||||
ch.pipeline().addLast(new ProxyMessageDecoder(proxyConfig.getProtocol().getMaxFrameLength(),
|
||||
proxyConfig.getProtocol().getLengthFieldOffset(), proxyConfig.getProtocol().getLengthFieldLength(),
|
||||
proxyConfig.getProtocol().getLengthAdjustment(), proxyConfig.getProtocol().getInitialBytesToStrip()));
|
||||
ch.pipeline().addLast(new ProxyMessageEncoder());
|
||||
ch.pipeline().addLast(new IdleStateHandler(proxyConfig.getProtocol().getReadIdleTime(), proxyConfig.getProtocol().getWriteIdleTime(), proxyConfig.getProtocol().getAllIdleTimeSeconds()));
|
||||
ch.pipeline().addLast(new ServerChannelHandler());
|
||||
ch.pipeline().addLast(new ProxyTunnelChannelHandler());
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import cn.hutool.core.util.StrUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.neutrinoproxy.core.Constants;
|
||||
import org.dromara.neutrinoproxy.core.ProxyMessage;
|
||||
import org.dromara.neutrinoproxy.server.proxy.domain.ProxyAttachment;
|
||||
import org.dromara.neutrinoproxy.server.constant.NetworkProtocolEnum;
|
||||
import org.dromara.neutrinoproxy.server.proxy.domain.VisitorChannelAttachInfo;
|
||||
import org.dromara.neutrinoproxy.server.service.FlowReportService;
|
||||
import org.dromara.neutrinoproxy.server.util.ProxyUtil;
|
||||
@@ -23,7 +23,7 @@ import java.net.InetSocketAddress;
|
||||
* @date: 2022/6/16
|
||||
*/
|
||||
@Slf4j
|
||||
public class VisitorChannelHandler extends SimpleChannelInboundHandler<ByteBuf> {
|
||||
public class TcpVisitorChannelHandler extends SimpleChannelInboundHandler<ByteBuf> {
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
|
||||
@@ -43,6 +43,10 @@ public class VisitorChannelHandler extends SimpleChannelInboundHandler<ByteBuf>
|
||||
ctx.channel().close();
|
||||
return;
|
||||
}
|
||||
|
||||
// 代理通道可写,则设置访问通道可读。代理通道不可写,则设置访问通道不可读
|
||||
visitorChannel.config().setAutoRead(proxyChannel.isWritable());
|
||||
|
||||
// 转发代理数据
|
||||
byte[] bytes = new byte[buf.readableBytes()];
|
||||
buf.readBytes(bytes);
|
||||
@@ -77,7 +81,7 @@ public class VisitorChannelHandler extends SimpleChannelInboundHandler<ByteBuf>
|
||||
visitorChannel.config().setOption(ChannelOption.AUTO_READ, false);
|
||||
|
||||
String visitorId = ProxyUtil.newVisitorId();
|
||||
ProxyUtil.addVisitorChannelToCmdChannel(cmdChannel, visitorId, visitorChannel, sa.getPort());
|
||||
ProxyUtil.addVisitorChannelToCmdChannel(NetworkProtocolEnum.TCP, cmdChannel, visitorId, visitorChannel, sa.getPort());
|
||||
cmdChannel.writeAndFlush(ProxyMessage.buildConnectMessage(visitorId).setData(lanInfo.getBytes()));
|
||||
|
||||
super.channelActive(ctx);
|
||||
@@ -91,8 +95,7 @@ public class VisitorChannelHandler extends SimpleChannelInboundHandler<ByteBuf>
|
||||
InetSocketAddress sa = (InetSocketAddress) visitorChannel.localAddress();
|
||||
Channel cmdChannel = ProxyUtil.getCmdChannelByServerPort(sa.getPort());
|
||||
|
||||
if (cmdChannel == null) {
|
||||
|
||||
if (null == cmdChannel) {
|
||||
// 该端口还没有代理客户端
|
||||
ctx.channel().close();
|
||||
} else {
|
||||
@@ -127,12 +130,13 @@ public class VisitorChannelHandler extends SimpleChannelInboundHandler<ByteBuf>
|
||||
InetSocketAddress sa = (InetSocketAddress) visitorChannel.localAddress();
|
||||
Channel cmdChannel = ProxyUtil.getCmdChannelByServerPort(sa.getPort());
|
||||
|
||||
if (cmdChannel == null) {
|
||||
if (null == cmdChannel) {
|
||||
// 该端口还没有代理客户端
|
||||
ctx.channel().close();
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
Channel proxyChannel = visitorChannel.attr(Constants.NEXT_CHANNEL).get();
|
||||
if (proxyChannel != null) {
|
||||
if (null != proxyChannel) {
|
||||
proxyChannel.config().setOption(ChannelOption.AUTO_READ, visitorChannel.isWritable());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
package org.dromara.neutrinoproxy.server.proxy.core;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelOption;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
import io.netty.channel.socket.DatagramPacket;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.dromara.neutrinoproxy.core.Constants;
|
||||
import org.dromara.neutrinoproxy.core.ProxyMessage;
|
||||
import org.dromara.neutrinoproxy.server.constant.NetworkProtocolEnum;
|
||||
import org.dromara.neutrinoproxy.server.proxy.domain.ProxyAttachment;
|
||||
import org.dromara.neutrinoproxy.server.proxy.domain.VisitorChannelAttachInfo;
|
||||
import org.dromara.neutrinoproxy.server.service.FlowReportService;
|
||||
import org.dromara.neutrinoproxy.server.util.ProxyUtil;
|
||||
import org.noear.solon.Solon;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
* @author: aoshiguchen
|
||||
* @date: 2023/9/16
|
||||
*/
|
||||
@Slf4j
|
||||
public class UdpVisitorChannelHandler extends SimpleChannelInboundHandler<DatagramPacket> {
|
||||
|
||||
@Override
|
||||
protected void channelRead0(ChannelHandlerContext ctx, DatagramPacket datagramPacket) throws Exception {
|
||||
log.debug("chid>>>{}", ctx.channel().id().asLongText());
|
||||
byte[] bytes = new byte[datagramPacket.content().readableBytes()];
|
||||
datagramPacket.content().readBytes(bytes);
|
||||
datagramPacket.content().resetReaderIndex();
|
||||
ProxyAttachment proxyAttachment = new ProxyAttachment(ctx.channel(), bytes, (channel, buf) -> {
|
||||
Channel proxyChannel = channel.attr(Constants.NEXT_CHANNEL).get();
|
||||
|
||||
if (null == proxyChannel) {
|
||||
// // 该端口还没有代理客户端
|
||||
// ctx.channel().close();
|
||||
return;
|
||||
}
|
||||
|
||||
proxyChannel.attr(Constants.SENDER).set(datagramPacket.sender());
|
||||
String targetIp = proxyChannel.attr(Constants.TARGET_IP).get();
|
||||
int targetPort = proxyChannel.attr(Constants.TARGET_PORT).get();
|
||||
Integer proxyResponses = proxyChannel.attr(Constants.PROXY_RESPONSES).get();
|
||||
Long proxyTimeoutMs = proxyChannel.attr(Constants.PROXY_TIMEOUT_MS).get();
|
||||
|
||||
// 转发代理数据
|
||||
String visitorId = ProxyUtil.getVisitorIdByChannel(channel);
|
||||
proxyChannel.writeAndFlush(ProxyMessage.buildUdpTransferMessage(new ProxyMessage.UdpBaseInfo()
|
||||
.setVisitorId(visitorId)
|
||||
.setVisitorIp(datagramPacket.sender().getAddress().getHostAddress())
|
||||
.setVisitorPort(datagramPacket.sender().getPort())
|
||||
.setTargetIp(targetIp)
|
||||
.setTargetPort(targetPort)
|
||||
.setProxyTimeoutMs(proxyTimeoutMs)
|
||||
.setProxyResponses(proxyResponses)
|
||||
).setData(bytes));
|
||||
|
||||
// 增加流量计数
|
||||
VisitorChannelAttachInfo visitorChannelAttachInfo = ProxyUtil.getAttachInfo(channel);
|
||||
Solon.context().getBean(FlowReportService.class).addWriteByte(visitorChannelAttachInfo.getLicenseId(), bytes.length);
|
||||
});
|
||||
|
||||
// String visitorId = ProxyUtil.getVisitorIdByChannel(ctx.channel());
|
||||
// if (StringUtils.isNotBlank(visitorId)) {
|
||||
// // UDP代理隧道已就绪,直接转发
|
||||
// proxyAttachment.execute();
|
||||
// return;
|
||||
// }
|
||||
Channel proxyChannel = ctx.channel().attr(Constants.NEXT_CHANNEL).get();
|
||||
if (null != proxyChannel && proxyChannel.isActive()) {
|
||||
// UDP代理隧道已就绪,直接转发
|
||||
proxyAttachment.execute();
|
||||
return;
|
||||
}
|
||||
|
||||
Channel visitorChannel = ctx.channel();
|
||||
InetSocketAddress sa = (InetSocketAddress) visitorChannel.localAddress();
|
||||
Channel cmdChannel = ProxyUtil.getCmdChannelByServerPort(sa.getPort());
|
||||
|
||||
// 没有指令通道,直接结束
|
||||
if (null == cmdChannel) {
|
||||
// 该端口还没有代理客户端
|
||||
// ctx.channel().close();
|
||||
return;
|
||||
}
|
||||
|
||||
// 根据代理服务端端口,获取被代理客户端局域网连接信息
|
||||
String lanInfo = ProxyUtil.getClientLanInfoByServerPort(sa.getPort());
|
||||
if (StrUtil.isEmpty(lanInfo)) {
|
||||
ctx.channel().close();
|
||||
return;
|
||||
}
|
||||
|
||||
String[] targetInfo = lanInfo.split(":");
|
||||
String targetIp = targetInfo[0];
|
||||
int targetPort = Integer.parseInt(targetInfo[1]);
|
||||
|
||||
// // 用户连接到代理服务器时,设置用户连接不可读,等待代理后端服务器连接成功后再改变为可读状态
|
||||
// visitorChannel.config().setOption(ChannelOption.AUTO_READ, false);
|
||||
|
||||
// TODO UDP此处叫visitor似有不妥,与TCP不同,2.x重构思考
|
||||
String visitorId = ProxyUtil.newVisitorId();
|
||||
// 此处需要和tcp分开
|
||||
ProxyUtil.addVisitorChannelToCmdChannel(NetworkProtocolEnum.UDP, cmdChannel, visitorId, visitorChannel, sa.getPort());
|
||||
ProxyUtil.addProxyConnectAttachment(visitorId, proxyAttachment);
|
||||
cmdChannel.writeAndFlush(ProxyMessage.buildUdpConnectMessage(new ProxyMessage.UdpBaseInfo()
|
||||
.setVisitorId(visitorId)
|
||||
.setServerPort(sa.getPort())
|
||||
.setTargetIp(targetIp)
|
||||
.setTargetPort(targetPort)
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
||||
super.channelActive(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
|
||||
// 当出现异常就关闭连接
|
||||
ctx.close();
|
||||
log.error("[UDP Visitor Channel]VisitorChannel error", cause);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception {
|
||||
|
||||
// 通知代理客户端
|
||||
Channel visitorChannel = ctx.channel();
|
||||
InetSocketAddress sa = (InetSocketAddress) visitorChannel.localAddress();
|
||||
Channel cmdChannel = ProxyUtil.getCmdChannelByServerPort(sa.getPort());
|
||||
|
||||
if (null == cmdChannel) {
|
||||
// 该端口还没有代理客户端
|
||||
ctx.channel().close();
|
||||
}
|
||||
else {
|
||||
Channel proxyChannel = visitorChannel.attr(Constants.NEXT_CHANNEL).get();
|
||||
if (null != proxyChannel) {
|
||||
proxyChannel.config().setOption(ChannelOption.AUTO_READ, visitorChannel.isWritable());
|
||||
}
|
||||
}
|
||||
|
||||
super.channelWritabilityChanged(ctx);
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,7 @@ package org.dromara.neutrinoproxy.server.proxy.domain;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.dromara.neutrinoproxy.server.constant.NetworkProtocolEnum;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -32,6 +33,7 @@ import lombok.experimental.Accessors;
|
||||
@Accessors(chain = true)
|
||||
@Data
|
||||
public class VisitorChannelAttachInfo {
|
||||
private NetworkProtocolEnum protocol;
|
||||
private String visitorId;
|
||||
private String lanInfo;
|
||||
private Integer serverPort;
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
package org.dromara.neutrinoproxy.server.proxy.enhance;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import io.netty.bootstrap.ServerBootstrap;
|
||||
import io.netty.channel.*;
|
||||
import io.netty.channel.nio.NioEventLoopGroup;
|
||||
import io.netty.channel.socket.SocketChannel;
|
||||
import io.netty.channel.socket.nio.NioServerSocketChannel;
|
||||
import io.netty.handler.logging.LoggingHandler;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.neutrinoproxy.server.base.proxy.ProxyConfig;
|
||||
import org.dromara.neutrinoproxy.server.proxy.core.BytesMetricsHandler;
|
||||
import org.dromara.neutrinoproxy.server.proxy.core.ProxyTunnelServer;
|
||||
import org.noear.solon.annotation.Component;
|
||||
import org.noear.solon.annotation.Inject;
|
||||
import org.noear.solon.core.event.AppLoadEndEvent;
|
||||
import org.noear.solon.core.event.EventListener;
|
||||
|
||||
/**
|
||||
* HTTP代理
|
||||
* @author: aoshiguchen
|
||||
* @date: 2023/4/2
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class HttpProxy implements EventListener<AppLoadEndEvent> {
|
||||
@Inject
|
||||
private ProxyConfig proxyConfig;
|
||||
@Override
|
||||
public void onEvent(AppLoadEndEvent appLoadEndEvent) throws Throwable {
|
||||
if (StrUtil.isBlank(proxyConfig.getServer().getTcp().getDomainName()) || null == proxyConfig.getServer().getTcp().getHttpProxyPort()) {
|
||||
log.info("no config domain name,nonsupport http proxy.");
|
||||
return;
|
||||
}
|
||||
this.start();
|
||||
}
|
||||
|
||||
private void start() {
|
||||
try {
|
||||
ServerBootstrap bootstrap = new ServerBootstrap();
|
||||
bootstrap.group(new NioEventLoopGroup(1), new NioEventLoopGroup())
|
||||
.channel(NioServerSocketChannel.class).childHandler(new ChannelInitializer<SocketChannel>() {
|
||||
@Override
|
||||
public void initChannel(SocketChannel ch) throws Exception {
|
||||
if (null != proxyConfig.getServer().getTcp().getTransferLogEnable() && proxyConfig.getServer().getTcp().getTransferLogEnable()) {
|
||||
ch.pipeline().addFirst(new LoggingHandler(HttpProxy.class));
|
||||
}
|
||||
ch.pipeline().addFirst(new BytesMetricsHandler());
|
||||
ch.pipeline().addLast(new HttpVisitorChannelHandler(proxyConfig.getServer().getTcp().getDomainName()));
|
||||
}
|
||||
});
|
||||
bootstrap.bind("0.0.0.0", proxyConfig.getServer().getTcp().getHttpProxyPort()).sync();
|
||||
log.info("Http proxy server start success!port:{}", proxyConfig.getServer().getTcp().getHttpProxyPort());
|
||||
} catch (Exception e) {
|
||||
log.error("http proxy start err!", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
package org.dromara.neutrinoproxy.server.proxy.enhance;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelOption;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.dromara.neutrinoproxy.core.Constants;
|
||||
import org.dromara.neutrinoproxy.core.ProxyMessage;
|
||||
import org.dromara.neutrinoproxy.server.constant.NetworkProtocolEnum;
|
||||
import org.dromara.neutrinoproxy.server.proxy.domain.ProxyAttachment;
|
||||
import org.dromara.neutrinoproxy.server.proxy.domain.VisitorChannelAttachInfo;
|
||||
import org.dromara.neutrinoproxy.server.service.FlowReportService;
|
||||
import org.dromara.neutrinoproxy.server.util.ProxyUtil;
|
||||
import org.noear.solon.Solon;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
/**
|
||||
* @author: aoshiguchen
|
||||
* @date: 2023/5/27
|
||||
*/
|
||||
@Slf4j
|
||||
public class HttpVisitorChannelHandler extends SimpleChannelInboundHandler<ByteBuf> {
|
||||
/**
|
||||
* 域名
|
||||
*/
|
||||
private String domainName;
|
||||
|
||||
public HttpVisitorChannelHandler(String domainName) {
|
||||
this.domainName = domainName;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void channelRead0(ChannelHandlerContext ctx, ByteBuf byteBuf) throws Exception {
|
||||
if (StrUtil.isBlank(domainName)) {
|
||||
ctx.channel().close();
|
||||
return;
|
||||
}
|
||||
|
||||
byte[] bytes = new byte[byteBuf.readableBytes()];
|
||||
byteBuf.readBytes(bytes);
|
||||
byteBuf.resetReaderIndex();
|
||||
ProxyAttachment proxyAttachment = new ProxyAttachment(ctx.channel(), bytes, (channel, buf) -> {
|
||||
Channel proxyChannel = channel.attr(Constants.NEXT_CHANNEL).get();
|
||||
if (null == proxyChannel) {
|
||||
// 该端口还没有代理客户端
|
||||
ctx.channel().close();
|
||||
return;
|
||||
}
|
||||
|
||||
proxyChannel.writeAndFlush(ProxyMessage.buildTransferMessage(ProxyUtil.getVisitorIdByChannel(channel), bytes));
|
||||
|
||||
// 增加流量计数
|
||||
VisitorChannelAttachInfo visitorChannelAttachInfo = ProxyUtil.getAttachInfo(channel);
|
||||
Solon.context().getBean(FlowReportService.class).addWriteByte(visitorChannelAttachInfo.getLicenseId(), bytes.length);
|
||||
});
|
||||
|
||||
String visitorId = ProxyUtil.getVisitorIdByChannel(ctx.channel());
|
||||
if (StringUtils.isNotBlank(visitorId)) {
|
||||
proxyAttachment.execute();
|
||||
return;
|
||||
}
|
||||
|
||||
// 用户连接到代理服务器时,设置用户连接不可读,等待代理后端服务器连接成功后再改变为可读状态
|
||||
ctx.channel().config().setOption(ChannelOption.AUTO_READ, false);
|
||||
|
||||
String host = getHost(bytes);
|
||||
log.debug("HttpProxy host: {}", host);
|
||||
if (StringUtils.isBlank(host)) {
|
||||
ctx.channel().close();
|
||||
return;
|
||||
}
|
||||
if (!host.endsWith(domainName)) {
|
||||
ctx.channel().close();
|
||||
return;
|
||||
}
|
||||
int index = host.lastIndexOf("." + domainName);
|
||||
String subdomain = host.substring(0, index);
|
||||
|
||||
// 根据域名拿到绑定的映射对应的cmdChannel
|
||||
Integer serverPort = ProxyUtil.getServerPortBySubdomain(subdomain);
|
||||
if (null == serverPort) {
|
||||
ctx.channel().close();
|
||||
return;
|
||||
}
|
||||
Channel cmdChannel = ProxyUtil.getCmdChannelByServerPort(serverPort);
|
||||
if (null == cmdChannel) {
|
||||
ctx.channel().close();
|
||||
return;
|
||||
}
|
||||
String lanInfo = ProxyUtil.getClientLanInfoByServerPort(serverPort);
|
||||
if (StringUtils.isBlank(lanInfo)) {
|
||||
ctx.channel().close();
|
||||
return;
|
||||
}
|
||||
|
||||
visitorId = ProxyUtil.newVisitorId();
|
||||
ProxyUtil.addVisitorChannelToCmdChannel(NetworkProtocolEnum.HTTP, cmdChannel, visitorId, ctx.channel(), serverPort);
|
||||
ProxyUtil.addProxyConnectAttachment(visitorId, proxyAttachment);
|
||||
cmdChannel.writeAndFlush(ProxyMessage.buildConnectMessage(visitorId).setData(lanInfo.getBytes()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
||||
|
||||
// 通知代理客户端
|
||||
Channel visitorChannel = ctx.channel();
|
||||
InetSocketAddress sa = (InetSocketAddress) visitorChannel.localAddress();
|
||||
Channel cmdChannel = ProxyUtil.getCmdChannelByServerPort(sa.getPort());
|
||||
|
||||
if (cmdChannel == null) {
|
||||
// 该端口还没有代理客户端
|
||||
ctx.channel().close();
|
||||
} else {
|
||||
|
||||
// 用户连接断开,从控制连接中移除
|
||||
String visitorId = ProxyUtil.getVisitorIdByChannel(visitorChannel);
|
||||
ProxyUtil.removeVisitorChannelFromCmdChannel(cmdChannel, visitorId);
|
||||
|
||||
// 删除代理附加对象
|
||||
ProxyUtil.remoteProxyConnectAttachment(visitorId);
|
||||
|
||||
Channel proxyChannel = visitorChannel.attr(Constants.NEXT_CHANNEL).get();
|
||||
if (proxyChannel != null && proxyChannel.isActive()) {
|
||||
proxyChannel.attr(Constants.NEXT_CHANNEL).remove();
|
||||
proxyChannel.attr(Constants.LICENSE_ID).remove();
|
||||
proxyChannel.attr(Constants.VISITOR_ID).remove();
|
||||
|
||||
proxyChannel.config().setOption(ChannelOption.AUTO_READ, true);
|
||||
// 通知客户端,用户连接已经断开
|
||||
proxyChannel.writeAndFlush(ProxyMessage.buildDisconnectMessage(visitorId));
|
||||
}
|
||||
}
|
||||
|
||||
super.channelInactive(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
||||
super.channelActive(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
|
||||
// 当出现异常就关闭连接
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
private String getHost(byte[] buf) {
|
||||
String req = new String(buf);
|
||||
String[] lines = req.split("\r\n");
|
||||
String firstLine = lines[0];
|
||||
if (!(firstLine.endsWith("HTTP/1.1") || firstLine.endsWith("HTTP/1.0"))) {
|
||||
return null;
|
||||
}
|
||||
for (int i = 1; i < lines.length; i++) {
|
||||
String line = lines[i];
|
||||
if (!line.startsWith("Host: ")) {
|
||||
continue;
|
||||
}
|
||||
// 域名
|
||||
String domain = line.substring(6);
|
||||
// 去掉域名后面的端口号
|
||||
return domain.replaceAll(":.*", "");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package org.dromara.neutrinoproxy.server.proxy.enhance;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import io.netty.bootstrap.ServerBootstrap;
|
||||
import io.netty.channel.*;
|
||||
import io.netty.channel.nio.NioEventLoopGroup;
|
||||
import io.netty.channel.socket.SocketChannel;
|
||||
import io.netty.channel.socket.nio.NioServerSocketChannel;
|
||||
import io.netty.handler.logging.LoggingHandler;
|
||||
import io.netty.handler.ssl.SslHandler;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.dromara.neutrinoproxy.core.util.FileUtil;
|
||||
import org.dromara.neutrinoproxy.server.base.proxy.ProxyConfig;
|
||||
import org.dromara.neutrinoproxy.server.proxy.core.BytesMetricsHandler;
|
||||
import org.dromara.neutrinoproxy.server.proxy.core.ProxyTunnelServer;
|
||||
import org.noear.solon.annotation.Component;
|
||||
import org.noear.solon.annotation.Inject;
|
||||
import org.noear.solon.core.event.AppLoadEndEvent;
|
||||
import org.noear.solon.core.event.EventListener;
|
||||
|
||||
import javax.net.ssl.*;
|
||||
import java.io.InputStream;
|
||||
import java.security.KeyStore;
|
||||
|
||||
/**
|
||||
* HTTPS代理
|
||||
* @author: aoshiguchen
|
||||
* @date: 2023/4/2
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class HttpsProxy implements EventListener<AppLoadEndEvent> {
|
||||
@Inject
|
||||
private ProxyConfig proxyConfig;
|
||||
@Override
|
||||
public void onEvent(AppLoadEndEvent appLoadEndEvent) throws Throwable {
|
||||
if (StrUtil.isBlank(proxyConfig.getServer().getTcp().getDomainName()) || null == proxyConfig.getServer().getTcp().getHttpsProxyPort() ||
|
||||
StringUtils.isEmpty(proxyConfig.getServer().getTcp().getJksPath()) || StringUtils.isEmpty(proxyConfig.getServer().getTcp().getKeyStorePassword())) {
|
||||
log.info("no config domain name,nonsupport https proxy.");
|
||||
return;
|
||||
}
|
||||
this.start();
|
||||
}
|
||||
|
||||
private void start() {
|
||||
try {
|
||||
ServerBootstrap bootstrap = new ServerBootstrap();
|
||||
bootstrap.group(new NioEventLoopGroup(1), new NioEventLoopGroup())
|
||||
.channel(NioServerSocketChannel.class).childHandler(new ChannelInitializer<SocketChannel>() {
|
||||
@Override
|
||||
public void initChannel(SocketChannel ch) throws Exception {
|
||||
if (null != proxyConfig.getServer().getTcp().getTransferLogEnable() && proxyConfig.getServer().getTcp().getTransferLogEnable()) {
|
||||
ch.pipeline().addFirst(new LoggingHandler(HttpsProxy.class));
|
||||
}
|
||||
ch.pipeline().addLast(createSslHandler());
|
||||
ch.pipeline().addFirst(new BytesMetricsHandler());
|
||||
ch.pipeline().addLast(new HttpVisitorChannelHandler(proxyConfig.getServer().getTcp().getDomainName()));
|
||||
}
|
||||
});
|
||||
bootstrap.bind("0.0.0.0", proxyConfig.getServer().getTcp().getHttpsProxyPort()).sync();
|
||||
log.info("Https proxy server started!port:{}", proxyConfig.getServer().getTcp().getHttpsProxyPort());
|
||||
} catch (Exception e) {
|
||||
log.error("https proxy start err!", e);
|
||||
}
|
||||
}
|
||||
|
||||
private ChannelHandler createSslHandler() {
|
||||
try {
|
||||
InputStream jksInputStream = FileUtil.getInputStream(proxyConfig.getServer().getTcp().getJksPath());
|
||||
SSLContext serverContext = SSLContext.getInstance("TLS");
|
||||
final KeyStore ks = KeyStore.getInstance("JKS");
|
||||
|
||||
ks.load(jksInputStream, proxyConfig.getServer().getTcp().getKeyStorePassword().toCharArray());
|
||||
final KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||
kmf.init(ks, proxyConfig.getServer().getTcp().getKeyStorePassword().toCharArray());
|
||||
TrustManager[] trustManagers = null;
|
||||
|
||||
serverContext.init(kmf.getKeyManagers(), trustManagers, null);
|
||||
|
||||
SSLEngine sslEngine = serverContext.createSSLEngine();
|
||||
sslEngine.setUseClientMode(false);
|
||||
sslEngine.setNeedClientAuth(false);
|
||||
|
||||
return new SslHandler(sslEngine);
|
||||
} catch (Exception e) {
|
||||
log.error("create SSL handler failed", e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -79,81 +79,107 @@ public class ProxyMessageAuthHandler implements ProxyMessageHandler {
|
||||
String ip = ((InetSocketAddress)ctx.channel().remoteAddress()).getAddress().getHostAddress();
|
||||
Date now = new Date();
|
||||
|
||||
String info = proxyMessage.getInfo();
|
||||
String[] tmp = info.split(",");
|
||||
String licenseKey = proxyMessage.getInfo();
|
||||
String clientId = "";
|
||||
if (tmp.length == 2) {
|
||||
licenseKey = tmp[0];
|
||||
clientId = tmp[1];
|
||||
}
|
||||
|
||||
if (StrUtil.isEmpty(licenseKey)) {
|
||||
log.warn("[client connection] license cannot empty info:{} ", info);
|
||||
ctx.channel().writeAndFlush(ProxyMessage.buildAuthResultMessage(ExceptionEnum.AUTH_FAILED.getCode(), "license不能为空!", licenseKey));
|
||||
ctx.channel().close();
|
||||
clientConnectRecordService.add(new ClientConnectRecordDO()
|
||||
.setIp(ip)
|
||||
.setType(ClientConnectTypeEnum.CONNECT.getType())
|
||||
.setMsg(licenseKey)
|
||||
.setCode(SuccessCodeEnum.FAIL.getCode())
|
||||
.setErr("license不能为空!")
|
||||
.setErr("license cannot empty!")
|
||||
.setCreateTime(now)
|
||||
);
|
||||
return;
|
||||
}
|
||||
LicenseDO licenseDO = licenseService.findByKey(licenseKey);
|
||||
if (null == licenseDO) {
|
||||
log.warn("[client connection] license notfound info:{} ", info);
|
||||
ctx.channel().writeAndFlush(ProxyMessage.buildAuthResultMessage(ExceptionEnum.AUTH_FAILED.getCode(), "license不存在!", licenseKey));
|
||||
ctx.channel().close();
|
||||
clientConnectRecordService.add(new ClientConnectRecordDO()
|
||||
.setIp(ip)
|
||||
.setType(ClientConnectTypeEnum.CONNECT.getType())
|
||||
.setMsg(licenseKey)
|
||||
.setCode(SuccessCodeEnum.FAIL.getCode())
|
||||
.setErr("license不存在!")
|
||||
.setErr("license notfound!")
|
||||
.setCreateTime(now)
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (EnableStatusEnum.DISABLE.getStatus().equals(licenseDO.getEnable())) {
|
||||
ctx.channel().writeAndFlush(ProxyMessage.buildAuthResultMessage(ExceptionEnum.AUTH_FAILED.getCode(), "当前license已被禁用!", licenseKey));
|
||||
log.warn("[client connection] the license disabled info:{} ", info);
|
||||
ctx.channel().writeAndFlush(ProxyMessage.buildAuthResultMessage(ExceptionEnum.AUTH_FAILED.getCode(), "the license disabled!", licenseKey));
|
||||
ctx.channel().close();
|
||||
clientConnectRecordService.add(new ClientConnectRecordDO()
|
||||
.setIp(ip)
|
||||
.setLicenseId(licenseDO.getId())
|
||||
.setType(ClientConnectTypeEnum.CONNECT.getType())
|
||||
.setMsg(licenseKey)
|
||||
.setCode(SuccessCodeEnum.FAIL.getCode())
|
||||
.setErr("当前license已被禁用!")
|
||||
.setErr("the license disabled!")
|
||||
.setCreateTime(now));
|
||||
return;
|
||||
}
|
||||
UserDO userDO = userService.findById(licenseDO.getUserId());
|
||||
if (null == userDO || EnableStatusEnum.DISABLE.getStatus().equals(userDO.getEnable())) {
|
||||
ctx.channel().writeAndFlush(ProxyMessage.buildAuthResultMessage(ExceptionEnum.AUTH_FAILED.getCode(), "当前license无效!", licenseKey));
|
||||
log.warn("[client connection] the license invalid info:{} ", info);
|
||||
ctx.channel().writeAndFlush(ProxyMessage.buildAuthResultMessage(ExceptionEnum.AUTH_FAILED.getCode(), "the license invalid!", licenseKey));
|
||||
ctx.channel().close();
|
||||
clientConnectRecordService.add(new ClientConnectRecordDO()
|
||||
.setIp(ip)
|
||||
.setLicenseId(licenseDO.getId())
|
||||
.setType(ClientConnectTypeEnum.CONNECT.getType())
|
||||
.setMsg(licenseKey)
|
||||
.setCode(SuccessCodeEnum.FAIL.getCode())
|
||||
.setErr("当前license无效!")
|
||||
.setErr("the license invalid!")
|
||||
.setCreateTime(now));
|
||||
return;
|
||||
}
|
||||
Channel cmdChannel = ProxyUtil.getCmdChannelByLicenseId(licenseDO.getId());
|
||||
if (null != cmdChannel) {
|
||||
ctx.channel().writeAndFlush(ProxyMessage.buildAuthResultMessage(ExceptionEnum.AUTH_FAILED.getCode(), "当前license已被另一节点使用!", licenseKey));
|
||||
clientConnectRecordService.add(new ClientConnectRecordDO()
|
||||
.setIp(ip)
|
||||
.setLicenseId(licenseDO.getId())
|
||||
.setType(ClientConnectTypeEnum.CONNECT.getType())
|
||||
.setMsg(licenseKey)
|
||||
.setCode(SuccessCodeEnum.FAIL.getCode())
|
||||
.setErr("当前license已被另一节点使用!")
|
||||
.setCreateTime(now));
|
||||
return;
|
||||
String _clientId = ProxyUtil.getClientIdByLicenseId(licenseDO.getId());
|
||||
if (!clientId.equals(_clientId)) {
|
||||
log.warn("[client connection] the license on another no used info:{} _clientId:{}", info, _clientId);
|
||||
ctx.channel().writeAndFlush(ProxyMessage.buildAuthResultMessage(ExceptionEnum.AUTH_FAILED.getCode(), "the license on another no used!", licenseKey));
|
||||
ctx.channel().close();
|
||||
clientConnectRecordService.add(new ClientConnectRecordDO()
|
||||
.setIp(ip)
|
||||
.setLicenseId(licenseDO.getId())
|
||||
.setType(ClientConnectTypeEnum.CONNECT.getType())
|
||||
.setMsg(licenseKey)
|
||||
.setCode(SuccessCodeEnum.FAIL.getCode())
|
||||
.setErr("the license on another no used!")
|
||||
.setCreateTime(now));
|
||||
return;
|
||||
}
|
||||
}
|
||||
// 发送认证成功消息
|
||||
ctx.channel().writeAndFlush(ProxyMessage.buildAuthResultMessage(ExceptionEnum.SUCCESS.getCode(), "认证成功!", licenseKey));
|
||||
ctx.channel().writeAndFlush(ProxyMessage.buildAuthResultMessage(ExceptionEnum.SUCCESS.getCode(), "auth success!", licenseKey));
|
||||
|
||||
clientConnectRecordService.add(new ClientConnectRecordDO()
|
||||
.setIp(ip)
|
||||
.setLicenseId(licenseDO.getId())
|
||||
.setType(ClientConnectTypeEnum.CONNECT.getType())
|
||||
.setMsg(licenseKey)
|
||||
.setMsg(info)
|
||||
.setCode(SuccessCodeEnum.SUCCESS.getCode())
|
||||
.setCreateTime(now));
|
||||
|
||||
// 设置当前licenseId对应的客户端ID
|
||||
ProxyUtil.setLicenseIdToClientIdMap(licenseDO.getId(), clientId);
|
||||
|
||||
log.warn("[client connection] auth success info:{} ", info);
|
||||
|
||||
// 更新license在线状态
|
||||
licenseMapper.updateOnlineStatus(licenseDO.getId(), OnlineStatusEnum.ONLINE.getStatus(), now);
|
||||
// 初始化VisitorChannel
|
||||
|
||||
@@ -34,14 +34,14 @@ public class ProxyMessageConnectHandler implements ProxyMessageHandler {
|
||||
public void handle(ChannelHandlerContext ctx, ProxyMessage proxyMessage) {
|
||||
String info = proxyMessage.getInfo();
|
||||
if (StrUtil.isEmpty(info)) {
|
||||
ctx.channel().writeAndFlush(ProxyMessage.buildErrMessage(ExceptionEnum.CONNECT_FAILED, "info不能为空!"));
|
||||
ctx.channel().writeAndFlush(ProxyMessage.buildErrMessage(ExceptionEnum.CONNECT_FAILED, "info cannot be empty!"));
|
||||
ctx.channel().close();
|
||||
return;
|
||||
}
|
||||
|
||||
String[] tokens = info.split("@");
|
||||
if (tokens.length != 2) {
|
||||
ctx.channel().writeAndFlush(ProxyMessage.buildErrMessage(ExceptionEnum.CONNECT_FAILED, "info格式有误!"));
|
||||
ctx.channel().writeAndFlush(ProxyMessage.buildErrMessage(ExceptionEnum.CONNECT_FAILED, "info format error!"));
|
||||
ctx.channel().close();
|
||||
return;
|
||||
}
|
||||
@@ -50,18 +50,18 @@ public class ProxyMessageConnectHandler implements ProxyMessageHandler {
|
||||
|
||||
LicenseDO licenseDO = licenseService.findByKey(licenseKey);
|
||||
if (null == licenseDO) {
|
||||
ctx.channel().writeAndFlush(ProxyMessage.buildErrMessage(ExceptionEnum.CONNECT_FAILED, "license不存在!"));
|
||||
ctx.channel().writeAndFlush(ProxyMessage.buildErrMessage(ExceptionEnum.CONNECT_FAILED, "the license notfound!"));
|
||||
ctx.channel().close();
|
||||
return;
|
||||
}
|
||||
if (EnableStatusEnum.DISABLE.getStatus().equals(licenseDO.getEnable())) {
|
||||
ctx.channel().writeAndFlush(ProxyMessage.buildErrMessage(ExceptionEnum.CONNECT_FAILED, "当前license已被禁用!"));
|
||||
ctx.channel().writeAndFlush(ProxyMessage.buildErrMessage(ExceptionEnum.CONNECT_FAILED, "the license invalid!"));
|
||||
ctx.channel().close();
|
||||
return;
|
||||
}
|
||||
UserDO userDO = userService.findById(licenseDO.getUserId());
|
||||
if (null == userDO || EnableStatusEnum.DISABLE.getStatus().equals(userDO.getEnable())) {
|
||||
ctx.channel().writeAndFlush(ProxyMessage.buildErrMessage(ExceptionEnum.CONNECT_FAILED, "当前license无效!"));
|
||||
ctx.channel().writeAndFlush(ProxyMessage.buildErrMessage(ExceptionEnum.CONNECT_FAILED, "the license invalid!"));
|
||||
ctx.channel().close();
|
||||
return;
|
||||
}
|
||||
@@ -69,7 +69,7 @@ public class ProxyMessageConnectHandler implements ProxyMessageHandler {
|
||||
Channel cmdChannel = ProxyUtil.getCmdChannelByLicenseId(licenseDO.getId());
|
||||
|
||||
if (null == cmdChannel) {
|
||||
ctx.channel().writeAndFlush(ProxyMessage.buildErrMessage(ExceptionEnum.CONNECT_FAILED, "服务端异常,指令通道不存在!"));
|
||||
ctx.channel().writeAndFlush(ProxyMessage.buildErrMessage(ExceptionEnum.CONNECT_FAILED, "server error,cmd channel notfound!"));
|
||||
ctx.channel().close();
|
||||
return;
|
||||
}
|
||||
@@ -88,6 +88,8 @@ public class ProxyMessageConnectHandler implements ProxyMessageHandler {
|
||||
// 获取代理附加对象
|
||||
ProxyAttachment proxyAttachment = ProxyUtil.getProxyConnectAttachment(visitorId);
|
||||
if (null != proxyAttachment) {
|
||||
// 及时释放
|
||||
ProxyUtil.remoteProxyConnectAttachment(visitorId);
|
||||
proxyAttachment.execute();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,17 @@ public class ProxyMessageTransferHandler implements ProxyMessageHandler {
|
||||
public void handle(ChannelHandlerContext ctx, ProxyMessage proxyMessage) {
|
||||
Channel visitorChannel = ctx.channel().attr(Constants.NEXT_CHANNEL).get();
|
||||
if (null != visitorChannel) {
|
||||
if (!visitorChannel.isWritable()) {
|
||||
//自己不可写,通道可以读,让通道关闭读
|
||||
//自己可写,通道不可以读,让通道打开读
|
||||
if (ctx.channel().config().isAutoRead()) {
|
||||
ctx.channel().config().setAutoRead(false);
|
||||
}
|
||||
} else {
|
||||
if (ctx.channel().config().isAutoRead()) {
|
||||
ctx.channel().config().setAutoRead(true);
|
||||
}
|
||||
}
|
||||
ByteBuf buf = ctx.alloc().buffer(proxyMessage.getData().length);
|
||||
buf.writeBytes(proxyMessage.getData());
|
||||
visitorChannel.writeAndFlush(buf);
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
package org.dromara.neutrinoproxy.server.proxy.handler;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelOption;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.neutrinoproxy.core.*;
|
||||
import org.dromara.neutrinoproxy.core.dispatcher.Match;
|
||||
import org.dromara.neutrinoproxy.server.constant.EnableStatusEnum;
|
||||
import org.dromara.neutrinoproxy.server.dal.PortMappingMapper;
|
||||
import org.dromara.neutrinoproxy.server.dal.entity.LicenseDO;
|
||||
import org.dromara.neutrinoproxy.server.dal.entity.PortMappingDO;
|
||||
import org.dromara.neutrinoproxy.server.dal.entity.UserDO;
|
||||
import org.dromara.neutrinoproxy.server.proxy.domain.ProxyAttachment;
|
||||
import org.dromara.neutrinoproxy.server.service.LicenseService;
|
||||
import org.dromara.neutrinoproxy.server.service.UserService;
|
||||
import org.dromara.neutrinoproxy.server.util.ProxyUtil;
|
||||
import org.noear.solon.annotation.Component;
|
||||
import org.noear.solon.annotation.Inject;
|
||||
|
||||
/**
|
||||
* @author: aoshiguchen
|
||||
* @date: 2023/9/19
|
||||
*/
|
||||
@Slf4j
|
||||
@Match(type = Constants.ProxyDataTypeName.UDP_CONNECT)
|
||||
@Component
|
||||
public class UdpProxyMessageConnectHandler implements ProxyMessageHandler {
|
||||
@Inject
|
||||
private LicenseService licenseService;
|
||||
@Inject
|
||||
private UserService userService;
|
||||
@Inject
|
||||
private PortMappingMapper portMappingMapper;
|
||||
|
||||
@Override
|
||||
public void handle(ChannelHandlerContext ctx, ProxyMessage proxyMessage) {
|
||||
final ProxyMessage.UdpBaseInfo udpBaseInfo = JSONObject.parseObject(proxyMessage.getInfo(), ProxyMessage.UdpBaseInfo.class);
|
||||
final String licenseKey = new String(proxyMessage.getData());
|
||||
log.info("[UDP connect]info:{} licenseKey:{}", proxyMessage.getInfo(), licenseKey);
|
||||
|
||||
LicenseDO licenseDO = licenseService.findByKey(licenseKey);
|
||||
if (null == licenseDO) {
|
||||
ctx.channel().writeAndFlush(ProxyMessage.buildErrMessage(ExceptionEnum.CONNECT_FAILED, "the license notfound!"));
|
||||
ctx.channel().close();
|
||||
return;
|
||||
}
|
||||
if (EnableStatusEnum.DISABLE.getStatus().equals(licenseDO.getEnable())) {
|
||||
ctx.channel().writeAndFlush(ProxyMessage.buildErrMessage(ExceptionEnum.CONNECT_FAILED, "the license disabled!"));
|
||||
ctx.channel().close();
|
||||
return;
|
||||
}
|
||||
UserDO userDO = userService.findById(licenseDO.getUserId());
|
||||
if (null == userDO || EnableStatusEnum.DISABLE.getStatus().equals(userDO.getEnable())) {
|
||||
ctx.channel().writeAndFlush(ProxyMessage.buildErrMessage(ExceptionEnum.CONNECT_FAILED, "the license invalid!"));
|
||||
ctx.channel().close();
|
||||
return;
|
||||
}
|
||||
|
||||
Channel cmdChannel = ProxyUtil.getCmdChannelByLicenseId(licenseDO.getId());
|
||||
|
||||
if (null == cmdChannel) {
|
||||
ctx.channel().writeAndFlush(ProxyMessage.buildErrMessage(ExceptionEnum.CONNECT_FAILED, "server error,cmd channel notfound!"));
|
||||
ctx.channel().close();
|
||||
return;
|
||||
}
|
||||
|
||||
Channel visitorChannel = ProxyUtil.getVisitorChannel(cmdChannel, udpBaseInfo.getVisitorId());
|
||||
if (null == visitorChannel) {
|
||||
return;
|
||||
}
|
||||
PortMappingDO portMappingDO = portMappingMapper.findByLicenseIdAndServerPort(licenseDO.getId(), udpBaseInfo.getServerPort());
|
||||
if (null == portMappingDO || !EnableStatusEnum.ENABLE.getStatus().equals(portMappingDO.getEnable())) {
|
||||
ctx.channel().writeAndFlush(ProxyMessage.buildErrMessage(ExceptionEnum.CONNECT_FAILED, "server error, port mapping notfound!"));
|
||||
ctx.channel().close();
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.channel().attr(Constants.VISITOR_ID).set(udpBaseInfo.getVisitorId());
|
||||
ctx.channel().attr(Constants.LICENSE_ID).set(licenseDO.getId());
|
||||
ctx.channel().attr(Constants.NEXT_CHANNEL).set(visitorChannel);
|
||||
ctx.channel().attr(Constants.TARGET_IP).set(portMappingDO.getClientIp());
|
||||
ctx.channel().attr(Constants.TARGET_PORT).set(portMappingDO.getClientPort());
|
||||
ctx.channel().attr(Constants.PROXY_RESPONSES).set(portMappingDO.getProxyResponses());
|
||||
ctx.channel().attr(Constants.PROXY_TIMEOUT_MS).set(portMappingDO.getProxyTimeoutMs());
|
||||
visitorChannel.attr(Constants.NEXT_CHANNEL).set(ctx.channel());
|
||||
visitorChannel.attr(Constants.IS_UDP_KEY).set(Boolean.TRUE);
|
||||
// // 代理客户端与后端服务器连接成功,修改用户连接为可读状态
|
||||
// visitorChannel.config().setOption(ChannelOption.AUTO_READ, true);
|
||||
// 获取代理附加对象
|
||||
ProxyAttachment proxyAttachment = ProxyUtil.getProxyConnectAttachment(udpBaseInfo.getVisitorId());
|
||||
if (null != proxyAttachment) {
|
||||
// 及时释放
|
||||
ProxyUtil.remoteProxyConnectAttachment(udpBaseInfo.getVisitorId());
|
||||
proxyAttachment.execute();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return ProxyDataTypeEnum.UDP_CONNECT.getDesc();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package org.dromara.neutrinoproxy.server.proxy.handler;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.socket.DatagramPacket;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.neutrinoproxy.core.Constants;
|
||||
import org.dromara.neutrinoproxy.core.ProxyDataTypeEnum;
|
||||
import org.dromara.neutrinoproxy.core.ProxyMessage;
|
||||
import org.dromara.neutrinoproxy.core.ProxyMessageHandler;
|
||||
import org.dromara.neutrinoproxy.core.dispatcher.Match;
|
||||
import org.dromara.neutrinoproxy.server.proxy.domain.VisitorChannelAttachInfo;
|
||||
import org.dromara.neutrinoproxy.server.service.FlowReportService;
|
||||
import org.dromara.neutrinoproxy.server.util.ProxyUtil;
|
||||
import org.noear.solon.Solon;
|
||||
import org.noear.solon.annotation.Component;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
/**
|
||||
* @author: aoshiguchen
|
||||
* @date: 2023/9/21
|
||||
*/
|
||||
@Slf4j
|
||||
@Match(type = Constants.ProxyDataTypeName.UDP_TRANSFER)
|
||||
@Component
|
||||
public class UdpProxyMessageTransferHandler implements ProxyMessageHandler {
|
||||
@Override
|
||||
public void handle(ChannelHandlerContext ctx, ProxyMessage proxyMessage) {
|
||||
final ProxyMessage.UdpBaseInfo udpBaseInfo = JSONObject.parseObject(proxyMessage.getInfo(), ProxyMessage.UdpBaseInfo.class);
|
||||
log.debug("[UDP transfer]info:{} data:{}", proxyMessage.getInfo(), new String(proxyMessage.getData()));
|
||||
|
||||
Channel visitorChannel = ctx.channel().attr(Constants.NEXT_CHANNEL).get();
|
||||
if (null != visitorChannel) {
|
||||
|
||||
if (!visitorChannel.isWritable()) {
|
||||
//自己不可写,通道可以读,让通道关闭读
|
||||
//自己可写,通道不可以读,让通道打开读
|
||||
if (ctx.channel().config().isAutoRead()) {
|
||||
ctx.channel().config().setAutoRead(false);
|
||||
}
|
||||
} else {
|
||||
if (ctx.channel().config().isAutoRead()) {
|
||||
ctx.channel().config().setAutoRead(true);
|
||||
}
|
||||
}
|
||||
|
||||
// InetSocketAddress address = new InetSocketAddress(udpBaseInfo.getVisitorIp(), udpBaseInfo.getVisitorPort());
|
||||
// ByteBuf byteBuf = Unpooled.copiedBuffer(proxyMessage.getData());
|
||||
// visitorChannel.writeAndFlush(new DatagramPacket(byteBuf, address));
|
||||
InetSocketAddress address = ctx.channel().attr(Constants.SENDER).get();
|
||||
if (null != address) {
|
||||
visitorChannel.writeAndFlush(new DatagramPacket(Unpooled.copiedBuffer(proxyMessage.getData()), address));
|
||||
}
|
||||
|
||||
// 增加流量计数(TODO 如果UDP映射服务端端口修改,这个似乎不准)
|
||||
Integer licenseId = visitorChannel.attr(Constants.LICENSE_ID).get();
|
||||
if (null != licenseId) {
|
||||
Solon.context().getBean(FlowReportService.class).addReadByte(licenseId, proxyMessage.getData().length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return ProxyDataTypeEnum.UDP_TRANSFER.getDesc();
|
||||
}
|
||||
}
|
||||
@@ -60,11 +60,11 @@ public class JobLogService implements IJobCallback {
|
||||
Integer code = 0;
|
||||
String msg = "";
|
||||
if (null == throwable) {
|
||||
msg = "执行成功";
|
||||
log.info("job[id={},name={}]执行完毕", jobInfo.getId(), jobInfo.getName());
|
||||
msg = "execute success";
|
||||
log.debug("job[id={},name={}]execute success", jobInfo.getId(), jobInfo.getName());
|
||||
} else {
|
||||
log.error("job[id={},name={}]执行异常", jobInfo.getId(), jobInfo.getName(), throwable);
|
||||
msg = "执行异常:\r\n" + ExceptionUtils.getStackTrace(throwable);
|
||||
log.error("job[id={},name={}]execute error", jobInfo.getId(), jobInfo.getName(), throwable);
|
||||
msg = "execute error:\r\n" + ExceptionUtils.getStackTrace(throwable);
|
||||
code = -1;
|
||||
}
|
||||
jobLogMapper.insert(new JobLogDO()
|
||||
|
||||
@@ -6,9 +6,12 @@ import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.google.common.collect.Sets;
|
||||
import ma.glasnost.orika.MapperFacade;
|
||||
import org.apache.ibatis.solon.annotation.Db;
|
||||
import org.dromara.neutrinoproxy.server.base.db.DBInitialize;
|
||||
import org.dromara.neutrinoproxy.server.base.page.PageInfo;
|
||||
import org.dromara.neutrinoproxy.server.base.page.PageQuery;
|
||||
import org.dromara.neutrinoproxy.server.base.rest.ServiceException;
|
||||
import org.dromara.neutrinoproxy.server.base.rest.SystemContextHolder;
|
||||
import org.dromara.neutrinoproxy.server.constant.EnableStatusEnum;
|
||||
import org.dromara.neutrinoproxy.server.constant.ExceptionConstant;
|
||||
@@ -19,18 +22,15 @@ import org.dromara.neutrinoproxy.server.controller.req.proxy.LicenseUpdateEnable
|
||||
import org.dromara.neutrinoproxy.server.controller.req.proxy.LicenseUpdateReq;
|
||||
import org.dromara.neutrinoproxy.server.controller.res.proxy.*;
|
||||
import org.dromara.neutrinoproxy.server.dal.LicenseMapper;
|
||||
import org.dromara.neutrinoproxy.server.dal.PortMappingMapper;
|
||||
import org.dromara.neutrinoproxy.server.dal.UserMapper;
|
||||
import org.dromara.neutrinoproxy.server.dal.entity.LicenseDO;
|
||||
import org.dromara.neutrinoproxy.server.dal.entity.PortMappingDO;
|
||||
import org.dromara.neutrinoproxy.server.dal.entity.UserDO;
|
||||
import org.dromara.neutrinoproxy.server.util.ParamCheckUtil;
|
||||
import ma.glasnost.orika.MapperFacade;
|
||||
import org.apache.ibatis.solon.annotation.Db;
|
||||
import org.dromara.neutrinoproxy.server.controller.res.proxy.*;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.noear.solon.annotation.Component;
|
||||
import org.noear.solon.annotation.Init;
|
||||
import org.noear.solon.annotation.Inject;
|
||||
import org.noear.solon.core.Lifecycle;
|
||||
import org.noear.solon.core.bean.LifecycleBean;
|
||||
|
||||
import java.util.*;
|
||||
@@ -39,220 +39,231 @@ import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* license服务
|
||||
*
|
||||
* @author: aoshiguchen
|
||||
* @date: 2022/8/6
|
||||
*/
|
||||
@Component
|
||||
public class LicenseService implements LifecycleBean {
|
||||
@Inject
|
||||
private MapperFacade mapperFacade;
|
||||
@Db
|
||||
private LicenseMapper licenseMapper;
|
||||
@Db
|
||||
private UserMapper userMapper;
|
||||
@Inject
|
||||
private VisitorChannelService visitorChannelService;
|
||||
@Inject
|
||||
private DBInitialize dbInitialize;
|
||||
@Inject
|
||||
private MapperFacade mapperFacade;
|
||||
@Db
|
||||
private LicenseMapper licenseMapper;
|
||||
@Db
|
||||
private PortMappingMapper portMappingMapper;
|
||||
@Db
|
||||
private UserMapper userMapper;
|
||||
@Inject
|
||||
private VisitorChannelService visitorChannelService;
|
||||
@Inject
|
||||
private DBInitialize dbInitialize;
|
||||
|
||||
public PageInfo<LicenseListRes> page(PageQuery pageQuery, LicenseListReq req) {
|
||||
Page<LicenseListRes> result = PageHelper.startPage(pageQuery.getCurrent(), pageQuery.getSize());
|
||||
List<LicenseDO> list = licenseMapper.selectList(new LambdaQueryWrapper<LicenseDO>()
|
||||
.eq(req.getUserId() != null, LicenseDO::getUserId, req.getUserId())
|
||||
.eq(req.getIsOnline() != null, LicenseDO::getIsOnline, req.getIsOnline())
|
||||
.eq(req.getEnable() != null, LicenseDO::getEnable, req.getEnable())
|
||||
.orderByAsc(Arrays.asList(LicenseDO::getUserId, LicenseDO::getId))
|
||||
);
|
||||
List<LicenseListRes> respList = mapperFacade.mapAsList(list, LicenseListRes.class);
|
||||
if (CollectionUtils.isEmpty(list)) {
|
||||
return PageInfo.of(respList, result.getTotal(), pageQuery.getCurrent(), pageQuery.getSize());
|
||||
}
|
||||
if (!CollectionUtil.isEmpty(respList)) {
|
||||
Set<Integer> userIds = respList.stream().map(LicenseListRes::getUserId).collect(Collectors.toSet());
|
||||
List<UserDO> userList = userMapper.findByIds(userIds);
|
||||
Map<Integer, UserDO> userMap = userList.stream().collect(Collectors.toMap(UserDO::getId, Function.identity()));
|
||||
for (LicenseListRes item : respList) {
|
||||
UserDO userDO = userMap.get(item.getUserId());
|
||||
if (null != userDO) {
|
||||
item.setUserName(userDO.getName());
|
||||
}
|
||||
item.setKey(desensitization(item.getUserId(), item.getKey()));
|
||||
}
|
||||
}
|
||||
return PageInfo.of(respList, result.getTotal(), pageQuery.getCurrent(), pageQuery.getSize());
|
||||
}
|
||||
public PageInfo<LicenseListRes> page(PageQuery pageQuery, LicenseListReq req) {
|
||||
Page<LicenseListRes> result = PageHelper.startPage(pageQuery.getCurrent(), pageQuery.getSize());
|
||||
List<LicenseDO> list = licenseMapper.selectList(new LambdaQueryWrapper<LicenseDO>()
|
||||
.eq(req.getUserId() != null, LicenseDO::getUserId, req.getUserId())
|
||||
.eq(req.getIsOnline() != null, LicenseDO::getIsOnline, req.getIsOnline())
|
||||
.eq(req.getEnable() != null, LicenseDO::getEnable, req.getEnable())
|
||||
.orderByAsc(Arrays.asList(LicenseDO::getUserId, LicenseDO::getId))
|
||||
);
|
||||
List<LicenseListRes> respList = mapperFacade.mapAsList(list, LicenseListRes.class);
|
||||
if (CollectionUtils.isEmpty(list)) {
|
||||
return PageInfo.of(respList, result.getTotal(), pageQuery.getCurrent(), pageQuery.getSize());
|
||||
}
|
||||
if (!CollectionUtil.isEmpty(respList)) {
|
||||
Set<Integer> userIds = respList.stream().map(LicenseListRes::getUserId).collect(Collectors.toSet());
|
||||
List<UserDO> userList = userMapper.findByIds(userIds);
|
||||
Map<Integer, UserDO> userMap = userList.stream().collect(Collectors.toMap(UserDO::getId, Function.identity()));
|
||||
for (LicenseListRes item : respList) {
|
||||
UserDO userDO = userMap.get(item.getUserId());
|
||||
if (null != userDO) {
|
||||
item.setUserName(userDO.getName());
|
||||
}
|
||||
item.setKey(desensitization(item.getUserId(), item.getKey()));
|
||||
}
|
||||
}
|
||||
return PageInfo.of(respList, result.getTotal(), pageQuery.getCurrent(), pageQuery.getSize());
|
||||
}
|
||||
|
||||
public List<LicenseListRes> list(LicenseListReq req) {
|
||||
List<LicenseDO> list = licenseMapper.selectList(new LambdaQueryWrapper<LicenseDO>()
|
||||
.eq(null != req.getEnable(), LicenseDO::getEnable, req.getEnable())
|
||||
);
|
||||
List<LicenseListRes> licenseList = assembleConvertLicenses(list);
|
||||
return licenseList;
|
||||
}
|
||||
public List<LicenseListRes> list(LicenseListReq req) {
|
||||
List<LicenseDO> list = licenseMapper.selectList(new LambdaQueryWrapper<LicenseDO>()
|
||||
.eq(null != req.getEnable(), LicenseDO::getEnable, req.getEnable())
|
||||
);
|
||||
List<LicenseListRes> licenseList = assembleConvertLicenses(list);
|
||||
return licenseList;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private List<LicenseListRes> assembleConvertLicenses(List<LicenseDO> list) {
|
||||
List<LicenseListRes> licenseList = mapperFacade.mapAsList(list, LicenseListRes.class);
|
||||
if (!CollectionUtil.isEmpty(licenseList)) {
|
||||
Set<Integer> userIds = licenseList.stream().map(LicenseListRes::getUserId).collect(Collectors.toSet());
|
||||
List<UserDO> userList = userMapper.findByIds(userIds);
|
||||
Map<Integer, UserDO> userMap = userList.stream().collect(Collectors.toMap(UserDO::getId, Function.identity()));
|
||||
for (LicenseListRes item : licenseList) {
|
||||
UserDO userDO = userMap.get(item.getUserId());
|
||||
if (null != userDO) {
|
||||
item.setUserName(userDO.getName());
|
||||
}
|
||||
item.setKey(desensitization(item.getUserId(), item.getKey()));
|
||||
}
|
||||
}
|
||||
return licenseList;
|
||||
}
|
||||
private List<LicenseListRes> assembleConvertLicenses(List<LicenseDO> list) {
|
||||
List<LicenseListRes> licenseList = mapperFacade.mapAsList(list, LicenseListRes.class);
|
||||
if (!CollectionUtil.isEmpty(licenseList)) {
|
||||
Set<Integer> userIds = licenseList.stream().map(LicenseListRes::getUserId).collect(Collectors.toSet());
|
||||
List<UserDO> userList = userMapper.findByIds(userIds);
|
||||
Map<Integer, UserDO> userMap = userList.stream().collect(Collectors.toMap(UserDO::getId, Function.identity()));
|
||||
for (LicenseListRes item : licenseList) {
|
||||
UserDO userDO = userMap.get(item.getUserId());
|
||||
if (null != userDO) {
|
||||
item.setUserName(userDO.getName());
|
||||
}
|
||||
item.setKey(desensitization(item.getUserId(), item.getKey()));
|
||||
}
|
||||
}
|
||||
return licenseList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建license
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
public LicenseCreateRes create(LicenseCreateReq req) {
|
||||
LicenseDO licenseDO = licenseMapper.checkRepeat(req.getUserId(), req.getName());
|
||||
ParamCheckUtil.checkExpression(null == licenseDO, ExceptionConstant.LICENSE_NAME_CANNOT_REPEAT);
|
||||
/**
|
||||
* 创建license
|
||||
*
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
public LicenseCreateRes create(LicenseCreateReq req) {
|
||||
LicenseDO licenseDO = licenseMapper.checkRepeat(req.getUserId(), req.getName());
|
||||
ParamCheckUtil.checkExpression(null == licenseDO, ExceptionConstant.LICENSE_NAME_CANNOT_REPEAT);
|
||||
|
||||
String key = UUID.randomUUID().toString().replaceAll("-", "");
|
||||
Date now = new Date();
|
||||
String key = UUID.randomUUID().toString().replaceAll("-", "");
|
||||
Date now = new Date();
|
||||
|
||||
licenseMapper.insert(new LicenseDO()
|
||||
.setName(req.getName())
|
||||
.setKey(key)
|
||||
.setUserId(req.getUserId())
|
||||
.setIsOnline(OnlineStatusEnum.OFFLINE.getStatus())
|
||||
.setEnable(EnableStatusEnum.ENABLE.getStatus())
|
||||
.setCreateTime(now)
|
||||
.setUpdateTime(now)
|
||||
);
|
||||
return new LicenseCreateRes();
|
||||
}
|
||||
licenseMapper.insert(new LicenseDO()
|
||||
.setName(req.getName())
|
||||
.setKey(key)
|
||||
.setUserId(req.getUserId())
|
||||
.setIsOnline(OnlineStatusEnum.OFFLINE.getStatus())
|
||||
.setEnable(EnableStatusEnum.ENABLE.getStatus())
|
||||
.setCreateTime(now)
|
||||
.setUpdateTime(now)
|
||||
);
|
||||
return new LicenseCreateRes();
|
||||
}
|
||||
|
||||
public LicenseUpdateRes update(LicenseUpdateReq req) {
|
||||
LicenseDO oldLicenseDO = licenseMapper.findById(req.getId());
|
||||
ParamCheckUtil.checkNotNull(oldLicenseDO, ExceptionConstant.LICENSE_NOT_EXIST);
|
||||
public LicenseUpdateRes update(LicenseUpdateReq req) {
|
||||
LicenseDO oldLicenseDO = licenseMapper.findById(req.getId());
|
||||
ParamCheckUtil.checkNotNull(oldLicenseDO, ExceptionConstant.LICENSE_NOT_EXIST);
|
||||
|
||||
LicenseDO licenseCheck = licenseMapper.checkRepeat(oldLicenseDO.getUserId(), req.getName(), Sets.newHashSet(oldLicenseDO.getId()));
|
||||
ParamCheckUtil.checkMustNull(licenseCheck, ExceptionConstant.LICENSE_NAME_CANNOT_REPEAT);
|
||||
LicenseDO licenseCheck = licenseMapper.checkRepeat(oldLicenseDO.getUserId(), req.getName(), Sets.newHashSet(oldLicenseDO.getId()));
|
||||
ParamCheckUtil.checkMustNull(licenseCheck, ExceptionConstant.LICENSE_NAME_CANNOT_REPEAT);
|
||||
|
||||
licenseMapper.update(req.getId(), req.getName(), new Date());
|
||||
return new LicenseUpdateRes();
|
||||
}
|
||||
licenseMapper.update(req.getId(), req.getName(), new Date());
|
||||
return new LicenseUpdateRes();
|
||||
}
|
||||
|
||||
public LicenseDetailRes detail(Integer id) {
|
||||
LicenseDO licenseDO = licenseMapper.findById(id);
|
||||
if (null == licenseDO) {
|
||||
return null;
|
||||
}
|
||||
UserDO userDO = userMapper.findById(licenseDO.getUserId());
|
||||
String userName = "";
|
||||
if (null != userDO) {
|
||||
userName = userDO.getName();
|
||||
}
|
||||
return new LicenseDetailRes()
|
||||
.setId(licenseDO.getId())
|
||||
.setName(licenseDO.getName())
|
||||
.setKey(desensitization(licenseDO.getUserId(), licenseDO.getKey()))
|
||||
.setUserId(licenseDO.getUserId())
|
||||
.setUserName(userName)
|
||||
.setIsOnline(licenseDO.getIsOnline())
|
||||
.setEnable(licenseDO.getEnable())
|
||||
.setCreateTime(licenseDO.getCreateTime())
|
||||
.setUpdateTime(licenseDO.getUpdateTime())
|
||||
;
|
||||
}
|
||||
public LicenseDetailRes detail(Integer id) {
|
||||
LicenseDO licenseDO = licenseMapper.findById(id);
|
||||
if (null == licenseDO) {
|
||||
return null;
|
||||
}
|
||||
UserDO userDO = userMapper.findById(licenseDO.getUserId());
|
||||
String userName = "";
|
||||
if (null != userDO) {
|
||||
userName = userDO.getName();
|
||||
}
|
||||
return new LicenseDetailRes()
|
||||
.setId(licenseDO.getId())
|
||||
.setName(licenseDO.getName())
|
||||
.setKey(desensitization(licenseDO.getUserId(), licenseDO.getKey()))
|
||||
.setUserId(licenseDO.getUserId())
|
||||
.setUserName(userName)
|
||||
.setIsOnline(licenseDO.getIsOnline())
|
||||
.setEnable(licenseDO.getEnable())
|
||||
.setCreateTime(licenseDO.getCreateTime())
|
||||
.setUpdateTime(licenseDO.getUpdateTime())
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新license启用状态
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
public LicenseUpdateEnableStatusRes updateEnableStatus(LicenseUpdateEnableStatusReq req) {
|
||||
licenseMapper.updateEnableStatus(req.getId(), req.getEnable(), new Date());
|
||||
// 更新VisitorChannel
|
||||
visitorChannelService.updateVisitorChannelByLicenseId(req.getId(), req.getEnable());
|
||||
return new LicenseUpdateEnableStatusRes();
|
||||
}
|
||||
/**
|
||||
* 更新license启用状态
|
||||
*
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
public LicenseUpdateEnableStatusRes updateEnableStatus(LicenseUpdateEnableStatusReq req) {
|
||||
licenseMapper.updateEnableStatus(req.getId(), req.getEnable(), new Date());
|
||||
// 更新VisitorChannel
|
||||
visitorChannelService.updateVisitorChannelByLicenseId(req.getId(), req.getEnable());
|
||||
return new LicenseUpdateEnableStatusRes();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除license
|
||||
* @param id
|
||||
*/
|
||||
public void delete(Integer id) {
|
||||
licenseMapper.deleteById(id);
|
||||
// 更新VisitorChannel
|
||||
visitorChannelService.updateVisitorChannelByLicenseId(id, EnableStatusEnum.DISABLE.getStatus());
|
||||
}
|
||||
/**
|
||||
* 删除license
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
public void delete(Integer id) {
|
||||
List<PortMappingDO> portMappingDOList = portMappingMapper.findListByLicenseId(id);
|
||||
if (CollectionUtil.isNotEmpty(portMappingDOList)) {
|
||||
throw ServiceException.create(ExceptionConstant.LICENSE_CANNOT_BE_DELETED, portMappingDOList.size());
|
||||
}
|
||||
licenseMapper.deleteById(id);
|
||||
// 更新VisitorChannel
|
||||
visitorChannelService.updateVisitorChannelByLicenseId(id, EnableStatusEnum.DISABLE.getStatus());
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置license
|
||||
* @param id
|
||||
*/
|
||||
public void reset(Integer id) {
|
||||
String key = UUID.randomUUID().toString().replaceAll("-", "");
|
||||
Date now = new Date();
|
||||
/**
|
||||
* 重置license
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
public void reset(Integer id) {
|
||||
String key = UUID.randomUUID().toString().replaceAll("-", "");
|
||||
Date now = new Date();
|
||||
|
||||
licenseMapper.reset(id, key, now);
|
||||
}
|
||||
licenseMapper.reset(id, key, now);
|
||||
}
|
||||
|
||||
public LicenseDO findByKey(String license) {
|
||||
return licenseMapper.findByKey(license);
|
||||
}
|
||||
public LicenseDO findByKey(String license) {
|
||||
return licenseMapper.findByKey(license);
|
||||
}
|
||||
|
||||
/**
|
||||
* 脱敏处理
|
||||
* 非当前登录人的license,一律脱敏
|
||||
* @param userId
|
||||
* @param licenseKey
|
||||
* @return
|
||||
*/
|
||||
private String desensitization(Integer userId, String licenseKey) {
|
||||
Integer currentUserId = SystemContextHolder.getUser().getId();
|
||||
if (currentUserId.equals(userId)) {
|
||||
return licenseKey;
|
||||
}
|
||||
return licenseKey.substring(0, 10) + "****" + licenseKey.substring(licenseKey.length() - 10);
|
||||
}
|
||||
/**
|
||||
* 脱敏处理
|
||||
* 非当前登录人的license,一律脱敏
|
||||
*
|
||||
* @param userId
|
||||
* @param licenseKey
|
||||
* @return
|
||||
*/
|
||||
private String desensitization(Integer userId, String licenseKey) {
|
||||
Integer currentUserId = SystemContextHolder.getUser().getId();
|
||||
if (currentUserId.equals(userId)) {
|
||||
return licenseKey;
|
||||
}
|
||||
return licenseKey.substring(0, 10) + "****" + licenseKey.substring(licenseKey.length() - 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* 服务端项目停止、启动时,更新在线状态为离线
|
||||
*/
|
||||
@Init
|
||||
public void init() {
|
||||
licenseMapper.updateOnlineStatus(OnlineStatusEnum.OFFLINE.getStatus(), new Date());
|
||||
}
|
||||
/**
|
||||
* 服务端项目停止、启动时,更新在线状态为离线
|
||||
*/
|
||||
@Init
|
||||
public void init() {
|
||||
licenseMapper.updateOnlineStatus(OnlineStatusEnum.OFFLINE.getStatus(), new Date());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void start() throws Throwable {
|
||||
@Override
|
||||
public void start() throws Throwable {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 服务端项目停止、启动时,更新在线状态为离线
|
||||
*/
|
||||
@Override
|
||||
public void stop() throws Throwable {
|
||||
licenseMapper.updateOnlineStatus(OnlineStatusEnum.OFFLINE.getStatus(), new Date());
|
||||
}
|
||||
/**
|
||||
* 服务端项目停止、启动时,更新在线状态为离线
|
||||
*/
|
||||
@Override
|
||||
public void stop() throws Throwable {
|
||||
licenseMapper.updateOnlineStatus(OnlineStatusEnum.OFFLINE.getStatus(), new Date());
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询当前角色下的license,若为管理员 则返回全部license
|
||||
*/
|
||||
public List<LicenseListRes> queryCurUserLicense(LicenseListReq req) {
|
||||
if(SystemContextHolder.isAdmin()){
|
||||
return this.list(req);
|
||||
}
|
||||
/**
|
||||
* 查询当前角色下的license,若为管理员 则返回全部license
|
||||
*/
|
||||
public List<LicenseListRes> queryCurUserLicense(LicenseListReq req) {
|
||||
if (SystemContextHolder.isAdmin()) {
|
||||
return this.list(req);
|
||||
}
|
||||
|
||||
List<LicenseDO> list = licenseMapper.selectList(new LambdaQueryWrapper<LicenseDO>()
|
||||
.eq(LicenseDO::getEnable, EnableStatusEnum.ENABLE.getStatus())
|
||||
.eq(LicenseDO::getUserId,SystemContextHolder.getUserId())
|
||||
);
|
||||
List<LicenseListRes> licenseList = assembleConvertLicenses(list);
|
||||
return licenseList;
|
||||
}
|
||||
List<LicenseDO> list = licenseMapper.selectList(new LambdaQueryWrapper<LicenseDO>()
|
||||
.eq(LicenseDO::getEnable, EnableStatusEnum.ENABLE.getStatus())
|
||||
.eq(LicenseDO::getUserId, SystemContextHolder.getUserId())
|
||||
);
|
||||
List<LicenseListRes> licenseList = assembleConvertLicenses(list);
|
||||
return licenseList;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.google.common.collect.Sets;
|
||||
import ma.glasnost.orika.MapperFacade;
|
||||
import org.apache.ibatis.solon.annotation.Db;
|
||||
import org.dromara.neutrinoproxy.server.base.db.DBInitialize;
|
||||
import org.dromara.neutrinoproxy.server.base.page.PageInfo;
|
||||
import org.dromara.neutrinoproxy.server.base.page.PageQuery;
|
||||
@@ -31,14 +33,10 @@ import org.dromara.neutrinoproxy.server.dal.entity.PortMappingDO;
|
||||
import org.dromara.neutrinoproxy.server.dal.entity.PortPoolDO;
|
||||
import org.dromara.neutrinoproxy.server.dal.entity.UserDO;
|
||||
import org.dromara.neutrinoproxy.server.util.ParamCheckUtil;
|
||||
import ma.glasnost.orika.MapperFacade;
|
||||
import org.apache.ibatis.solon.annotation.Db;
|
||||
import org.dromara.neutrinoproxy.server.controller.res.proxy.*;
|
||||
import org.dromara.neutrinoproxy.server.util.ProxyUtil;
|
||||
import org.noear.solon.annotation.Component;
|
||||
import org.noear.solon.annotation.Init;
|
||||
import org.noear.solon.annotation.Inject;
|
||||
import org.noear.solon.core.Lifecycle;
|
||||
import org.noear.solon.core.bean.LifecycleBean;
|
||||
|
||||
import java.util.*;
|
||||
@@ -51,25 +49,25 @@ import java.util.stream.Collectors;
|
||||
*/
|
||||
@Component
|
||||
public class PortMappingService implements LifecycleBean {
|
||||
@Inject
|
||||
private MapperFacade mapperFacade;
|
||||
@Db
|
||||
private PortMappingMapper portMappingMapper;
|
||||
@Db
|
||||
private LicenseMapper licenseMapper;
|
||||
@Db
|
||||
private UserMapper userMapper;
|
||||
@Db
|
||||
private PortPoolMapper portPoolMapper;
|
||||
@Inject
|
||||
private VisitorChannelService visitorChannelService;
|
||||
@Inject
|
||||
private MapperFacade mapperFacade;
|
||||
@Db
|
||||
private PortMappingMapper portMappingMapper;
|
||||
@Db
|
||||
private LicenseMapper licenseMapper;
|
||||
@Db
|
||||
private UserMapper userMapper;
|
||||
@Db
|
||||
private PortPoolMapper portPoolMapper;
|
||||
@Inject
|
||||
private VisitorChannelService visitorChannelService;
|
||||
|
||||
@Inject
|
||||
private PortPoolService portPoolService;
|
||||
@Inject
|
||||
private ProxyConfig proxyConfig;
|
||||
@Inject
|
||||
private DBInitialize dbInitialize;
|
||||
@Inject
|
||||
private PortPoolService portPoolService;
|
||||
@Inject
|
||||
private ProxyConfig proxyConfig;
|
||||
@Inject
|
||||
private DBInitialize dbInitialize;
|
||||
|
||||
public PageInfo<PortMappingListRes> page(PageQuery pageQuery, PortMappingListReq req) {
|
||||
Page<PortMappingListRes> result = PageHelper.startPage(pageQuery.getCurrent(), pageQuery.getSize());
|
||||
@@ -77,6 +75,13 @@ public class PortMappingService implements LifecycleBean {
|
||||
//描述字段为模糊查询,在应用层处理,否则sqlite不支持
|
||||
req.setDescription("%" + req.getDescription() + "%");
|
||||
}
|
||||
|
||||
// 协议名称转换
|
||||
if (StringUtils.isNotBlank(req.getProtocal())) {
|
||||
NetworkProtocolEnum networkProtocolEnum = NetworkProtocolEnum.of(req.getProtocal());
|
||||
req.setProtocal(networkProtocolEnum.getDesc());
|
||||
}
|
||||
|
||||
List<PortMappingDO> list = portMappingMapper.selectPortMappingByCondition(req);
|
||||
List<PortMappingListRes> respList = mapperFacade.mapAsList(list, PortMappingListRes.class);
|
||||
if (CollectionUtils.isEmpty(list)) {
|
||||
@@ -105,15 +110,15 @@ public class PortMappingService implements LifecycleBean {
|
||||
return;
|
||||
}
|
||||
item.setUserName(user.getName());
|
||||
if (StrUtil.isNotBlank(proxyConfig.getServer().getDomainName()) && StrUtil.isNotBlank(item.getSubdomain())) {
|
||||
item.setDomain(item.getSubdomain() + "." + proxyConfig.getServer().getDomainName());
|
||||
if (StrUtil.isNotBlank(proxyConfig.getServer().getTcp().getDomainName()) && StrUtil.isNotBlank(item.getSubdomain())) {
|
||||
item.setDomain(item.getSubdomain() + "." + proxyConfig.getServer().getTcp().getDomainName());
|
||||
}
|
||||
if (NetworkProtocolEnum.HTTP.getDesc().equals(item.getProtocal())) {
|
||||
item.setProtocal("HTTP(S)");
|
||||
}
|
||||
});
|
||||
//sorted [userId asc] [licenseId asc] [createTime asc]
|
||||
respList = respList.stream().sorted(Comparator.comparing(PortMappingListRes::getUserId)
|
||||
.thenComparing(PortMappingListRes::getLicenseId)
|
||||
.thenComparing(PortMappingListRes::getCreateTime))
|
||||
.collect(Collectors.toList());
|
||||
respList = respList.stream().sorted(Comparator.comparing(PortMappingListRes::getUserId).thenComparing(PortMappingListRes::getLicenseId).thenComparing(PortMappingListRes::getCreateTime)).collect(Collectors.toList());
|
||||
return PageInfo.of(respList, result.getTotal(), pageQuery.getCurrent(), pageQuery.getSize());
|
||||
}
|
||||
|
||||
@@ -137,6 +142,8 @@ public class PortMappingService implements LifecycleBean {
|
||||
portMappingDO.setServerPort(req.getServerPort());
|
||||
portMappingDO.setClientIp(req.getClientIp());
|
||||
portMappingDO.setClientPort(req.getClientPort());
|
||||
portMappingDO.setProxyResponses(req.getProxyResponses());
|
||||
portMappingDO.setProxyTimeoutMs(req.getProxyTimeoutMs());
|
||||
portMappingDO.setDescription(req.getDescription());
|
||||
portMappingDO.setIsOnline(OnlineStatusEnum.OFFLINE.getStatus());
|
||||
portMappingDO.setEnable(EnableStatusEnum.ENABLE.getStatus());
|
||||
@@ -146,9 +153,7 @@ public class PortMappingService implements LifecycleBean {
|
||||
// 更新VisitorChannel
|
||||
visitorChannelService.addVisitorChannelByPortMapping(portMappingDO);
|
||||
// 更新域名映射
|
||||
if (NetworkProtocolEnum.HTTP.getDesc().equals(portMappingDO.getProtocal()) &&
|
||||
StrUtil.isNotBlank(proxyConfig.getServer().getDomainName()) &&
|
||||
StrUtil.isNotBlank(portMappingDO.getSubdomain())) {
|
||||
if (NetworkProtocolEnum.isHttp(portMappingDO.getProtocal()) && StrUtil.isNotBlank(proxyConfig.getServer().getTcp().getDomainName()) && StrUtil.isNotBlank(portMappingDO.getSubdomain())) {
|
||||
ProxyUtil.setSubdomainToServerPort(portMappingDO.getSubdomain(), portMappingDO.getServerPort());
|
||||
}
|
||||
return new PortMappingCreateRes();
|
||||
@@ -178,6 +183,8 @@ public class PortMappingService implements LifecycleBean {
|
||||
portMappingDO.setServerPort(req.getServerPort());
|
||||
portMappingDO.setClientIp(req.getClientIp());
|
||||
portMappingDO.setClientPort(req.getClientPort());
|
||||
portMappingDO.setProxyResponses(req.getProxyResponses());
|
||||
portMappingDO.setProxyTimeoutMs(req.getProxyTimeoutMs());
|
||||
portMappingDO.setDescription(req.getDescription());
|
||||
portMappingDO.setUpdateTime(new Date());
|
||||
portMappingDO.setEnable(EnableStatusEnum.ENABLE.getStatus());
|
||||
@@ -185,14 +192,11 @@ public class PortMappingService implements LifecycleBean {
|
||||
// 更新VisitorChannel
|
||||
visitorChannelService.updateVisitorChannelByPortMapping(oldPortMappingDO, portMappingDO);
|
||||
// 删除老的域名映射
|
||||
if (NetworkProtocolEnum.HTTP.getDesc().equals(oldPortMappingDO.getProtocal()) &&
|
||||
StrUtil.isNotBlank(oldPortMappingDO.getSubdomain())) {
|
||||
if (NetworkProtocolEnum.isHttp(oldPortMappingDO.getProtocal()) && StrUtil.isNotBlank(oldPortMappingDO.getSubdomain())) {
|
||||
ProxyUtil.removeSubdomainToServerPort(oldPortMappingDO.getSubdomain());
|
||||
}
|
||||
// 更新域名映射
|
||||
if (NetworkProtocolEnum.HTTP.getDesc().equals(portMappingDO.getProtocal()) &&
|
||||
StrUtil.isNotBlank(proxyConfig.getServer().getDomainName()) &&
|
||||
StrUtil.isNotBlank(portMappingDO.getSubdomain())) {
|
||||
if (NetworkProtocolEnum.isHttp(portMappingDO.getProtocal()) && StrUtil.isNotBlank(proxyConfig.getServer().getTcp().getDomainName()) && StrUtil.isNotBlank(portMappingDO.getSubdomain())) {
|
||||
ProxyUtil.setSubdomainToServerPort(portMappingDO.getSubdomain(), portMappingDO.getServerPort());
|
||||
}
|
||||
return new PortMappingUpdateRes();
|
||||
@@ -204,15 +208,17 @@ public class PortMappingService implements LifecycleBean {
|
||||
return null;
|
||||
}
|
||||
PortMappingDetailRes res = new PortMappingDetailRes()
|
||||
.setId(portMappingDO.getId())
|
||||
.setLicenseId(portMappingDO.getLicenseId())
|
||||
.setServerPort(portMappingDO.getServerPort())
|
||||
.setClientIp(portMappingDO.getClientIp())
|
||||
.setClientPort(portMappingDO.getClientPort())
|
||||
.setIsOnline(portMappingDO.getIsOnline())
|
||||
.setEnable(portMappingDO.getEnable())
|
||||
.setCreateTime(portMappingDO.getCreateTime())
|
||||
.setUpdateTime(portMappingDO.getUpdateTime());
|
||||
.setId(portMappingDO.getId())
|
||||
.setLicenseId(portMappingDO.getLicenseId())
|
||||
.setServerPort(portMappingDO.getServerPort())
|
||||
.setClientIp(portMappingDO.getClientIp())
|
||||
.setClientPort(portMappingDO.getClientPort())
|
||||
.setIsOnline(portMappingDO.getIsOnline())
|
||||
.setProxyTimeoutMs(portMappingDO.getProxyTimeoutMs())
|
||||
.setProxyResponses(portMappingDO.getProxyResponses())
|
||||
.setEnable(portMappingDO.getEnable())
|
||||
.setCreateTime(portMappingDO.getCreateTime())
|
||||
.setUpdateTime(portMappingDO.getUpdateTime());
|
||||
|
||||
LicenseDO license = licenseMapper.findById(portMappingDO.getLicenseId());
|
||||
if (null != license) {
|
||||
@@ -265,8 +271,7 @@ public class PortMappingService implements LifecycleBean {
|
||||
// 更新VisitorChannel
|
||||
visitorChannelService.removeVisitorChannelByPortMapping(portMappingDO);
|
||||
// 更新域名映射
|
||||
if (NetworkProtocolEnum.HTTP.getDesc().equals(portMappingDO.getProtocal()) &&
|
||||
StrUtil.isNotBlank(portMappingDO.getSubdomain())) {
|
||||
if (NetworkProtocolEnum.isHttp(portMappingDO.getProtocal()) && StrUtil.isNotBlank(portMappingDO.getSubdomain())) {
|
||||
ProxyUtil.removeSubdomainToServerPort(portMappingDO.getSubdomain());
|
||||
}
|
||||
}
|
||||
@@ -289,13 +294,10 @@ public class PortMappingService implements LifecycleBean {
|
||||
portMappingMapper.updateOnlineStatus(OnlineStatusEnum.OFFLINE.getStatus(), new Date());
|
||||
|
||||
// 未配置域名,则不需要处理域名映射逻辑
|
||||
if (StrUtil.isBlank(proxyConfig.getServer().getDomainName())) {
|
||||
if (StrUtil.isBlank(proxyConfig.getServer().getTcp().getDomainName())) {
|
||||
return;
|
||||
}
|
||||
List<PortMappingDO> portMappingDOList = portMappingMapper.selectList(new LambdaQueryWrapper<PortMappingDO>()
|
||||
.eq(PortMappingDO::getProtocal, NetworkProtocolEnum.HTTP.getDesc())
|
||||
.isNotNull(PortMappingDO::getSubdomain)
|
||||
);
|
||||
List<PortMappingDO> portMappingDOList = portMappingMapper.selectList(new LambdaQueryWrapper<PortMappingDO>().eq(PortMappingDO::getProtocal, NetworkProtocolEnum.HTTP.getDesc()).isNotNull(PortMappingDO::getSubdomain));
|
||||
if (CollectionUtil.isEmpty(portMappingDOList)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.apache.ibatis.solon.annotation.Db;
|
||||
import org.dromara.neutrinoproxy.server.controller.req.system.*;
|
||||
import org.dromara.neutrinoproxy.server.controller.res.system.*;
|
||||
import org.dromara.neutrinoproxy.server.dal.entity.PortGroupDO;
|
||||
import org.dromara.neutrinoproxy.server.util.PortAvailableUtil;
|
||||
import org.noear.solon.annotation.Component;
|
||||
import org.noear.solon.annotation.Inject;
|
||||
|
||||
@@ -175,8 +176,44 @@ public class PortPoolService {
|
||||
* 游客:全局端口 + 当前选择用户独占端口 + 当前选择license独占端口
|
||||
* 非管理员身份时:下拉选择license,只能选当前用户下的LICENSE
|
||||
*/
|
||||
public List<PortPoolListRes> getAvailablePortList(AvailablePortListReq req) {
|
||||
public PageInfo<PortPoolListRes> getAvailablePortList(AvailablePortListReq req) {
|
||||
|
||||
LicenseDO licenseDO = licenseMapper.queryById(req.getLicenseId());
|
||||
return portPoolMapper.getAvailablePortList(req.getLicenseId(), licenseDO.getUserId());
|
||||
if(StringUtils.isNotEmpty(req.getKeyword())){
|
||||
req.setKeyword(req.getKeyword()+"%");
|
||||
}
|
||||
|
||||
Page<PortPoolListRes> result = PageHelper.startPage(req.getPage(), req.getSize());
|
||||
List<PortPoolListRes> portList = portPoolMapper.getAvailablePortList(req.getLicenseId(), licenseDO.getUserId(), req.getKeyword());
|
||||
|
||||
return PageInfo.of(portList, result.getTotal(), req.getPage(), req.getSize());
|
||||
}
|
||||
|
||||
public void deleteBatch(List<Integer> ids) {
|
||||
List<PortPoolDO> portPoolDOList = portPoolMapper.selectBatchIds(ids);
|
||||
ParamCheckUtil.checkNotNull(portPoolDOList, ExceptionConstant.PORT_NOT_EXIST);
|
||||
|
||||
portPoolMapper.deleteBatchIds(ids);
|
||||
// 更新visitorChannel
|
||||
portPoolDOList.stream().forEach(portPoolDO -> {
|
||||
visitorChannelService.updateVisitorChannelByPortPool(portPoolDO.getPort(), EnableStatusEnum.DISABLE.getStatus());
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查端口是否被占用
|
||||
* 端口映射编辑时,如果端口号没有变动,则不验证。避免出现端口映射正在使用时,无法更新端口映射其他信息的问题
|
||||
* @param port
|
||||
* @param portMappingId
|
||||
* @return
|
||||
*/
|
||||
public boolean portAvailable(Integer port, Integer portMappingId) {
|
||||
if (null != portMappingId) {
|
||||
PortMappingDO portMappingDO = portMappingMapper.findById(portMappingId);
|
||||
if (null != portMappingDO && portMappingDO.getServerPort().equals(port)) {
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
}
|
||||
return PortAvailableUtil.isPortAvailable(port);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.dromara.neutrinoproxy.server.service;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.neutrinoproxy.server.constant.NetworkProtocolEnum;
|
||||
import org.dromara.neutrinoproxy.server.controller.res.system.ProtocalListRes;
|
||||
import org.noear.solon.annotation.Component;
|
||||
|
||||
@@ -22,8 +23,8 @@ public class ProtocalService {
|
||||
public List<ProtocalListRes> list() {
|
||||
return Lists.newArrayList(
|
||||
new ProtocalListRes().setName("TCP").setEnable(Boolean.TRUE).setRemark("支持一切TCP之上的协议"),
|
||||
new ProtocalListRes().setName("HTTP").setEnable(Boolean.TRUE).setRemark("支持绑定子域名,未绑定时等价于时使用TCP"),
|
||||
new ProtocalListRes().setName("UDP").setEnable(Boolean.FALSE).setRemark("暂不支持")
|
||||
new ProtocalListRes().setName("HTTP(S)").setEnable(Boolean.TRUE).setRemark("支持绑定子域名,未绑定时等价于时使用TCP。 若配置了证书,则同时支持HTTPS。"),
|
||||
new ProtocalListRes().setName("UDP").setEnable(Boolean.TRUE).setRemark("暂不支持")
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ public class ProxyMutualService {
|
||||
Date now = new Date();
|
||||
portMappingMapper.updateOnlineStatus(attachInfo.getLicenseId(), serverPort, OnlineStatusEnum.ONLINE.getStatus(), now);
|
||||
licenseMapper.updateOnlineStatus(attachInfo.getLicenseId(), OnlineStatusEnum.ONLINE.getStatus(), now);
|
||||
log.info("绑定服务端端口 licenseId:{},ip:{},serverPort:{}", attachInfo.getLicenseId(), attachInfo.getIp(), serverPort);
|
||||
log.info("bind server port licenseId:{},ip:{},serverPort:{}", attachInfo.getLicenseId(), attachInfo.getIp(), serverPort);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -64,7 +64,7 @@ public class ProxyMutualService {
|
||||
Date now = new Date();
|
||||
portMappingMapper.updateOnlineStatus(attachInfo.getLicenseId(), OnlineStatusEnum.OFFLINE.getStatus(), now);
|
||||
licenseMapper.updateOnlineStatus(attachInfo.getLicenseId(), OnlineStatusEnum.OFFLINE.getStatus(), now);
|
||||
log.info("客户端下线 licenseId:{},ip:{}", attachInfo.getLicenseId(), attachInfo.getIp());
|
||||
log.info("client offline licenseId:{},ip:{}", attachInfo.getLicenseId(), attachInfo.getIp());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,8 +3,10 @@ package org.dromara.neutrinoproxy.server.service;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
import org.dromara.neutrinoproxy.core.Constants;
|
||||
import org.dromara.neutrinoproxy.server.constant.EnableStatusEnum;
|
||||
import org.dromara.neutrinoproxy.server.constant.NetworkProtocolEnum;
|
||||
import org.dromara.neutrinoproxy.server.dal.LicenseMapper;
|
||||
import org.dromara.neutrinoproxy.server.dal.PortMappingMapper;
|
||||
import org.dromara.neutrinoproxy.server.dal.PortPoolMapper;
|
||||
@@ -14,7 +16,7 @@ import org.dromara.neutrinoproxy.server.dal.entity.PortMappingDO;
|
||||
import org.dromara.neutrinoproxy.server.dal.entity.PortPoolDO;
|
||||
import org.dromara.neutrinoproxy.server.dal.entity.UserDO;
|
||||
import org.dromara.neutrinoproxy.server.proxy.core.BytesMetricsHandler;
|
||||
import org.dromara.neutrinoproxy.server.proxy.core.VisitorChannelHandler;
|
||||
import org.dromara.neutrinoproxy.server.proxy.core.TcpVisitorChannelHandler;
|
||||
import org.dromara.neutrinoproxy.server.proxy.domain.CmdChannelAttachInfo;
|
||||
import org.dromara.neutrinoproxy.server.proxy.domain.ProxyMapping;
|
||||
import org.dromara.neutrinoproxy.server.util.ProxyUtil;
|
||||
@@ -41,10 +43,10 @@ import java.util.stream.Collectors;
|
||||
@Slf4j
|
||||
@Component
|
||||
public class VisitorChannelService {
|
||||
@Inject("serverBossGroup")
|
||||
private NioEventLoopGroup serverBossGroup;
|
||||
@Inject("serverWorkerGroup")
|
||||
private NioEventLoopGroup serverWorkerGroup;
|
||||
@Inject("tcpServerBootstrap")
|
||||
private ServerBootstrap tcpServerBootstrap;
|
||||
@Inject("udpServerBootstrap")
|
||||
private Bootstrap udpServerBootstrap;
|
||||
@Inject
|
||||
private ProxyMutualService proxyMutualService;
|
||||
@Db
|
||||
@@ -209,7 +211,8 @@ public class VisitorChannelService {
|
||||
if (null != proxyChannel) {
|
||||
proxyChannel.close();
|
||||
}
|
||||
visitorChannel.close();
|
||||
// TODO 此处如果时UDP的visitorChannel,则不能close,后续重构考虑
|
||||
// visitorChannel.close();
|
||||
}
|
||||
ProxyUtil.removeProxyInfo(portMappingDO.getServerPort());
|
||||
}
|
||||
@@ -218,21 +221,23 @@ public class VisitorChannelService {
|
||||
if (CollectionUtil.isEmpty(portMappingList)) {
|
||||
return;
|
||||
}
|
||||
ServerBootstrap bootstrap = new ServerBootstrap();
|
||||
bootstrap.group(serverBossGroup, serverWorkerGroup)
|
||||
.channel(NioServerSocketChannel.class).childHandler(new ChannelInitializer<SocketChannel>() {
|
||||
@Override
|
||||
public void initChannel(SocketChannel ch) throws Exception {
|
||||
ch.pipeline().addFirst(new BytesMetricsHandler());
|
||||
ch.pipeline().addLast(new VisitorChannelHandler());
|
||||
}
|
||||
});
|
||||
|
||||
for (PortMappingDO portMapping : portMappingList) {
|
||||
if (EnableStatusEnum.DISABLE.getStatus().equals(portMapping.getEnable())) {
|
||||
// 端口映射被禁用了,忽略 TODO 映射没被禁用,但端口被禁用了也需要处理
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
proxyMutualService.bindServerPort(cmdChannelAttachInfo, portMapping.getServerPort());
|
||||
bootstrap.bind(portMapping.getServerPort()).get();
|
||||
log.info("绑定用户端口: {}", portMapping.getServerPort());
|
||||
|
||||
NetworkProtocolEnum networkProtocolEnum = NetworkProtocolEnum.of(portMapping.getProtocal());
|
||||
if (networkProtocolEnum == NetworkProtocolEnum.UDP) {
|
||||
udpServerBootstrap.bind(portMapping.getServerPort()).get();
|
||||
log.info("bind UDP user port: {}", portMapping.getServerPort());
|
||||
} else {
|
||||
tcpServerBootstrap.bind(portMapping.getServerPort()).get();
|
||||
log.info("bind TCP user port: {}", portMapping.getServerPort());
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
// BindException表示该端口已经绑定过
|
||||
if (!(ex.getCause() instanceof BindException)) {
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package org.dromara.neutrinoproxy.server.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
|
||||
/**
|
||||
* 检查端口是否被占用
|
||||
* 文章参考:https://blog.csdn.net/xingluxiaoseng/article/details/40148527
|
||||
*/
|
||||
public class PortAvailableUtil {
|
||||
|
||||
private static void bindPort(String host, int port) throws IOException {
|
||||
Socket s = new Socket();
|
||||
s.bind(new InetSocketAddress(host, port));
|
||||
s.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* 端口占用判断,若是端口被占用,则会抛出IOException异常,表示端口被占用
|
||||
* @param port
|
||||
* @return
|
||||
*/
|
||||
public static boolean isPortAvailable(int port) {
|
||||
try {
|
||||
bindPort("0.0.0.0", port);
|
||||
bindPort(InetAddress.getLocalHost().getHostAddress(), port);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("端口被占用:"+isPortAvailable(9527));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import com.google.common.collect.Sets;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.dromara.neutrinoproxy.core.ChannelAttribute;
|
||||
import org.dromara.neutrinoproxy.core.Constants;
|
||||
import org.dromara.neutrinoproxy.server.constant.NetworkProtocolEnum;
|
||||
import org.dromara.neutrinoproxy.server.proxy.domain.CmdChannelAttachInfo;
|
||||
import org.dromara.neutrinoproxy.server.proxy.domain.ProxyAttachment;
|
||||
import org.dromara.neutrinoproxy.server.proxy.domain.ProxyMapping;
|
||||
@@ -63,6 +64,10 @@ public class ProxyUtil {
|
||||
* 子域名 - 服务端端口映射
|
||||
*/
|
||||
private static Map<String, Integer> subdomainToServerPort = new HashMap<>();
|
||||
/**
|
||||
* licenseId - 客户端Id映射
|
||||
*/
|
||||
private static Map<Integer, String> licenseIdToClientIdMap = new HashMap<>();
|
||||
|
||||
/**
|
||||
* 初始化代理信息
|
||||
@@ -197,18 +202,21 @@ public class ProxyUtil {
|
||||
* @param visitorId
|
||||
* @param visitorChannel
|
||||
*/
|
||||
public static void addVisitorChannelToCmdChannel(Channel cmdChannel, String visitorId, Channel visitorChannel, Integer serverPort) {
|
||||
public static void addVisitorChannelToCmdChannel(NetworkProtocolEnum protocol, Channel cmdChannel, String visitorId, Channel visitorChannel, Integer serverPort) {
|
||||
InetSocketAddress sa = (InetSocketAddress) visitorChannel.localAddress();
|
||||
String lanInfo = getClientLanInfoByServerPort(sa.getPort());
|
||||
CmdChannelAttachInfo cmdChannelAttachInfo = getAttachInfo(cmdChannel);
|
||||
|
||||
setAttachInfo(visitorChannel, new VisitorChannelAttachInfo()
|
||||
.setVisitorId(visitorId)
|
||||
.setLanInfo(lanInfo)
|
||||
.setServerPort(serverPort)
|
||||
.setLicenseId(cmdChannelAttachInfo.getLicenseId())
|
||||
.setIp(((InetSocketAddress)visitorChannel.remoteAddress()).getAddress().getHostAddress())
|
||||
);
|
||||
VisitorChannelAttachInfo attachInfo = new VisitorChannelAttachInfo()
|
||||
.setProtocol(protocol)
|
||||
.setVisitorId(visitorId)
|
||||
.setLanInfo(lanInfo)
|
||||
.setServerPort(serverPort)
|
||||
.setLicenseId(cmdChannelAttachInfo.getLicenseId());
|
||||
if (NetworkProtocolEnum.UDP != protocol) {
|
||||
attachInfo.setIp(((InetSocketAddress)visitorChannel.remoteAddress()).getAddress().getHostAddress());
|
||||
}
|
||||
setAttachInfo(visitorChannel, attachInfo);
|
||||
userChannelMapLock.writeLock().lock();
|
||||
try {
|
||||
cmdChannelAttachInfo.getVisitorChannelMap().put(visitorId, visitorChannel);
|
||||
@@ -387,4 +395,30 @@ public class ProxyUtil {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置licenseId - clientId映射
|
||||
* @param licenseId
|
||||
* @param clientId
|
||||
*/
|
||||
public static void setLicenseIdToClientIdMap(Integer licenseId, String clientId) {
|
||||
licenseIdToClientIdMap.put(licenseId, clientId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据licenseId获取clientId
|
||||
* @param licenseId
|
||||
* @return
|
||||
*/
|
||||
public static String getClientIdByLicenseId(Integer licenseId) {
|
||||
return licenseIdToClientIdMap.get(licenseId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据licenseId删除clientId
|
||||
* @param licenseId
|
||||
*/
|
||||
public static void removeClientIdByLicenseId(Integer licenseId) {
|
||||
licenseIdToClientIdMap.remove(licenseId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
server:
|
||||
# 服务端web端口,用于支持HTTP接口,管理后台页面访问
|
||||
port: ${WEB_PORT:8888}
|
||||
context-path: /neutrino-proxy-server
|
||||
|
||||
neutrino:
|
||||
proxy:
|
||||
@@ -9,25 +11,60 @@ neutrino:
|
||||
length-field-length: 4
|
||||
initial-bytes-to-strip: 0
|
||||
length-adjustment: 0
|
||||
read-idle-time: 40
|
||||
write-idle-time: 10
|
||||
read-idle-time: 120
|
||||
write-idle-time: 20
|
||||
all-idle-time-seconds: 0
|
||||
server:
|
||||
boss-thread-count: 10
|
||||
work-thread-count: 60
|
||||
logger:
|
||||
# 日志级别
|
||||
level: ${LOG_LEVEL:info}
|
||||
# 隧道相关配置-用于维持服务端与客户端的通信
|
||||
tunnel:
|
||||
# 线程池相关配置,用于技术调优,可忽略
|
||||
boss-thread-count: 2
|
||||
work-thread-count: 10
|
||||
# 隧道非SSL端口
|
||||
port: ${OPEN_PORT:9000}
|
||||
# 隧道SSL端口
|
||||
ssl-port: ${SSL_PORT:9002}
|
||||
# 隧道SSL证书配置
|
||||
key-store-password: ${STORE_PASS:123456}
|
||||
key-manager-password: ${MGR_PASS:123456}
|
||||
jks-path: ${JKS_PATH:classpath:/test.jks}
|
||||
http-proxy-port: ${HTTP_PROXY_PORT:80}
|
||||
# 如果不配置,则不支持域名映射
|
||||
domain-name: ${DOMAIN_NAME:}
|
||||
# 是否开启隧道传输报文日志(日志级别为debug时开启才有效)
|
||||
transfer-log-enable: ${TUNNEL_LOG:false}
|
||||
# 是否开启心跳日志
|
||||
heartbeat-log-enable: ${HEARTBEAT_LOG:false}
|
||||
server:
|
||||
tcp:
|
||||
# 线程池相关配置,用于技术调优,可忽略
|
||||
boss-thread-count: 5
|
||||
work-thread-count: 20
|
||||
# http代理端口,默认80
|
||||
http-proxy-port: ${HTTP_PROXY_PORT:80}
|
||||
# https代理端口,默认443 (需要配置域名、证书)
|
||||
https-proxy-port: ${HTTPS_PROXY_PORT:443}
|
||||
# 如果不配置,则不支持域名映射
|
||||
domain-name: ${DOMAIN_NAME:}
|
||||
# https证书配置
|
||||
key-store-password: ${HTTPS_STORE_PASS:}
|
||||
jks-path: ${HTTPS_JKS_PATH:}
|
||||
# 是否开启代理服务报文日志(日志级别为debug时开启才有效)
|
||||
transfer-log-enable: ${SERVER_LOG:false}
|
||||
udp:
|
||||
# 线程池相关配置,用于技术调优,可忽略
|
||||
boss-thread-count: 5
|
||||
work-thread-count: 20
|
||||
# 是否开启代理服务报文日志(日志级别为debug时开启才有效)
|
||||
transfer-log-enable: ${SERVER_LOG:false}
|
||||
data:
|
||||
db:
|
||||
# 数据库类型,目前支持sqlite、mysql、mariadb
|
||||
type: ${DB_TYPE:sqlite}
|
||||
# 数据库连接URL
|
||||
url: ${DB_URL:jdbc:sqlite:data.db}
|
||||
# 数据库用户名
|
||||
username: ${DB_USER:}
|
||||
# 数据库密码
|
||||
password: ${DB_PASSWORD:}
|
||||
|
||||
#添加MIME印射(如果有需要?)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
<property name="LOG_FILE" value="/work/projects/neutrino-proxy-server/app.log"/>
|
||||
<property name="LOG_FILE" value="./logs/neutrino-proxy-server.log"/>
|
||||
<property name="LOG_PATTERN" value="%d{yyyy-MM-dd HH:mm:ss.SSS} %contextName [%thread] %-5level %logger{50} - %msg%n"/>
|
||||
<!-- <property name="ENCODE" value="utf8" />-->
|
||||
|
||||
|
||||
@@ -32,6 +32,9 @@
|
||||
possessor_type = 0
|
||||
OR ( possessor_type = 1 AND possessor_id = #{userId,jdbcType=INTEGER} )
|
||||
OR ( possessor_type = 2 AND possessor_id = #{licenseId,jdbcType=INTEGER} )
|
||||
)
|
||||
)
|
||||
<if test="keyword!=null and keyword!=''">
|
||||
AND `port` LIKE #{keyword}
|
||||
</if>
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
@@ -0,0 +1,209 @@
|
||||
#############################系统管理相关表#############################
|
||||
#用户表
|
||||
CREATE TABLE IF NOT EXISTS `user` (
|
||||
`id` int NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`name` varchar(50) NOT NULL COMMENT '用户名',
|
||||
`login_name` varchar(50) NOT NULL COMMENT '登录名',
|
||||
`login_password` varchar(255) NOT NULL COMMENT '登录密码',
|
||||
`enable` int NOT NULL COMMENT '是否启用(1、启用 2、禁用)',
|
||||
`create_time` datetime(3) NOT NULL COMMENT '创建时间',
|
||||
`update_time` datetime(3) NOT NULL COMMENT '更新时间',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `I_user_login_name` (`login_name`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
#用户token表
|
||||
CREATE TABLE IF NOT EXISTS `user_token` (
|
||||
`id` int NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`token` varchar(50) NOT NULL COMMENT 'token',
|
||||
`user_id` int NOT NULL COMMENT '用户ID',
|
||||
`expiration_time` datetime(3) NOT NULL COMMENT '过期时间',
|
||||
`create_time` datetime(3) NOT NULL COMMENT '创建时间',
|
||||
`update_time` datetime(3) NOT NULL COMMENT '更新时间',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `I_user_token_user_id` (`user_id`),
|
||||
KEY `I_user_token_token` (`token`),
|
||||
KEY `I_user_token_expiration_time` (`expiration_time`) USING BTREE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
#端口池
|
||||
CREATE TABLE IF NOT EXISTS `port_pool` (
|
||||
`id` int NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`group_id` int NOT NULL DEFAULT 1 COMMENT '分组ID',
|
||||
`port` int NOT NULL COMMENT '端口',
|
||||
`enable` int NOT NULL COMMENT '是否启用(1、启用 2、禁用)',
|
||||
`create_time` datetime(3) NOT NULL COMMENT '创建时间',
|
||||
`update_time` datetime(3) NOT NULL COMMENT '更新时间',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `I_port_pool_port` (`port`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
#端口分组
|
||||
CREATE TABLE IF NOT EXISTS `port_group` (
|
||||
`id` int NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`name` varchar(255) NOT NULL COMMENT '分组名称',
|
||||
`possessor_type` int NOT NULL DEFAULT '0' COMMENT '所有者类型 (0、全局共享 1、用户所有 2License所有) ',
|
||||
`possessor_id` int NOT NULL DEFAULT '-1' COMMENT '所有者id(当type为0时 固定为-1、当type为1时为用户id 、当type为2时为licenseid)',
|
||||
`enable` int NOT NULL COMMENT '是否启用(1、启用 2、禁用)',
|
||||
`create_time` datetime(3) NOT NULL COMMENT '创建时间',
|
||||
`update_time` datetime(3) NOT NULL COMMENT '更新时间',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
#############################代理配置相关表#############################
|
||||
#license表
|
||||
CREATE TABLE IF NOT EXISTS `license` (
|
||||
`id` int NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`name` varchar(50) NOT NULL COMMENT 'license名称',
|
||||
`key` varchar(100) NOT NULL COMMENT 'license key',
|
||||
`user_id` int NOT NULL COMMENT '用户ID',
|
||||
`is_online` int NOT NULL COMMENT '是否在线(1、在线 2、离线)',
|
||||
`enable` int NOT NULL COMMENT '是否启用(1、启用 2、禁用)',
|
||||
`create_time` datetime(3) NOT NULL COMMENT '创建时间',
|
||||
`update_time` datetime(3) NOT NULL COMMENT '更新时间',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
KEY `I_license_key` (`key`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
#端口映射表
|
||||
CREATE TABLE IF NOT EXISTS `port_mapping` (
|
||||
`id` int NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`license_id` int NOT NULL COMMENT 'licenseID',
|
||||
`protocal` varchar(10) NOT NULL DEFAULT 'TCP' COMMENT '协议',
|
||||
`subdomain` varchar(50) DEFAULT NULL COMMENT '子域名(仅HTTP时有效)',
|
||||
`server_port` int NOT NULL COMMENT '服务端端口',
|
||||
`client_ip` varchar(20) NOT NULL COMMENT '客户端IP',
|
||||
`client_port` int NOT NULL COMMENT '客户端端口',
|
||||
`is_online` int NOT NULL COMMENT '是否在线(1、在线 2、离线)',
|
||||
`description` varchar(100) DEFAULT NULL COMMENT '描述',
|
||||
`proxy_responses` int NOT NULL DEFAULT 0 COMMENT '代理响应数据包数量',
|
||||
`proxy_timeout_ms` int NOT NULL DEFAULT 0 COMMENT '代理超时毫秒数',
|
||||
`enable` int NOT NULL COMMENT '是否启用(1、启用 2、禁用)',
|
||||
`create_time` datetime(3) NOT NULL COMMENT '创建时间',
|
||||
`update_time` datetime(3) NOT NULL COMMENT '更新时间',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `I_port_mapping_server_port` (`server_port`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
#############################日志管理相关表#############################
|
||||
#用户登录记录表
|
||||
CREATE TABLE IF NOT EXISTS `user_login_record` (
|
||||
`id` int NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`user_id` int NOT NULL COMMENT '用户ID',
|
||||
`ip` varchar(50) NOT NULL COMMENT 'IP',
|
||||
`token` varchar(100) NOT NULL COMMENT 'token',
|
||||
`type` int NOT NULL COMMENT '类型(1、登录 2、登出)',
|
||||
`create_time` datetime(3) NOT NULL COMMENT '创建时间',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
#客户端连接记录表
|
||||
CREATE TABLE IF NOT EXISTS `client_connect_record` (
|
||||
`id` int NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`ip` varchar(50) NOT NULL COMMENT 'IP',
|
||||
`license_id` int NOT NULL COMMENT 'licenseId',
|
||||
`type` int NOT NULL COMMENT '类型(1、连接 2、断开连接)',
|
||||
`msg` varchar(512) DEFAULT NULL COMMENT '消息',
|
||||
`code` int NOT NULL COMMENT '结果 (1、成功 2、失败)',
|
||||
`err` text DEFAULT NULL COMMENT '异常信息',
|
||||
`create_time` datetime(3) NOT NULL COMMENT '创建时间',
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
#############################调度管理相关表#############################
|
||||
#触发器信息表
|
||||
CREATE TABLE IF NOT EXISTS `job_info` (
|
||||
`id` int NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`desc` varchar(255) NOT NULL COMMENT '描述',
|
||||
`handler` varchar(255) NOT NULL COMMENT '处理器',
|
||||
`cron` varchar(128) NOT NULL COMMENT 'cron',
|
||||
`param` varchar(512) DEFAULT NULL COMMENT '参数',
|
||||
`alarm_email` varchar(255) DEFAULT NULL COMMENT '报警邮箱',
|
||||
`alarm_ding` varchar(255) DEFAULT NULL COMMENT '报警钉钉配置',
|
||||
`enable` int NOT NULL COMMENT '是否启用(1、启用 2、禁用)',
|
||||
`create_time` datetime(3) NOT NULL COMMENT '创建时间',
|
||||
`update_time` datetime(3) NOT NULL COMMENT '更新时间',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `I_job_info_handler` (`handler`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
#触发器日志表
|
||||
CREATE TABLE IF NOT EXISTS `job_log` (
|
||||
`id` int NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`job_id` int NOT NULL COMMENT 'JobId',
|
||||
`handler` varchar(255) NOT NULL COMMENT '处理器',
|
||||
`param` varchar(512) DEFAULT NULL COMMENT '参数',
|
||||
`code` int NOT NULL COMMENT '结果(1、成功 2、失败)',
|
||||
`msg` text COMMENT '消息',
|
||||
`alarm_status` int NOT NULL COMMENT '报警状态(1、未报警 2、已报警)',
|
||||
`create_time` datetime(3) NOT NULL COMMENT '创建时间',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
KEY `I_job_log_create_time` (`create_time`) USING BTREE,
|
||||
KEY `I_job_log_code` (`code`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
#############################报表管理相关表#############################
|
||||
#流量统计报表-分钟(保留24小时)
|
||||
CREATE TABLE IF NOT EXISTS `flow_report_minute` (
|
||||
`id` int NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`user_id` int NOT NULL COMMENT '用户ID',
|
||||
`license_id` int NOT NULL COMMENT 'licenseId',
|
||||
`write_bytes` int NOT NULL COMMENT '写入流量',
|
||||
`read_bytes` int NOT NULL COMMENT '读取流量',
|
||||
`date` datetime(3) NOT NULL COMMENT '时间',
|
||||
`date_str` varchar(20) NOT NULL COMMENT '时间 yyyy-MM-dd HH:mm',
|
||||
`create_time` datetime(3) NOT NULL COMMENT '创建时间',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `I_flow_report_minute_create_time` (`create_time`) USING BTREE,
|
||||
KEY `I_flow_report_minute_date` (`date`) USING BTREE,
|
||||
KEY `I_flow_report_minute_user_id` (`user_id`),
|
||||
KEY `I_flow_report_minute_license_id` (`license_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
#流量统计报表-小时(保留60天)
|
||||
CREATE TABLE IF NOT EXISTS `flow_report_hour` (
|
||||
`id` int NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`user_id` int NOT NULL COMMENT '用户ID',
|
||||
`license_id` int NOT NULL COMMENT 'licenseId',
|
||||
`write_bytes` int NOT NULL COMMENT '写入流量',
|
||||
`read_bytes` int NOT NULL COMMENT '读取流量',
|
||||
`date` datetime(3) NOT NULL COMMENT '时间',
|
||||
`date_str` varchar(20) NOT NULL COMMENT '时间 yyyy-MM-dd HH',
|
||||
`create_time` datetime(3) NOT NULL COMMENT '创建时间',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `I_flow_report_hour_create_time` (`create_time`) USING BTREE,
|
||||
KEY `I_flow_report_hour_date` (`date`) USING BTREE,
|
||||
KEY `I_flow_report_hour_user_id` (`user_id`),
|
||||
KEY `I_flow_report_hour_license_id` (`license_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
#流量统计报表-天(保留1年)
|
||||
CREATE TABLE IF NOT EXISTS `flow_report_day` (
|
||||
`id` int NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`user_id` int NOT NULL COMMENT '用户ID',
|
||||
`license_id` int NOT NULL COMMENT 'licenseId',
|
||||
`write_bytes` int NOT NULL COMMENT '写入流量',
|
||||
`read_bytes` int NOT NULL COMMENT '读取流量',
|
||||
`date` datetime(3) NOT NULL COMMENT '时间',
|
||||
`date_str` varchar(20) NOT NULL COMMENT '时间 yyyy-MM-dd',
|
||||
`create_time` datetime(3) NOT NULL COMMENT '创建时间',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `I_flow_report_day_create_time` (`create_time`) USING BTREE,
|
||||
KEY `I_flow_report_day_date` (`date`) USING BTREE,
|
||||
KEY `I_flow_report_day_user_id` (`user_id`),
|
||||
KEY `I_flow_report_day_license_id` (`license_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
#流量统计报表-月(全量保留)
|
||||
CREATE TABLE IF NOT EXISTS `flow_report_month` (
|
||||
`id` int NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`user_id` int NOT NULL COMMENT '用户ID',
|
||||
`license_id` int NOT NULL COMMENT 'licenseId',
|
||||
`write_bytes` int NOT NULL COMMENT '写入流量',
|
||||
`read_bytes` int NOT NULL COMMENT '读取流量',
|
||||
`date` datetime(3) NOT NULL COMMENT '时间',
|
||||
`date_str` varchar(20) NOT NULL COMMENT '时间 yyyy-MM',
|
||||
`create_time` datetime(3) NOT NULL COMMENT '创建时间',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `I_flow_report_month_create_time` (`create_time`) USING BTREE,
|
||||
KEY `I_flow_report_month_date` (`date`) USING BTREE,
|
||||
KEY `I_flow_report_month_user_id` (`user_id`),
|
||||
KEY `I_flow_report_month_license_id` (`license_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
@@ -0,0 +1,13 @@
|
||||
#job_qrtz_trigger_info
|
||||
INSERT INTO job_info(`id`, `desc`, `handler`, `cron`, `param`, `enable`, `create_time`, `update_time`) VALUES
|
||||
(1, '示例Job', 'DemoJob', '0/10 * * * * ?', '{"a":101}', 1, now(), now());
|
||||
INSERT INTO job_info(`id`, `desc`, `handler`, `cron`, `param`, `enable`, `create_time`, `update_time`) VALUES
|
||||
(2, '数据清理任务', 'DataCleanJob', '0 0 1 * * ?', '', 1, now(), now());
|
||||
INSERT INTO job_info(`id`, `desc`, `handler`, `cron`, `param`, `enable`, `create_time`, `update_time`) VALUES
|
||||
(3, '流量统计报表-分钟', 'FlowReportForMinuteJob', '0 */1 * * * ?', '', 1, now(), now());
|
||||
INSERT INTO job_info(`id`, `desc`, `handler`, `cron`, `param`, `enable`, `create_time`, `update_time`) VALUES
|
||||
(4, '流量统计报表-小时', 'FlowReportForHourJob', '0 0 */1 * * ?', '', 1, now(), now());
|
||||
INSERT INTO job_info(`id`, `desc`, `handler`, `cron`, `param`, `enable`, `create_time`, `update_time`) VALUES
|
||||
(5, '流量统计报表-天', 'FlowReportForDayJob', '0 0 1 * * ?', '', 1, now(), now());
|
||||
INSERT INTO job_info(`id`, `desc`, `handler`, `cron`, `param`, `enable`, `create_time`, `update_time`) VALUES
|
||||
(6, '流量统计报表-月', 'FlowReportForMonthJob', '0 30 1 1 * ?', '', 1, now(), now());
|
||||
@@ -0,0 +1,3 @@
|
||||
#license
|
||||
INSERT INTO license(`id`, `name`, `key`, `user_id`, `is_online`, `enable`, `create_time`, `update_time`) VALUES
|
||||
(1, '我的mac', 'b0a907332b474b25897c4dcb31fc7eb6', 1, 2, 1, now(), now());
|
||||
@@ -0,0 +1,3 @@
|
||||
#port_group
|
||||
INSERT INTO `port_group`(`id`,`name`,`possessor_type`,`possessor_id`,`enable`,`create_time`,`update_time`) VALUES
|
||||
(1, '全局(默认)', 0, -1, 1, now(), now());
|
||||
@@ -0,0 +1,7 @@
|
||||
#port_mapping
|
||||
INSERT INTO port_mapping(`id`, `license_id`, `server_port`, `protocal`, `subdomain`, `client_ip`, `client_port`, `is_online`, `enable`, `create_time`, `update_time`) VALUES
|
||||
(1, 1, 9101, 'HTTP', 'test1', '127.0.0.1', 8080, 2, 1, now(), now());
|
||||
INSERT INTO port_mapping(`id`, `license_id`, `server_port`, `protocal`, `subdomain`, `client_ip`, `client_port`, `is_online`, `enable`, `create_time`, `update_time`) VALUES
|
||||
(2, 1, 9102, 'TCP', '', '127.0.0.1', 3306, 2, 1, now(), now());
|
||||
INSERT INTO port_mapping(`id`, `license_id`, `server_port`, `protocal`, `subdomain`, `client_ip`, `client_port`, `is_online`, `enable`, `create_time`, `update_time`) VALUES
|
||||
(3, 1, 9103, 'HTTP', 'test2', '127.0.0.1', 8081, 2, 1, now(), now());
|
||||
@@ -0,0 +1,41 @@
|
||||
#端口池
|
||||
INSERT INTO port_pool(`id`, `group_id`, `port`, `enable`, `create_time`, `update_time`) VALUES
|
||||
(1, 1, 9101, 1, now(), now());
|
||||
INSERT INTO port_pool(`id`, `group_id`, `port`, `enable`, `create_time`, `update_time`) VALUES
|
||||
(2, 1, 9102, 1, now(), now());
|
||||
INSERT INTO port_pool(`id`, `group_id`, `port`, `enable`, `create_time`, `update_time`) VALUES
|
||||
(3, 1, 9103, 1, now(), now());
|
||||
INSERT INTO port_pool(`id`, `group_id`, `port`, `enable`, `create_time`, `update_time`) VALUES
|
||||
(4, 1, 9104, 1, now(), now());
|
||||
INSERT INTO port_pool(`id`, `group_id`, `port`, `enable`, `create_time`, `update_time`) VALUES
|
||||
(5, 1, 9105, 1, now(), now());
|
||||
INSERT INTO port_pool(`id`, `group_id`, `port`, `enable`, `create_time`, `update_time`) VALUES
|
||||
(6, 1, 9106, 1, now(), now());
|
||||
INSERT INTO port_pool(`id`, `group_id`, `port`, `enable`, `create_time`, `update_time`) VALUES
|
||||
(7, 1, 9107, 1, now(), now());
|
||||
INSERT INTO port_pool(`id`, `group_id`, `port`, `enable`, `create_time`, `update_time`) VALUES
|
||||
(8, 1, 9108, 1, now(), now());
|
||||
INSERT INTO port_pool(`id`, `group_id`, `port`, `enable`, `create_time`, `update_time`) VALUES
|
||||
(9, 1, 9109, 1, now(), now());
|
||||
INSERT INTO port_pool(`id`, `group_id`, `port`, `enable`, `create_time`, `update_time`) VALUES
|
||||
(10, 1, 9110, 1, now(), now());
|
||||
INSERT INTO port_pool(`id`, `group_id`, `port`, `enable`, `create_time`, `update_time`) VALUES
|
||||
(11, 1, 9111, 1, now(), now());
|
||||
INSERT INTO port_pool(`id`, `group_id`, `port`, `enable`, `create_time`, `update_time`) VALUES
|
||||
(12, 1, 9112, 1, now(), now());
|
||||
INSERT INTO port_pool(`id`, `group_id`, `port`, `enable`, `create_time`, `update_time`) VALUES
|
||||
(13, 1, 9113, 1, now(), now());
|
||||
INSERT INTO port_pool(`id`, `group_id`, `port`, `enable`, `create_time`, `update_time`) VALUES
|
||||
(14, 1, 9114, 1, now(), now());
|
||||
INSERT INTO port_pool(`id`, `group_id`, `port`, `enable`, `create_time`, `update_time`) VALUES
|
||||
(15, 1, 9115, 1, now(), now());
|
||||
INSERT INTO port_pool(`id`, `group_id`, `port`, `enable`, `create_time`, `update_time`) VALUES
|
||||
(16, 1, 9116, 1, now(), now());
|
||||
INSERT INTO port_pool(`id`, `group_id`, `port`, `enable`, `create_time`, `update_time`) VALUES
|
||||
(17, 1, 9117, 1, now(), now());
|
||||
INSERT INTO port_pool(`id`, `group_id`, `port`, `enable`, `create_time`, `update_time`) VALUES
|
||||
(18, 1, 9118, 1, now(), now());
|
||||
INSERT INTO port_pool(`id`, `group_id`, `port`, `enable`, `create_time`, `update_time`) VALUES
|
||||
(19, 1, 9119, 1, now(), now());
|
||||
INSERT INTO port_pool(`id`, `group_id`, `port`, `enable`, `create_time`, `update_time`) VALUES
|
||||
(20, 1, 9120, 1, now(), now());
|
||||
@@ -0,0 +1,5 @@
|
||||
#用户表 6613b92b77056faeb72068f184ed4c4f
|
||||
INSERT INTO `user`(`id`, `name`,`login_name`,`login_password`,`enable`,`create_time`, `update_time`) VALUES
|
||||
(1, '管理员', 'admin', 'e10adc3949ba59abbe56e057f20f883e', 1, now(), now());
|
||||
INSERT INTO `user`(`id`, `name`,`login_name`,`login_password`,`enable`,`create_time`, `update_time`) VALUES
|
||||
(2, '游客', 'visitor', 'e10adc3949ba59abbe56e057f20f883e', 1, now(), now());
|
||||
@@ -76,6 +76,8 @@ CREATE TABLE IF NOT EXISTS `port_mapping` (
|
||||
`client_port` int NOT NULL COMMENT '客户端端口',
|
||||
`is_online` int NOT NULL COMMENT '是否在线(1、在线 2、离线)',
|
||||
`description` varchar(100) DEFAULT NULL COMMENT '描述',
|
||||
`proxy_responses` int NOT NULL DEFAULT 0 COMMENT '代理响应数据包数量',
|
||||
`proxy_timeout_ms` int NOT NULL DEFAULT 0 COMMENT '代理超时毫秒数',
|
||||
`enable` int NOT NULL COMMENT '是否启用(1、启用 2、禁用)',
|
||||
`create_time` datetime(3) NOT NULL COMMENT '创建时间',
|
||||
`update_time` datetime(3) NOT NULL COMMENT '更新时间',
|
||||
@@ -204,4 +206,4 @@ CREATE TABLE IF NOT EXISTS `flow_report_month` (
|
||||
KEY `I_flow_report_month_date` (`date`) USING BTREE,
|
||||
KEY `I_flow_report_month_user_id` (`user_id`),
|
||||
KEY `I_flow_report_month_license_id` (`license_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
ALTER TABLE port_mapping ADD `proxy_responses` int NOT NULL DEFAULT 0 COMMENT '代理响应数据包数量';
|
||||
ALTER TABLE port_mapping ADD `proxy_timeout_ms` int NOT NULL DEFAULT 0 COMMENT '代理超时毫秒数';
|
||||
@@ -70,6 +70,8 @@ CREATE TABLE IF NOT EXISTS `port_mapping` (
|
||||
`client_port` INTEGER NOT NULL,
|
||||
`is_online` INTEGER(2) NOT NULL,
|
||||
`description` VARCHAR(100) DEFAULT NULL,
|
||||
`proxy_responses` INTEGER(20) NOT NULL DEFAULT 0,
|
||||
`proxy_timeout_ms` INTEGER(20) NOT NULL DEFAULT 0,
|
||||
`enable` INTEGER(2) NOT NULL,
|
||||
`create_time` INTEGER(20) NOT NULL,
|
||||
`update_time` INTEGER(20) NOT NULL
|
||||
@@ -190,4 +192,4 @@ CREATE TABLE IF NOT EXISTS `flow_report_month` (
|
||||
CREATE INDEX IF NOT EXISTS I_flow_report_month_create_time ON flow_report_month(create_time);
|
||||
CREATE INDEX IF NOT EXISTS I_flow_report_month_date ON flow_report_month(`date`);
|
||||
CREATE INDEX IF NOT EXISTS I_flow_report_month_user_id ON flow_report_month(`user_id`);
|
||||
CREATE INDEX IF NOT EXISTS I_flow_report_month_license_id ON flow_report_month(`license_id`);
|
||||
CREATE INDEX IF NOT EXISTS I_flow_report_month_license_id ON flow_report_month(`license_id`);
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
ALTER TABLE port_mapping ADD `proxy_responses` INTEGER(20) NOT NULL DEFAULT 0;
|
||||
ALTER TABLE port_mapping ADD `proxy_timeout_ms` INTEGER(20) NOT NULL DEFAULT 0;
|
||||
|
After Width: | Height: | Size: 4.9 KiB |
|
After Width: | Height: | Size: 47 KiB |
@@ -7,7 +7,7 @@ article: false
|
||||
|
||||
## 1、 部署服务端
|
||||
### 1.1、 Docker一键部署
|
||||
> 当前最新版本为1.8.0,下面的脚本中,可以使用:`registry.cn-hangzhou.aliyuncs.com/asgc/neutrino-proxy:1.8.0` 指定版本安装,推荐使用`latest`直接安装最新版。
|
||||
> 当前最新版本为1.9.0,下面的脚本中,可以使用:`registry.cn-hangzhou.aliyuncs.com/asgc/neutrino-proxy:1.9.0` 指定版本安装,推荐使用`latest`直接安装最新版。
|
||||
|
||||
#### 使用默认sqlite数据库
|
||||
```shell
|
||||
@@ -46,9 +46,9 @@ registry.cn-hangzhou.aliyuncs.com/asgc/neutrino-proxy:latest
|
||||
- 在服务器上新建部署目录:`/work/projects/neutrino-proxy-server`
|
||||
- 将` neutrino-proxy-server.jar`、`neutrino-proxy-admin.zip`上传至服务器部署目录。
|
||||
- 解压`neutrino-proxy-admin.zip`文件
|
||||
- 执行命令`java -jar neutrino-proxy-server.jar`启动服务端完成部署,默认使用sqlite数据库。
|
||||
- 若需要指定自己的mysql数据库,同样的需要在当前目录下新建`app.yml`文件,文件内容同上。执行命令`java -jar neutrino-proxy-server.jar config=app.yml`启动服务端完成部署
|
||||
- 可参照 https://gitee.com/dromara/neutrino-proxy/blob/master/bin/server_start.sh 使用shell脚本启动服务端。
|
||||
- 执行命令`java -Dfile.encoding=utf-8 -jar neutrino-proxy-server.jar`启动服务端完成部署,默认使用sqlite数据库。
|
||||
- 若需要指定自己的mysql数据库,同样的需要在当前目录下新建`app.yml`文件,文件内容同上。执行命令`java -Dfile.encoding=utf-8 -jar neutrino-proxy-server.jar config=app.yml`启动服务端完成部署
|
||||
- 可参照 https://gitee.com/dromara/neutrino-proxy/blob/master/scripts/unix/server_start.sh 使用shell脚本启动服务端。
|
||||
|
||||
## 2、管理后台配置
|
||||
- 服务端部署成功后,访问`http://{服务端IP}:8888`打开后台管理页面。
|
||||
@@ -63,7 +63,7 @@ registry.cn-hangzhou.aliyuncs.com/asgc/neutrino-proxy:latest
|
||||
```yml
|
||||
neutrino:
|
||||
proxy:
|
||||
client:
|
||||
tunnel:
|
||||
# ssl证书密钥(使用jjar包内自带的证书,则此处无需修改)
|
||||
key-store-password: 123456
|
||||
# ssl证书管理密钥(使用jjar包内自带的证书,则此处无需修改。自定义证书,则此处配置对应的路径)
|
||||
@@ -87,6 +87,11 @@ neutrino:
|
||||
|
||||
访问成功,至此首次完整的内网穿透体验完成。开源不易,请速至[Gitee仓库](https://gitee.com/dromara/neutrino-proxy)一键三连🤝
|
||||
|
||||
## 5、客户端Docker部署
|
||||
> 因为一些原因,官方不推荐客户端使用Docker方式部署,但有不少朋友希望采用这种方式,因此从1.9.0版本开始维护了客户端镜像,版本号同服务端,也可使用`latest`直接安装最新版。
|
||||
- 客户端镜像地址:registry.cn-hangzhou.aliyuncs.com/asgc/neutrino-proxy-client:latest
|
||||
- 注意:客户端采用docker部署时,服务端端口映射客户端ip请不要配置127.0.0.1应该配置为容器访问宿主机的ip或者hostname,具体请自行百度
|
||||
|
||||
<!--
|
||||
## 4.开发&调试
|
||||
|
||||
@@ -115,4 +120,4 @@ module.exports = {
|
||||
}
|
||||
```
|
||||
:::
|
||||
-->
|
||||
-->
|
||||
|
||||
@@ -35,3 +35,28 @@ permalink: /pages/269a2e/
|
||||
# 所有的代理映射都能绑定域名吗?
|
||||
不行的。之所以能实现域名绑定,原因是HTTP请求附带了Host请求头,包含了请求的域名信息,代理服务端能根据请求的域名做分发。而TCP协议本身并不包含域名,因此无法实现。
|
||||
所以,目前只有HTTP(涵盖HTTPS)协议能支持。
|
||||
|
||||
# 代理服务端使用非80端口时,nginx配置示例
|
||||
```
|
||||
server {
|
||||
listen 80;
|
||||
# 此处配不配貌似不影响
|
||||
server_name localhost *.neutrino-proxy.asgc.fun;
|
||||
|
||||
location / {
|
||||
if ($http_host ~* "(.*?).neutrino-proxy.asgc.fun") {
|
||||
# 转发到代理服务端HTTP代理端口
|
||||
proxy_pass http://localhost:8899;
|
||||
}
|
||||
|
||||
tcp_nodelay on;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
#以上三行,目的是将代理服务器收到的用户的信息传到真实服务器上
|
||||
|
||||
root html;
|
||||
index index.html index.htm;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
---
|
||||
title: HTTPS配置
|
||||
date: 2023-05-27 11:40:12
|
||||
permalink: /pages/99a300/
|
||||
---
|
||||
|
||||
## 基础说明
|
||||
- 在中微子代理中,HTTP的定位是:为ip+端口的访问形式增加域名访问的支持。因此:
|
||||
- 如果端口映射正确配置了域名,那么该映射同时支持IP+端口、域名2种访问形式。
|
||||
- 如果端口映射未配置域名,那么只能以ip+端口的形式访问,此时等价于选择TCP协议。
|
||||
|
||||
- 在中微子代理中,HTTPS作为HTTP的一种增强行为,不作为一个单独的协议。因此:
|
||||
- 在端口映射中只需要选择HTTP即可
|
||||
- 若端口映射未正确配置域名,那么同理,此时等价于选择TCP协议。
|
||||
- 若端口映射配置了域名,但是未正确配置HTTPS端口、证书,那么此时可以通过域名访问,但不支持HTTPS
|
||||
- 若端口映射配置了域名,且正确配置了HTTPS端口、证书,那么此时可以通过IP+端口、http域名、https域名3种形式访问
|
||||
|
||||
|
||||
## HTTPS配置流程
|
||||
- 按照域名映射流程,完成域名的配置
|
||||
- 在服务端配置域名的HTTPS证书信息(此处应该是通配符证书)
|
||||
|
||||
## HTTPS端口问题
|
||||
- 与HTTP类似,HTTPS也有一个默认端口:443,默认情况下需要占用服务端443端口
|
||||
- 如果代理服务端不能独占443端口,此处可以指定任意端口,但需要在nginx中配置443端口的转发规则。此处与域名映射中代理服务端不使用80端口的情况类似
|
||||
@@ -0,0 +1,72 @@
|
||||
---
|
||||
title: 服务端配置
|
||||
date: 2023-05-27 11:41:44
|
||||
permalink: /pages/f2d0f1/
|
||||
---
|
||||
|
||||
::: tip
|
||||
|
||||
1.9.0版本,服务端配置格式有所调整。从之前的版本升级的,需要注意
|
||||
|
||||
:::
|
||||
|
||||
|
||||
# 以下是最新的服务端配置格式(app.yml)
|
||||
```yml
|
||||
server:
|
||||
# 服务端web端口,用于支持HTTP接口,管理后台页面访问
|
||||
port: ${WEB_PORT:8888}
|
||||
|
||||
neutrino:
|
||||
proxy:
|
||||
logger:
|
||||
# 日志级别
|
||||
level: ${LOG_LEVEL:info}
|
||||
# 隧道相关配置-用于维持服务端与客户端的通信
|
||||
tunnel:
|
||||
# 线程池相关配置,用于技术调优,可忽略
|
||||
boss-thread-count: 2
|
||||
work-thread-count: 10
|
||||
# 隧道非SSL端口
|
||||
port: ${OPEN_PORT:9000}
|
||||
# 隧道SSL端口
|
||||
ssl-port: ${SSL_PORT:9002}
|
||||
# 隧道SSL证书配置
|
||||
key-store-password: ${STORE_PASS:123456}
|
||||
key-manager-password: ${MGR_PASS:123456}
|
||||
jks-path: ${JKS_PATH:classpath:/test.jks}
|
||||
# 是否开启隧道传输报文日志(日志级别为debug时开启才有效)
|
||||
transfer-log-enable: ${TUNNEL_LOG:false}
|
||||
server:
|
||||
tcp:
|
||||
# 线程池相关配置,用于技术调优,可忽略
|
||||
boss-thread-count: 5
|
||||
work-thread-count: 20
|
||||
# http代理端口,默认80
|
||||
http-proxy-port: ${HTTP_PROXY_PORT:80}
|
||||
# https代理端口,默认443 (需要配置域名、证书)
|
||||
https-proxy-port: ${HTTPS_PROXY_PORT:443}
|
||||
# 如果不配置,则不支持域名映射
|
||||
domain-name: ${DOMAIN_NAME:}
|
||||
# https证书配置
|
||||
key-store-password: ${HTTPS_STORE_PASS:}
|
||||
jks-path: ${HTTPS_JKS_PATH:}
|
||||
# 是否开启代理服务报文日志(日志级别为debug时开启才有效)
|
||||
transfer-log-enable: ${SERVER_LOG:false}
|
||||
udp:
|
||||
# 线程池相关配置,用于技术调优,可忽略
|
||||
boss-thread-count: 5
|
||||
work-thread-count: 20
|
||||
# 是否开启代理服务报文日志(日志级别为debug时开启才有效)
|
||||
transfer-log-enable: ${SERVER_LOG:false}
|
||||
data:
|
||||
db:
|
||||
# 数据库类型,目前支持sqlite、mysql、mariadb
|
||||
type: ${DB_TYPE:sqlite}
|
||||
# 数据库连接URL
|
||||
url: ${DB_URL:jdbc:sqlite:data.db}
|
||||
# 数据库用户名
|
||||
username: ${DB_USER:}
|
||||
# 数据库密码
|
||||
password: ${DB_PASSWORD:}
|
||||
```
|
||||
@@ -0,0 +1,53 @@
|
||||
---
|
||||
title: 客户端配置
|
||||
date: 2023-06-09 21:15:35
|
||||
permalink: /pages/50ce10/
|
||||
---
|
||||
|
||||
::: tip
|
||||
|
||||
1.9.0版本,客户端配置格式有所调整。从之前的版本升级的,需要注意
|
||||
|
||||
:::
|
||||
|
||||
# 以下是最新的客户端配置格式(app.yml)
|
||||
```yml
|
||||
neutrino:
|
||||
proxy:
|
||||
logger:
|
||||
# 日志级别
|
||||
level: ${LOG_LEVEL:info}
|
||||
tunnel:
|
||||
# 线程池相关配置,用于技术调优,可忽略
|
||||
thread-count: 50
|
||||
# 隧道SSL证书配置
|
||||
key-store-password: ${STORE_PASS:123456}
|
||||
jks-path: ${JKS_PATH:classpath:/test.jks}
|
||||
# 服务端IP
|
||||
server-ip: ${SERVER_IP:localhost}
|
||||
# 服务端端口(对应服务端app.yml中的tunnel.port、tunnel.ssl-port)
|
||||
server-port: ${SERVER_PORT:9002}
|
||||
# 是否启用SSL(注意:该配置必须和server-port对应上)
|
||||
ssl-enable: ${SSL_ENABLE:true}
|
||||
# 客户端连接唯一凭证
|
||||
license-key: ${LICENSE_KEY:}
|
||||
# 客户端唯一身份标识(可忽略,若不设置首次启动会自动生成)
|
||||
client-id: ${CLIENT_ID:}
|
||||
# 是否开启隧道传输报文日志(日志级别为debug时开启才有效)
|
||||
transfer-log-enable: ${CLIENT_LOG:false}
|
||||
# 重连设置
|
||||
reconnection:
|
||||
# 重连间隔(秒)
|
||||
interval-seconds: 10
|
||||
# 是否开启无限重连(未开启时,客户端license不合法会自动停止应用,开启了则不会,请谨慎开启)
|
||||
unlimited: false
|
||||
client:
|
||||
udp:
|
||||
# 线程池相关配置,用于技术调优,可忽略
|
||||
boss-thread-count: 5
|
||||
work-thread-count: 20
|
||||
# udp傀儡端口范围
|
||||
puppet-port-range: 10000-10500
|
||||
# 是否开启隧道传输报文日志(日志级别为debug时开启才有效)
|
||||
transfer-log-enable: ${CLIENT_LOG:false}
|
||||
```
|
||||
@@ -0,0 +1,31 @@
|
||||
---
|
||||
title: 常见问题汇总
|
||||
date: 2023-07-01 13:35:00
|
||||
permalink: /pages/a00001/
|
||||
---
|
||||
|
||||
## 1、客户端启动后连不上服务端,一直在重连
|
||||
### 1.1、启动日志包含`not found license-key config`相关字样
|
||||
出现这种情况,说明客户端没获取到配置的license,可按如下检查:
|
||||
- 客户端是否有配置app.yml,app.yml中是否有配置`license-key`
|
||||
- 客户端启动参数是否指定app.yml配置,若未指定客户端不会加载任何jar外部的配置文件
|
||||
- 客户端启动参数指定的配置文件路径是否正确?如:`java -jar neutrino-proxy-client.jar config=app.yml`,代表`app.yml`文件与jar在同级别目录下,如果不在同级别目录,请使用绝对/相对路径指定
|
||||
- 除此之外license还可以用以下方法直接在启动参数中指定:
|
||||
- `java -jar -DLICENSE_KEY=xxxx -DSERVER_IP=x.x.x.x -DSERVER_PORT=9000 -DSSL_ENABLE=false neutrino-proxy-client.jar`
|
||||
- `java -jar neutrino-proxy-client.jar serverIp=x.x.x.x serverPort=9000 sslEnable=false licenseKey=xxxx`
|
||||
|
||||
### 1.2、配置文件确定都已经配置,且启动参数正确指定了,但是没有出现`认证成功日志`
|
||||
- 确认客户端配置的`server-ip`,必须是服务端所在机器的ip,且保证客户端所在机器能正常ping通
|
||||
- 确认客户端配置的`server-port`与`ssl-enable`,默认情况应配置为9000、false或9002、true,除非服务端app.yml有改动隧道对外端口
|
||||
- 确认服务端对外的9000、9002端口是否已经放开
|
||||
- 服务端如果采用docker部署,需要确保容器的9000、9002端口映射到宿主机
|
||||
|
||||
## 2、关于中微子代理涉及的2类SSL证书
|
||||
### 2.1、HTTPS证书
|
||||
该证书用于服务端支持HTTPS,若需要在服务端`app.yml`中配置即可
|
||||
|
||||
### 2.2、隧道SSL证书
|
||||
该证书用于对客户端-服务端之间的数据通信进行加密,因此客户端/服务端均需要配置该证书。可参考如下命令生成:
|
||||
```
|
||||
keytool -genkey -alias test1 -keyalg RSA -keysize 1024 -validity 3650 -keypass 123456 -storepass 123456 -keystore "./test.jks"
|
||||
```
|
||||
@@ -6,8 +6,10 @@ article: false
|
||||
---
|
||||
|
||||
### 演示环境
|
||||
> 由于部分用户使用演示环境代理非法网站导致演示环境服务器被封禁,因此不再提供演示服务。
|
||||
|
||||
可使用分配好的游客license试用。服务器带宽较低,仅供学习使用!
|
||||
|
||||
管理后台地址:<a href="http://103.163.47.16:9527" target="_blank">http://103.163.47.16:9527</a>
|
||||
|
||||
游客账号:visitor/123456
|
||||
游客账号:visitor/123456
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
---
|
||||
title: 2023年
|
||||
date: 2023-06-09 21:33:17
|
||||
permalink: /pages/cded59/
|
||||
---
|
||||
|
||||
| 日期 | 渠道 | 金额 |昵称| 备注 |
|
||||
|:-----------|:---|:-----|:-|:-----------------|
|
||||
| 2023-07-31 |Gitee捐助| 50 |失败女神| 感谢您的开源项目! |
|
||||
| 2023-07-28 |微信转账| 50 |AdrianPteLtd.com-咨询| |
|
||||
| 2023-07-12 |微信红包| 100 |MaxKeyTop| 请大佬抽包烟 |
|
||||
| 2023-07-04 |微信红包| 50 |姫野永遠| |
|
||||
| 2023-06-29 |微信红包| 16.8 |迟迟🌱| 加油 |
|
||||
| 2023-06-27 |微信红包| 30 |Arno| |
|
||||
| 2023-06-25 |Gitee捐助| 10 |zhujue888| 感谢您的开源项目! |
|
||||
| 2023-06-16 |微信红包| 50 |小跟班| |
|
||||
| 2023-06-10 |Gitee捐助| 10 |失败女神| 感谢您的开源项目! |
|
||||
| 2023-06-09 |Gitee捐助| 50 |Admin| 感谢您的开源项目! |
|
||||
| 2023-06-09 |微信红包| 50 |李阳| 开源无限好 |
|
||||
| 2023-06-09 |Gitee捐助| 50 |罗宾| 感谢您的开源项目! |
|
||||
| 2023-06-07 |Gitee捐助| 50 |罗宾| 感谢您的开源项目! |
|
||||
| 2023-06-03 |Gitee捐助| 50 |Admin| 感谢您的开源项目! |
|
||||
| 2023-05-29 |微信红包| 20 |TYY| |
|
||||
| 2023-05-29 |Gitee捐助| 10 |笑看| 感谢您的开源项目! |
|
||||
| 2023-05-26 |微信红包| 50 |至少还有满天星光照耀你| |
|
||||
| 2023-02-23 |Gitee捐助| 10 |Yohanes| 感谢您的开源项目! |
|
||||
| 2023-02-23 |Gitee捐助| 20 |jam_lee| 感谢您的开源项目!希望能支持域名映射|
|
||||
| 2023-02-10 |Gitee捐助| 5 |实习两年半| 感谢您的开源项目! |
|
||||
| 2023-02-02 |Gitee捐助| 10 |阳光很暖| 感谢您的开源项目! |
|
||||
@@ -1,7 +1,7 @@
|
||||
---
|
||||
home: true
|
||||
|
||||
heroImage: /img/logo.png
|
||||
heroImage: /img/logo-0.75x.png
|
||||
heroText: Neutrino-Proxy
|
||||
tagline: 🚀一个基于Netty的开源内网穿透神器
|
||||
actionText: 开始使用 →
|
||||
@@ -21,8 +21,12 @@ features: # 可选的
|
||||
details: 新增、编辑、删除、禁用实时生效。
|
||||
- title: Docker
|
||||
details: 服务端支持Docker一键部署。
|
||||
# - title: SSL证书
|
||||
# details: 支持SSL,保护您的信息安全。
|
||||
- title: 隧道SSL加密
|
||||
details: 隧道通信支持SSL,保护您的数据安全
|
||||
- title: HTTPS
|
||||
details: 支持HTTPS
|
||||
- title: 多客户端支持
|
||||
details: 暂未支持
|
||||
|
||||
# 文章列表显示方式: detailed 默认,显示详细版文章列表(包括作者、分类、标签、摘要、分页等)| simple => 显示简约版文章列表(仅标题和日期)| none 不显示文章列表
|
||||
postList: none
|
||||
@@ -162,135 +166,138 @@ postList: none
|
||||
-->
|
||||
|
||||
<h2 id="🤝-dromara-组织项目"><a href="#🤝-dromara-组织项目" class="header-anchor">#</a> 🤝 dromara 组织项目</h2>
|
||||
<p align="center"><b><a href="https://dromara.org/zh/projects/" target="_blank">为往圣继绝学,一个人或许能走的更快,但一群人会走的更远。</a></b></p>
|
||||
<p align="center"><b><a href="https://dromara.org/zh/projects/?from=neutrino-proxy" target="_blank">为往圣继绝学,一个人或许能走的更快,但一群人会走的更远。</a></b></p>
|
||||
<p>
|
||||
<a href="https://gitee.com/dromara/TLog" target="_blank" class="friends-item">
|
||||
<a href="https://gitee.com/dromara/TLog?from=neutrino-proxy" target="_blank" class="friends-item">
|
||||
<img class="no-zoom friends-item-img hover-alt" src="https://oss.dev33.cn/sa-token/link/tlog.png" msg="一个轻量级的分布式日志标记追踪神器,10分钟即可接入,自动对日志打标签完成微服务的链路追踪">
|
||||
</a>
|
||||
<a href="https://gitee.com/dromara/liteFlow" target="_blank" class="friends-item">
|
||||
<a href="https://gitee.com/dromara/liteFlow?from=neutrino-proxy" target="_blank" class="friends-item">
|
||||
<img class="no-zoom friends-item-img hover-alt" src="https://oss.dev33.cn/sa-token/link/liteflow.png" msg="轻量,快速,稳定,可编排的组件式流程引擎">
|
||||
</a>
|
||||
<a href="https://hutool.cn/" target="_blank" class="friends-item">
|
||||
<a href="https://hutool.cn/?from=neutrino-proxy" target="_blank" class="friends-item">
|
||||
<img class="no-zoom friends-item-img hover-alt" src="https://oss.dev33.cn/sa-token/link/hutool.jpg" msg="🍬小而全的Java工具类库,使Java拥有函数式语言般的优雅,让Java语言也可以“甜甜的”。">
|
||||
</a>
|
||||
<a href="https://sa-token.cc/" target="_blank" class="friends-item">
|
||||
<a href="https://sa-token.cc/?from=neutrino-proxy" target="_blank" class="friends-item">
|
||||
<img class="no-zoom friends-item-img hover-alt" src="https://oss.dev33.cn/sa-token/link/sa-token.png" msg="一个轻量级 java 权限认证框架,让鉴权变得简单、优雅!">
|
||||
</a>
|
||||
<a href="https://gitee.com/dromara/hmily" target="_blank" class="friends-item">
|
||||
<a href="https://gitee.com/dromara/hmily?from=neutrino-proxy" target="_blank" class="friends-item">
|
||||
<img class="no-zoom friends-item-img hover-alt" src="https://oss.dev33.cn/sa-token/link/hmily.png" msg="高性能一站式分布式事务解决方案。">
|
||||
</a>
|
||||
<a href="https://gitee.com/dromara/Raincat" target="_blank" class="friends-item">
|
||||
<a href="https://gitee.com/dromara/Raincat?from=neutrino-proxy" target="_blank" class="friends-item">
|
||||
<img class="no-zoom friends-item-img hover-alt" src="https://oss.dev33.cn/sa-token/link/raincat.png" msg="强一致性分布式事务解决方案。">
|
||||
</a>
|
||||
<a href="https://gitee.com/dromara/myth" target="_blank" class="friends-item">
|
||||
<a href="https://gitee.com/dromara/myth?from=neutrino-proxy" target="_blank" class="friends-item">
|
||||
<img class="no-zoom friends-item-img hover-alt" src="https://oss.dev33.cn/sa-token/link/myth.png" msg="可靠消息分布式事务解决方案。">
|
||||
</a>
|
||||
<a href="https://cubic.jiagoujishu.com/" target="_blank" class="friends-item">
|
||||
<a href="https://cubic.jiagoujishu.com/?from=neutrino-proxy" target="_blank" class="friends-item">
|
||||
<img class="no-zoom friends-item-img hover-alt" src="https://oss.dev33.cn/sa-token/link/cubic.png" msg="一站式问题定位平台,以agent的方式无侵入接入应用,完整集成arthas功能模块,致力于应用级监控,帮助开发人员快速定位问题">
|
||||
</a>
|
||||
<a href="https://maxkey.top/" target="_blank" class="friends-item">
|
||||
<a href="https://maxkey.top/?from=neutrino-proxy" target="_blank" class="friends-item">
|
||||
<img class="no-zoom friends-item-img hover-alt" src="https://oss.dev33.cn/sa-token/link/maxkey.png" msg="业界领先的身份管理和认证产品">
|
||||
</a>
|
||||
<a href="http://forest.dtflyx.com/" target="_blank" class="friends-item">
|
||||
<a href="http://forest.dtflyx.com/?from=neutrino-proxy" target="_blank" class="friends-item">
|
||||
<img class="no-zoom friends-item-img hover-alt" src="https://oss.dev33.cn/sa-token/link/forest-logo.png" msg="Forest能够帮助您使用更简单的方式编写Java的HTTP客户端" nf="">
|
||||
</a>
|
||||
<a href="https://jpom.top/" target="_blank" class="friends-item">
|
||||
<a href="https://jpom.top/?from=neutrino-proxy" target="_blank" class="friends-item">
|
||||
<img class="no-zoom friends-item-img hover-alt" src="https://oss.dev33.cn/sa-token/link/jpom.png" msg="一款简而轻的低侵入式在线构建、自动部署、日常运维、项目监控软件">
|
||||
</a>
|
||||
<a href="https://su.usthe.com/" target="_blank" class="friends-item">
|
||||
<a href="https://su.usthe.com/?from=neutrino-proxy" target="_blank" class="friends-item">
|
||||
<img class="no-zoom friends-item-img hover-alt" src="https://oss.dev33.cn/sa-token/link/sureness.png" msg="面向 REST API 的高性能认证鉴权框架">
|
||||
</a>
|
||||
<a href="https://easy-es.cn/" target="_blank" class="friends-item">
|
||||
<a href="https://easy-es.cn/?from=neutrino-proxy" target="_blank" class="friends-item">
|
||||
<img class="no-zoom friends-item-img hover-alt" src="https://oss.dev33.cn/sa-token/link/easy-es2.png" msg="🚀傻瓜级ElasticSearch搜索引擎ORM框架">
|
||||
</a>
|
||||
<a href="https://gitee.com/dromara/northstar" target="_blank" class="friends-item">
|
||||
<a href="https://gitee.com/dromara/northstar?from=neutrino-proxy" target="_blank" class="friends-item">
|
||||
<img class="no-zoom friends-item-img hover-alt" src="https://oss.dev33.cn/sa-token/link/northstar_logo.png" msg="Northstar盈富量化交易平台">
|
||||
</a>
|
||||
<a href="https://hertzbeat.com/" target="_blank" class="friends-item">
|
||||
<a href="https://hertzbeat.com/?from=neutrino-proxy" target="_blank" class="friends-item">
|
||||
<img class="no-zoom friends-item-img hover-alt" src="https://oss.dev33.cn/sa-token/link/hertzbeat-brand.svg" msg="易用友好的云监控系统">
|
||||
</a>
|
||||
<a href="https://dromara.gitee.io/fast-request/" target="_blank" class="friends-item">
|
||||
<a href="https://dromara.gitee.io/fast-request/?from=neutrino-proxy" target="_blank" class="friends-item">
|
||||
<img class="no-zoom friends-item-img hover-alt" src="https://oss.dev33.cn/sa-token/link/fast-request.gif" msg="Idea 版 Postman,为简化调试API而生">
|
||||
</a>
|
||||
<a href="https://www.jeesuite.com/" target="_blank" class="friends-item">
|
||||
<a href="https://www.jeesuite.com/?from=neutrino-proxy" target="_blank" class="friends-item">
|
||||
<img class="no-zoom friends-item-img hover-alt" src="https://oss.dev33.cn/sa-token/link/mendmix.png" msg="开源分布式云原生架构一站式解决方案">
|
||||
</a>
|
||||
<a href="https://gitee.com/dromara/koalas-rpc" target="_blank" class="friends-item">
|
||||
<a href="https://gitee.com/dromara/koalas-rpc?from=neutrino-proxy" target="_blank" class="friends-item">
|
||||
<img class="no-zoom friends-item-img hover-alt" src="https://oss.dev33.cn/sa-token/link/koalas-rpc2.png" msg="企业生产级百亿日PV高可用可拓展的RPC框架。">
|
||||
</a>
|
||||
<a href="https://async.sizegang.cn/" target="_blank" class="friends-item">
|
||||
<a href="https://async.sizegang.cn/?from=neutrino-proxy" target="_blank" class="friends-item">
|
||||
<img class="no-zoom friends-item-img hover-alt" src="https://oss.dev33.cn/sa-token/link/gobrs-async.png" msg="🔥 配置极简功能强大的异步任务动态编排框架">
|
||||
</a>
|
||||
<a href="https://dynamictp.cn/" target="_blank" class="friends-item">
|
||||
<a href="https://dynamictp.cn/?from=neutrino-proxy" target="_blank" class="friends-item">
|
||||
<img class="no-zoom friends-item-img hover-alt" src="https://oss.dev33.cn/sa-token/link/dynamic-tp.png" msg="🔥🔥🔥 基于配置中心的轻量级动态可监控线程池">
|
||||
</a>
|
||||
<a href="https://www.x-easypdf.cn" target="_blank" class="friends-item">
|
||||
<a href="https://www.x-easypdf.cn?from=neutrino-proxy" target="_blank" class="friends-item">
|
||||
<img class="no-zoom friends-item-img hover-alt" src="https://oss.dev33.cn/sa-token/link/x-easypdf.png" msg="一个用搭积木的方式构建pdf的框架(基于pdfbox)">
|
||||
</a>
|
||||
<a href="http://dromara.gitee.io/image-combiner" target="_blank" class="friends-item">
|
||||
<a href="http://dromara.gitee.io/image-combiner?from=neutrino-proxy" target="_blank" class="friends-item">
|
||||
<img class="no-zoom friends-item-img hover-alt" src="https://oss.dev33.cn/sa-token/link/image-combiner.png" msg="一个专门用于图片合成的工具,没有很复杂的功能,简单实用,却不失强大">
|
||||
</a>
|
||||
<a href="https://www.herodotus.cn/" target="_blank" class="friends-item">
|
||||
<a href="https://www.herodotus.cn/?from=neutrino-proxy" target="_blank" class="friends-item">
|
||||
<img class="no-zoom friends-item-img hover-alt" src="https://oss.dev33.cn/sa-token/link/dante-cloud2.png" msg="Dante-Cloud 是一款企业级微服务架构和服务能力开发平台。">
|
||||
</a>
|
||||
<a href="http://www.mtruning.club" target="_blank" class="friends-item">
|
||||
<a href="http://www.mtruning.club?from=neutrino-proxy" target="_blank" class="friends-item">
|
||||
<img class="no-zoom friends-item-img hover-alt" src="https://oss.dev33.cn/sa-token/link/go-view.png" msg="低代码数据可视化开发平台">
|
||||
</a>
|
||||
<a href="https://tangyh.top/" target="_blank" class="friends-item">
|
||||
<a href="https://tangyh.top/?from=neutrino-proxy" target="_blank" class="friends-item">
|
||||
<img class="no-zoom friends-item-img hover-alt" src="https://oss.dev33.cn/sa-token/link/lamp-cloud.png" msg="微服务中后台快速开发平台,支持租户(SaaS)模式、非租户模式">
|
||||
</a>
|
||||
<a href="https://www.redisfront.com/" target="_blank" class="friends-item">
|
||||
<a href="https://www.redisfront.com/?from=neutrino-proxy" target="_blank" class="friends-item">
|
||||
<img class="no-zoom friends-item-img hover-alt" src="https://oss.dev33.cn/sa-token/link/redis-front.png" msg="RedisFront 是一款开源免费的跨平台 Redis 桌面客户端工具, 支持单机模式, 集群模式, 哨兵模式以及 SSH 隧道连接, 可轻松管理Redis缓存数据.">
|
||||
</a>
|
||||
<a href="https://www.yuque.com/u34495/mivcfg" target="_blank" class="friends-item">
|
||||
<a href="https://www.yuque.com/u34495/mivcfg?from=neutrino-proxy" target="_blank" class="friends-item">
|
||||
<img class="no-zoom friends-item-img hover-alt" src="https://oss.dev33.cn/sa-token/link/electron-egg.png" msg="一个入门简单、跨平台、企业级桌面软件开发框架">
|
||||
</a>
|
||||
<a href="https://gitee.com/dromara/open-capacity-platform" target="_blank" class="friends-item">
|
||||
<a href="https://gitee.com/dromara/open-capacity-platform?from=neutrino-proxy" target="_blank" class="friends-item">
|
||||
<img class="no-zoom friends-item-img hover-alt" src="https://oss.dev33.cn/sa-token/link/open-capacity-platform.jpg" msg="简称ocp是基于Spring Cloud的企业级微服务框架(用户权限管理,配置中心管理,应用管理,....)">
|
||||
</a>
|
||||
<a href="http://easy-trans.fhs-opensource.top/" target="_blank" class="friends-item">
|
||||
<a href="http://easy-trans.fhs-opensource.top/?from=neutrino-proxy" target="_blank" class="friends-item">
|
||||
<img class="no-zoom friends-item-img hover-alt" src="https://oss.dev33.cn/sa-token/link/easy_trans.png" msg="Easy-Trans 一个注解搞定数据翻译,减少30%SQL代码量">
|
||||
</a>
|
||||
<a href="https://gitee.com/dromara/neutrino-proxy" target="_blank" class="friends-item">
|
||||
<a href="https://gitee.com/dromara/neutrino-proxy?from=neutrino-proxy" target="_blank" class="friends-item">
|
||||
<img class="no-zoom friends-item-img hover-alt" src="https://oss.dev33.cn/sa-token/link/neutrino-proxy.svg" msg="一款基于 Netty 的、开源的内网穿透神器。">
|
||||
</a>
|
||||
<a href="https://chatgpt.cn.obiscr.com/" target="_blank" class="friends-item">
|
||||
<a href="https://chatgpt.cn.obiscr.com/?from=neutrino-proxy" target="_blank" class="friends-item">
|
||||
<img class="no-zoom friends-item-img hover-alt" src="https://oss.dev33.cn/sa-token/link/chatgpt.png" msg="一个支持在 JetBrains 系列 IDE 上运行的 ChatGPT 的插件。">
|
||||
</a>
|
||||
<a href="https://gitee.com/dromara/zyplayer-doc" target="_blank" class="friends-item">
|
||||
<a href="https://gitee.com/dromara/zyplayer-doc?from=neutrino-proxy" target="_blank" class="friends-item">
|
||||
<img class="no-zoom friends-item-img hover-alt" src="https://oss.dev33.cn/sa-token/link/zyplayer-doc.png" msg="zyplayer-doc是一款适合团队和个人使用的WIKI文档管理工具,同时还包含数据库文档、Api接口文档。">
|
||||
</a>
|
||||
<a href="https://gitee.com/dromara/payment-spring-boot" target="_blank" class="friends-item">
|
||||
<a href="https://gitee.com/dromara/payment-spring-boot?from=neutrino-proxy" target="_blank" class="friends-item">
|
||||
<img class="no-zoom friends-item-img hover-alt" src="https://oss.dev33.cn/sa-token/link/payment-spring-boot.png" msg="最全最好用的微信支付V3 Spring Boot 组件。">
|
||||
</a>
|
||||
<a href="https://www.j2eefast.com/" target="_blank" class="friends-item">
|
||||
<a href="https://www.j2eefast.com/?from=neutrino-proxy" target="_blank" class="friends-item">
|
||||
<img class="no-zoom friends-item-img hover-alt" src="https://oss.dev33.cn/sa-token/link/j2eefast.png" msg="J2eeFAST 是一个致力于中小企业 Java EE 企业级快速开发平台,我们永久开源!">
|
||||
</a>
|
||||
<a href="https://gitee.com/dromara/data-compare" target="_blank" class="friends-item">
|
||||
<a href="https://gitee.com/dromara/data-compare?from=neutrino-proxy" target="_blank" class="friends-item">
|
||||
<img class="no-zoom friends-item-img hover-alt" src="https://oss.dev33.cn/sa-token/link/dataCompare.png" msg="数据库比对工具:hive 表数据比对,mysql、Doris 数据比对,实现自动化配置进行数据比对,避免频繁写sql 进行处理,低代码(Low-Code) 平台">
|
||||
</a>
|
||||
<a href="https://gitee.com/dromara/open-giteye-api" target="_blank" class="friends-item">
|
||||
<a href="https://gitee.com/dromara/open-giteye-api?from=neutrino-proxy" target="_blank" class="friends-item">
|
||||
<img class="no-zoom friends-item-img hover-alt" src="https://oss.dev33.cn/sa-token/link/open-giteye-api.svg" msg="giteye.net 是专为开源作者设计的数据图表服务工具类站点,提供了包括 Star 趋势图、贡献者列表、Gitee指数等数据图表服务。">
|
||||
</a>
|
||||
<a href="https://gitee.com/dromara/RuoYi-Vue-Plus" target="_blank" class="friends-item">
|
||||
<a href="https://gitee.com/dromara/RuoYi-Vue-Plus?from=neutrino-proxy" target="_blank" class="friends-item">
|
||||
<img class="no-zoom friends-item-img hover-alt" src="https://oss.dev33.cn/sa-token/link/RuoYi-Vue-Plus.png" msg="后台管理系统 重写 RuoYi-Vue 所有功能 集成 Sa-Token + Mybatis-Plus + Jackson + Xxl-Job + SpringDoc + Hutool + OSS 定期同步">
|
||||
</a>
|
||||
<a href="https://gitee.com/dromara/RuoYi-Cloud-Plus" target="_blank" class="friends-item">
|
||||
<a href="https://gitee.com/dromara/RuoYi-Cloud-Plus?from=neutrino-proxy" target="_blank" class="friends-item">
|
||||
<img class="no-zoom friends-item-img hover-alt" src="https://oss.dev33.cn/sa-token/link/RuoYi-Cloud-Plus.png" msg="微服务管理系统 重写RuoYi-Cloud所有功能 整合 SpringCloudAlibaba Dubbo3.0 Sa-Token Mybatis-Plus MQ OSS ES Xxl-Job Docker 全方位升级 定期同步">
|
||||
</a>
|
||||
<a href="https://gitee.com/dromara/stream-query" target="_blank" class="friends-item">
|
||||
<a href="https://gitee.com/dromara/stream-query?from=neutrino-proxy" target="_blank" class="friends-item">
|
||||
<img class="no-zoom friends-item-img hover-alt" src="https://oss.dev33.cn/sa-token/link/stream-query.png" msg="允许完全摆脱 Mapper 的 mybatis-plus 体验!封装 stream 和 lambda 操作进行数据返回处理。">
|
||||
</a>
|
||||
<a href="https://dromara.org/zh/projects/" target="_blank" class="friends-item">
|
||||
<a href="https://dromara.org/zh/projects/?from=neutrino-proxy" target="_blank" class="friends-item">
|
||||
<img class="no-zoom friends-item-img hover-alt" src="https://oss.dev33.cn/sa-token/link/dromara.png" msg="让每一位开源爱好者,体会到开源的快乐。">
|
||||
</a>
|
||||
</p>
|
||||
|
||||
<h2>🤝 友情开源项目</h2>
|
||||
<p>
|
||||
<a href="https://gitee.com/noear/solon" target="_blank" class="friends-item" style="display: flex;">
|
||||
<a href="https://gitee.com/noear/solon?from=neutrino-proxy" target="_blank" class="friends-item" >
|
||||
<img class="no-zoom friends-item-img hover-alt" :src="$withBase('/img/logo/solon_logo_500_150.png')" msg="一个高效的应用开发框架:更快、更小、更简单。" />
|
||||
</a>
|
||||
<a href="https://gitee.com/xiaonuobase/snowy?from=neutrino-proxy" target="_blank" class="friends-item">
|
||||
<img class="no-zoom friends-item-img hover-alt" :src="$withBase('/img/logo/xiaonuo.png')" msg="国内首个国密前后端分离快速开发平台" />
|
||||
</a>
|
||||
</p>
|
||||
|
||||
<!-- AD -->
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.noear</groupId>
|
||||
<artifactId>solon-parent</artifactId>
|
||||
<version>2.2.8</version>
|
||||
<version>2.3.6</version>
|
||||
<relativePath />
|
||||
</parent>
|
||||
|
||||
@@ -97,6 +97,11 @@
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>5.1.49</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mariadb.jdbc</groupId>
|
||||
<artifactId>mariadb-java-client</artifactId>
|
||||
<version>2.7.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zaxxer</groupId>
|
||||
<artifactId>HikariCP</artifactId>
|
||||
|
||||
@@ -41,4 +41,6 @@ npm run build:$env
|
||||
#拷贝
|
||||
cd ..
|
||||
cp -rf ./neutrino-proxy-admin/dist $adminDeployDir/
|
||||
cp -rf ./neutrino-proxy-admin/dist/ $giteePagesDir
|
||||
cp -rf ./neutrino-proxy-admin/dist/ $giteePagesDir
|
||||
cd $serverDeployDir
|
||||
zip -r neutrino-proxy-admin.zip "neutrino-proxy-admin/"
|
||||
|
||||
@@ -41,4 +41,6 @@ npm run build:$env
|
||||
#拷贝
|
||||
cd ..
|
||||
cp -rf ./neutrino-proxy-admin/dist $adminDeployDir/
|
||||
cp -rf ./neutrino-proxy-admin/dist/ $giteePagesDir
|
||||
cp -rf ./neutrino-proxy-admin/dist/ $giteePagesDir
|
||||
cd $serverDeployDir
|
||||
zip -r neutrino-proxy-admin.zip "neutrino-proxy-admin/"
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
# 中微子代理客户端编译打包脚本,基础参数请自行修改
|
||||
|
||||
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home
|
||||
export MAVANE_HOME=/Users/yangwen/my/service/maven/apache-maven-3.8.1
|
||||
export PATH=:$PATH:$JAVA_HOME/bin:$MAVANE_HOME/bin
|
||||
export MAVEN_HOME=/Users/yangwen/my/service/maven/apache-maven-3.8.1
|
||||
export PATH=:$PATH:$JAVA_HOME/bin:$MAVEN_HOME/bin
|
||||
|
||||
deployDir="deploy"
|
||||
clientDeployDir=$deployDir"/client"
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
#!/bin/sh
|
||||
|
||||
# 镜像版本,每次更新版本时需要调整
|
||||
ImageVer=1.8.5
|
||||
ImageName=neutrino-proxy-client
|
||||
DockerFilePath=$PWD/../../neutrino-proxy-client/Dockerfile
|
||||
|
||||
deployDir=$PWD/../../"deploy"
|
||||
clientDeployDir=$deployDir"/client"
|
||||
|
||||
#切到项目根目录
|
||||
#初始化文件夹
|
||||
if [ ! -d "$deployDir" ];then
|
||||
mkdir $deployDir
|
||||
fi
|
||||
if [ ! -d "$clientDeployDir" ];then
|
||||
mkdir $clientDeployDir
|
||||
fi
|
||||
rm -rf $clientDeployDir/$ImageName.tar
|
||||
|
||||
#echo '打包jar...'
|
||||
sh ./client_build.sh
|
||||
|
||||
# 删除老的本地镜像
|
||||
docker rmi -f $(docker images | grep $ImageName | awk '{print $3}')
|
||||
# 构建镜像
|
||||
docker build -t $ImageName:$ImageVer -t $ImageName:latest -f $DockerFilePath $PWD/../..
|
||||
# 保存镜像到本地
|
||||
docker save -o $clientDeployDir/$ImageName.tar $ImageName:$ImageVer
|
||||
@@ -37,7 +37,7 @@ cp $OUT $JAR_PATH/logs/back_$time.out
|
||||
fi
|
||||
rm -f $OUT
|
||||
cd $JAR_PATH
|
||||
nohup java $JAVA_OPS -jar $NAME.jar $startupParams > $OUT 2>&1 &
|
||||
nohup java -Dfile.encoding=utf-8 $JAVA_OPS -jar $NAME.jar $startupParams > $OUT 2>&1 &
|
||||
echo "sleep 15s wating service start"
|
||||
sleep 15
|
||||
tail -200 $OUT
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
# 中微子代理客户端编译打包脚本,基础参数请自行修改
|
||||
|
||||
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home
|
||||
export MAVANE_HOME=/Users/yangwen/my/service/maven/apache-maven-3.8.1
|
||||
export PATH=:$PATH:$JAVA_HOME/bin:$MAVANE_HOME/bin
|
||||
export MAVEN_HOME=/Users/yangwen/my/service/maven/apache-maven-3.8.1
|
||||
export PATH=:$PATH:$JAVA_HOME/bin:$MAVEN_HOME/bin
|
||||
|
||||
deployDir="deploy"
|
||||
serverDeployDir=$deployDir"/server"
|
||||
|
||||
@@ -29,7 +29,7 @@ cp $OUT $JAR_PATH/logs/back_$time.out
|
||||
fi
|
||||
rm -f $OUT
|
||||
cd $JAR_PATH
|
||||
nohup java $JAVA_OPS -jar $NAME.jar > $OUT 2>&1 &
|
||||
nohup java -Dfile.encoding=utf-8 $JAVA_OPS -jar $NAME.jar > $OUT 2>&1 &
|
||||
echo "sleep 15s wating service start"
|
||||
sleep 15
|
||||
tail -200 $OUT
|
||||
|
||||
@@ -1,10 +1,45 @@
|
||||
# 1.x剩余规划
|
||||
- [ ] 增加针对https的支持
|
||||
# 1.x规划
|
||||
- Bug
|
||||
- 优化
|
||||
- 添加端口映射时,验证端口是否被其他服务占用
|
||||
- 拉下搜索license,支持模糊搜索
|
||||
- license下拉用户搜索,支持模糊搜索
|
||||
- UDP支持
|
||||
- 官网文档完善
|
||||
- HTTPS配置说明
|
||||
- 协议重构
|
||||
- 代码重构
|
||||
|
||||
# 1.8.6
|
||||
- [x] 端口映射选择端口支持分页
|
||||
- [x] 新增/更新端口映射,增加端口占用检测
|
||||
- [x] 拉下搜索license,支持模糊搜索
|
||||
- [x] license下拉用户搜索,支持模糊搜索
|
||||
- [x] 端口映射编辑时,如果端口号没有变动,则不验证。避免出现端口映射正在使用时,无法更新端口映射其他信息的问题
|
||||
- [x] 端口映射HTTP(S)新增打开网页按钮
|
||||
- [x] 客户端断开连接时,记录日志空指针异常问题修复
|
||||
|
||||
# 1.9.0
|
||||
- [x] 支持UDP
|
||||
- 服务端
|
||||
- 原`neutrino.proxy.server`配置移到`neutrino.proxy.server.tcp`下
|
||||
- 客户端
|
||||
- 原`neutrino.proxy.client`配置移到`neutrino.proxy.tunnel`下
|
||||
- [x] 端口映射HTTP(S)新增打开网页按钮,优先使用域名打开
|
||||
- [x] 新增/编辑端口映射时端口占用检测功能屏蔽,解决docker下使用的各种问题
|
||||
|
||||
# 1.9.1
|
||||
- [ ] 如果UDP映射服务端端口变动,流量统计似乎不准,转发功能或许也受到影响,需要评估、测试、思考如何优化
|
||||
- [ ] 增加服务端/客户端jar式一键部署脚本
|
||||
- [ ] 排查解决问题:https://gitee.com/dromara/neutrino-proxy/issues/I7LGLB
|
||||
- [ ] 访问白名单
|
||||
- [ ] 端口映射分组
|
||||
|
||||
# Bug
|
||||
- 指令通达被close的问题,org.dromara.neutrinoproxy.server.proxy.core.ServerChannelHandler.channelInactive
|
||||
- 指令通达被close的问题,org.dromara.neutrinoproxy.server.proxy.core.ProxyTunnelChannelHandler.channelInactive
|
||||
- windows环境下直接运行发布版的jar包,日志输出乱码
|
||||
- 代理mysql时,使用未开启远程访问的账号走代理访问mysql,代理客户端出现断开现象
|
||||
- 客户端连接映射某个端口以后,如果在服务器端禁用了,没有立刻反映出来,要灯客户端重连以后才会屏蔽被禁用的端口。
|
||||
|
||||
# 2.x规划
|
||||
- 插件开发
|
||||
@@ -19,6 +54,8 @@
|
||||
- [ ] 支持调整服务端端口、证书
|
||||
- [ ] 服务端版本、协议版本、客户端版本管理
|
||||
- [ ] 服务端日志
|
||||
- [ ] 支持持管理后台动态调整日志级别。
|
||||
- [ ] 动态调整转发、报文、心跳输出
|
||||
- client+计划启动
|
||||
- [ ] 安卓客户端
|
||||
- [ ] 基于electron-egg的多平台客户端
|
||||
@@ -26,4 +63,4 @@
|
||||
# 3.x规划
|
||||
- [ ] 支持针对用户限速、限流
|
||||
- [ ] 支持P2P穿透
|
||||
- [ ] 支持原生编译
|
||||
- [ ] 支持原生编译
|
||||
|
||||