Compare commits
42
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
99a93bb8a8 | ||
|
|
1bbf13763f | ||
|
|
75cf0702f2 | ||
|
|
a367865585 | ||
|
|
2d4a70ed22 | ||
|
|
dcf834c261 | ||
|
|
ccb6fe0fda | ||
|
|
afb4d63df0 | ||
|
|
11794e719d | ||
|
|
ca1ae2eb67 | ||
|
|
d996cf096e | ||
|
|
641e3533ea | ||
|
|
dd1c65f2e4 | ||
|
|
bd7f11a9f5 | ||
|
|
0a09eb30df | ||
|
|
a4eead50a0 | ||
|
|
3f2e86be31 | ||
|
|
921467078d | ||
|
|
750e6505ec | ||
|
|
6ad8b199a9 | ||
|
|
d7d4fbaa73 | ||
|
|
ef1a4110ff | ||
|
|
9dc6f0d479 | ||
|
|
5f39869400 | ||
|
|
c89daf1e60 | ||
|
|
c5d0763172 | ||
|
|
f525c45f8c | ||
|
|
e219cfe070 | ||
|
|
2b0e37ec86 | ||
|
|
be1621c42d | ||
|
|
d367c3099d | ||
|
|
19f77bd0d0 | ||
|
|
878c4284ef | ||
|
|
17b73f2f45 | ||
|
|
c7dc0c71df | ||
|
|
47318beb87 | ||
|
|
78c93cf3c3 | ||
|
|
d52b6a86c0 | ||
|
|
83269f93e1 | ||
|
|
191b9e1758 | ||
|
|
0dd71195cd | ||
|
|
3596d147b8 |
@@ -69,6 +69,7 @@ jobs:
|
||||
- name: Build with Maven (neutrino-proxy-client)
|
||||
run: |
|
||||
set MAVEN_OPTS="-Duser.language=UTF-8 -Dfile.encoding=UTF-8"
|
||||
mvn clean install -U -pl neutrino-proxy-client -am -DskipTests --no-transfer-progress
|
||||
cd neutrino-proxy-client
|
||||
mvn clean package --file pom.xml --no-transfer-progress
|
||||
mvn clean native:compile -P native --file pom.xml --no-transfer-progress
|
||||
|
||||
+2
-2
@@ -54,11 +54,11 @@ hs_err_pid*
|
||||
|
||||
**/memo/**
|
||||
|
||||
neutrino-proxy-vuepress/deploy
|
||||
neutrino-proxy-vuepress/deploy.sh
|
||||
.NEUTRINO_PROXY_CLIENT_ID
|
||||
logs
|
||||
data
|
||||
**/cert/**
|
||||
neutrino-proxy-server/src/main/resources/static/**
|
||||
/neutrino-proxy-server/src/main/resources/static/
|
||||
|
||||
client+/neutrino-proxy-client-chrome-plugin
|
||||
|
||||
@@ -1,19 +1,11 @@
|
||||
|
||||
|
||||
# what is new? 在原版的基础上新增了【域名解析】功能,域名解析【无需】绑定【本地端口】
|
||||
<p>
|
||||
<a href="https://gitee.com/zcans" target="_blank">
|
||||
<img src="assets/run-example/domain.png" >
|
||||
</a>
|
||||
|
||||
<p align="center">
|
||||
<img src="assets/logo/logo-text-vertical.png" width="45%">
|
||||
</p>
|
||||
<p align="center">
|
||||
<a href='https://gitee.com/dromara/neutrino-proxy/stargazers'><img src='https://gitee.com/dromara/neutrino-proxy/badge/star.svg?theme=dark' alt='star'></img></a>
|
||||
<a href='https://gitee.com/dromara/neutrino-proxy/members'><img src='https://gitee.com/dromara/neutrino-proxy/badge/fork.svg?theme=dark' alt='fork'></img></a>
|
||||
<a target="_blank" href="https://www.oracle.com/java/technologies/javase/javase-jdk21-downloads.html">
|
||||
<img src="https://img.shields.io/badge/JDK-21+-red.svg" />
|
||||
<a target="_blank" href="https://www.oracle.com/java/technologies/javase/javase-jdk17-downloads.html">
|
||||
<img src="https://img.shields.io/badge/JDK-17+-red.svg" />
|
||||
</a>
|
||||
<a href="./LICENSE">
|
||||
<img src="https://img.shields.io/badge/license-MIT-red" alt="license MIT">
|
||||
@@ -26,7 +18,6 @@
|
||||
- 遵循MIT许可,因此您可以对它进行复制、修改、传播并用于任何个人或商业行为。
|
||||
- 官网地址1:https://neutrino-proxy.dromara.org
|
||||
- 官网地址2:https://dromara.gitee.io/neutrino-proxy
|
||||
- 官网地址3:https://neutrino-proxy-docs.asgc.fun
|
||||
- 快速上手请[点击这里](https://dromara.gitee.io/neutrino-proxy/pages/793dcb)
|
||||
|
||||
# 2、名称由来
|
||||
@@ -100,6 +91,9 @@
|
||||
<a href="https://gitee.com/nichenxyx" target="_blank">
|
||||
<img src="assets/developer/NichenFly.jpg" width="11%">
|
||||
</a>
|
||||
<a href="https://gitee.com/giteeClass" target="_blank">
|
||||
<img src="assets/developer/coder.png" width="11%">
|
||||
</a>
|
||||
</p>
|
||||
|
||||
# ❤️ 感谢
|
||||
|
||||
@@ -79,3 +79,9 @@
|
||||
- 支持对用户、license限速
|
||||
- 修复HTTP(S)映射时使用tcp端口访问正常,使用域名访问偶现一直loading的问题
|
||||
- 修复HTTP(S)映射时使用映射的域名上传文件时,连接中断的问题
|
||||
|
||||
## 2.0.2
|
||||
- 升级solon版本到2.7.0-M2,解决不在当前目录下启动时找不到配置文件的问题
|
||||
- client抽出sdk(还需测试windows原生部署、进一步抽出neutrino-proxy-sdk)
|
||||
- 修复管理后台分页查询的已知问题
|
||||
- 修复native下,批量删除端口池报错的问题
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 1.4 MiB |
Binary file not shown.
|
Before Width: | Height: | Size: 102 KiB |
@@ -0,0 +1,16 @@
|
||||
FROM openjdk:21-jdk-oracle
|
||||
#同步时间
|
||||
#RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && \
|
||||
# apk update && apk add wget unzip vim && apk add -U tzdata && \
|
||||
# ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone
|
||||
# 设置时区为北京时间
|
||||
ENV TZ=Asia/Shanghai
|
||||
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
|
||||
RUN mkdir -p /root/neutrino-proxy/config
|
||||
WORKDIR /root/neutrino-proxy
|
||||
COPY ./target/neutrino-proxy-client.jar /root/neutrino-proxy/neutrino-proxy-client.jar
|
||||
COPY src/main/resources/app-copy.yml /root/neutrino-proxy/config/app.yml
|
||||
#VOLUME ["/root/neutrino-proxy"]
|
||||
ENTRYPOINT ["java","-jar","neutrino-proxy-client.jar","config=./config/app.yml"]
|
||||
|
||||
#docker run -it -d --restart=always --name np_client -e SERVER_IP=127.0.0.1
|
||||
@@ -0,0 +1,211 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>io.github.javpower</groupId>
|
||||
<artifactId>neutrino-proxy-client-spring-boot-starter</artifactId>
|
||||
<version>2.0.1</version>
|
||||
<name>neutrino-proxy-client-spring-boot-starter</name>
|
||||
<description>a tool about easy neutrino-proxy-client</description>
|
||||
<url>https://github.com/javpower/neutrino-proxy</url>
|
||||
<licenses>
|
||||
<license>
|
||||
<name> The Apache Software License, Version 2.0 </name>
|
||||
<url> http://www.apache.org/licenses/LICENSE-2.0.txt </url>
|
||||
<distribution> repo </distribution>
|
||||
</license>
|
||||
</licenses>
|
||||
<scm>
|
||||
<url>https://github.com/javpower/neutrino-proxy</url>
|
||||
<connection>scm:[email protected]/javpower/neutrino-proxy.git</connection>
|
||||
<developerConnection>scm:[email protected]/javpower/neutrino-proxy.git</developerConnection>
|
||||
</scm>
|
||||
<developers>
|
||||
<developer>
|
||||
<name>gc.x</name>
|
||||
<email>[email protected]</email>
|
||||
<organization> https://github.com/javpower</organization>
|
||||
<timezone>+8</timezone>
|
||||
</developer>
|
||||
</developers>
|
||||
<properties>
|
||||
<mica-auto.version>2.3.2</mica-auto.version>
|
||||
<spring-boot.version>2.7.13</spring-boot.version>
|
||||
<revision>2.0.1</revision>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.dromara.neutrino-proxy</groupId>
|
||||
<artifactId>neutrino-proxy-client-sdk</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>1.7.36</version>
|
||||
</dependency>
|
||||
<!-- 其他依赖项... -->
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<version>1.2.12</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.30</version>
|
||||
</dependency>
|
||||
<!--SSH中转隧道-->
|
||||
<dependency>
|
||||
<groupId>com.jcraft</groupId>
|
||||
<artifactId>jsch</artifactId>
|
||||
<version>0.1.54</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jcraft</groupId>
|
||||
<artifactId>jzlib</artifactId>
|
||||
<version>1.1.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.dreamlu</groupId>
|
||||
<artifactId>mica-auto</artifactId>
|
||||
<version>${mica-auto.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-dependencies</artifactId>
|
||||
<version>${spring-boot.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<distributionManagement>
|
||||
<snapshotRepository>
|
||||
<id>ossrh</id>
|
||||
<url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
|
||||
</snapshotRepository>
|
||||
<repository>
|
||||
<id>ossrh</id>
|
||||
<url> https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<source>8</source>
|
||||
<target>8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
|
||||
</manifest>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<version>${spring-boot.version}</version>
|
||||
<configuration>
|
||||
<mainClass>org.dromara.neutrinoproxy.client.starter.SpringProxyClient</mainClass>
|
||||
<skip>true</skip>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.sonatype.plugins</groupId>
|
||||
<artifactId>nexus-staging-maven-plugin</artifactId>
|
||||
<version>1.6.7</version>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<serverId>ossrh</serverId>
|
||||
<nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
|
||||
<autoReleaseAfterClose>true</autoReleaseAfterClose>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId> org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>2.2.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-sources</id>
|
||||
<goals>
|
||||
<goal>jar-no-fork</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>2.9.1</version>
|
||||
<configuration>
|
||||
<show>private</show>
|
||||
<nohelp>true</nohelp>
|
||||
<charset>UTF-8</charset>
|
||||
<encoding>UTF-8</encoding>
|
||||
<docencoding>UTF-8</docencoding>
|
||||
<additionalparam>-Xdoclint:none</additionalparam>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-gpg-plugin</artifactId>
|
||||
<version>1.5</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>sign-artifacts</id>
|
||||
<phase>verify</phase>
|
||||
<goals>
|
||||
<goal>sign</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
<version>2.8.2</version>
|
||||
</plugin>
|
||||
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package org.dromara.neutrinoproxy.client.starter;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* @author: gc.x
|
||||
* @date: 2024/1/21
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@Slf4j
|
||||
public class SpringProxyClient {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(SpringProxyClient.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package org.dromara.neutrinoproxy.client.starter.config;
|
||||
|
||||
import org.dromara.neutrinoproxy.client.starter.util.ApplicationContextUtils;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.event.ContextRefreshedEvent;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 启动监听
|
||||
* @author: gc.x
|
||||
* @date: 2024/1/21
|
||||
*/
|
||||
@Component
|
||||
public class MainBusListeners implements ApplicationListener<ContextRefreshedEvent> {
|
||||
@Override
|
||||
public void onApplicationEvent(ContextRefreshedEvent event) {
|
||||
ApplicationContextUtils.setContext(event.getApplicationContext());
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package org.dromara.neutrinoproxy.client.starter.config;
|
||||
|
||||
import org.dromara.neutrinoproxy.client.sdk.handler.ProxyMessageFactory;
|
||||
import org.dromara.neutrinoproxy.client.starter.util.ApplicationContextUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
||||
/**
|
||||
* 代理配置
|
||||
* @author: aoshiguchen
|
||||
* @date: 2022/10/8
|
||||
*/
|
||||
@Component
|
||||
public class ProxyConfiguration extends ProxyMessageFactory {
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
ApplicationContextUtils.stop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAotRuntime() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
package org.dromara.neutrinoproxy.client.starter.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.dromara.neutrinoproxy.client.starter.ssh.SSHProxy;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author: gc.x
|
||||
* @date: 2024/1/21
|
||||
*/
|
||||
@Data
|
||||
@ConfigurationProperties(prefix = "neutrino.proxy")
|
||||
@Component
|
||||
public class SpringProxyConfig {
|
||||
private Boolean enable=false;
|
||||
private Boolean sshEnable=false;
|
||||
private Protocol protocol;
|
||||
private Tunnel tunnel;
|
||||
private Client client;
|
||||
private List<SSHProxy> sshProxys;
|
||||
|
||||
@Data
|
||||
public static class Protocol {
|
||||
private Integer maxFrameLength;
|
||||
private Integer lengthFieldOffset;
|
||||
private Integer lengthFieldLength;
|
||||
private Integer initialBytesToStrip;
|
||||
private Integer lengthAdjustment;
|
||||
private Integer readIdleTime;
|
||||
private Integer writeIdleTime;
|
||||
private Integer allIdleTimeSeconds;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Tunnel {
|
||||
private String keyStorePassword;
|
||||
private String jksPath;
|
||||
private String serverIp;
|
||||
private Integer serverPort;
|
||||
private Boolean sslEnable;
|
||||
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;
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
package org.dromara.neutrinoproxy.client.starter.core;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.neutrinoproxy.client.sdk.config.ProxyConfig;
|
||||
import org.dromara.neutrinoproxy.client.starter.config.ProxyConfiguration;
|
||||
import org.dromara.neutrinoproxy.client.starter.config.SpringProxyConfig;
|
||||
import org.dromara.neutrinoproxy.client.starter.ssh.SSHConnectionFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 代理客户端服务
|
||||
* @author: gc.x
|
||||
* @date: 2024/1/21
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class ProxyClientService implements ApplicationRunner {
|
||||
|
||||
@Autowired
|
||||
private ProxyConfiguration proxyConfiguration;
|
||||
@Autowired
|
||||
private SpringProxyConfig springProxyConfig;
|
||||
@Override
|
||||
public void run(ApplicationArguments args) {
|
||||
if(springProxyConfig.getEnable()){
|
||||
log.info("start....");
|
||||
ProxyConfig proxyConfig = BeanUtil.toBean(springProxyConfig, ProxyConfig.class);
|
||||
proxyConfiguration.start(proxyConfig);
|
||||
log.info("start success!");
|
||||
}
|
||||
if(springProxyConfig.getSshEnable()){
|
||||
springProxyConfig.getSshProxys().forEach(sshProxy -> {
|
||||
String sshId = SSHConnectionFactory.factory.addConnection(sshProxy);
|
||||
SSHConnectionFactory.factory.openTunnel(sshId);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package org.dromara.neutrinoproxy.client.starter.ssh;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author: gc.x
|
||||
* @date: 2024/1/21
|
||||
*/
|
||||
public class SSHConnectionFactory {
|
||||
public static final SSHConnectionService factory = new SSHConnectionServiceImpl();
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package org.dromara.neutrinoproxy.client.starter.ssh;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author: gc.x
|
||||
* @date: 2024/1/21
|
||||
*/
|
||||
public interface SSHConnectionService {
|
||||
String addConnection(String host, String username, String password, int localPort, int remotePort,String remoteHost);
|
||||
String addConnection(SSHProxy sshProxy);
|
||||
void openTunnel(String sshId);
|
||||
void closeTunnel(String sshId);
|
||||
void closeAllTunnels();
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
package org.dromara.neutrinoproxy.client.starter.ssh;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
/**
|
||||
*
|
||||
* @author: gc.x
|
||||
* @date: 2024/1/21
|
||||
*/
|
||||
public class SSHConnectionServiceImpl implements SSHConnectionService {
|
||||
|
||||
private Map<String, SSHProxy> connections;
|
||||
private Map<String, SSHProxyFactory> factories;
|
||||
|
||||
public SSHConnectionServiceImpl() {
|
||||
connections = new HashMap<>();
|
||||
factories = new HashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String addConnection(String host, String username, String password, int localPort, int remotePort,String remoteHost) {
|
||||
SSHProxy connection = new SSHProxy();
|
||||
String sshId = UUID.randomUUID().toString();
|
||||
connection.setSshId(sshId);
|
||||
connection.setHost(host);
|
||||
connection.setUsername(username);
|
||||
connection.setPassword(password);
|
||||
connection.setLocalPort(localPort);
|
||||
connection.setRemotePort(remotePort);
|
||||
connection.setRemoteHost(remoteHost);
|
||||
connections.put(connection.getSshId(), connection);
|
||||
return sshId;
|
||||
}
|
||||
@Override
|
||||
public String addConnection(SSHProxy sshProxy) {
|
||||
String sshId = UUID.randomUUID().toString();
|
||||
sshProxy.setSshId(sshId);
|
||||
connections.put(sshProxy.getSshId(), sshProxy);
|
||||
return sshId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openTunnel(String sshId) {
|
||||
SSHProxy connection = connections.get(sshId);
|
||||
if (connection != null && !factories.containsKey(sshId)) {
|
||||
SSHProxyFactory factory = new SSHProxyFactoryImpl(connection);
|
||||
factory.openTunnel();
|
||||
factories.put(sshId, factory);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeTunnel(String sshId) {
|
||||
SSHProxyFactory factory = factories.get(sshId);
|
||||
|
||||
if (factory != null) {
|
||||
factory.closeTunnel();
|
||||
factories.remove(sshId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeAllTunnels() {
|
||||
for (Map.Entry<String, SSHProxyFactory> entry : factories.entrySet()) {
|
||||
SSHProxyFactory factory = entry.getValue();
|
||||
factory.closeTunnel();
|
||||
}
|
||||
factories.clear();
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package org.dromara.neutrinoproxy.client.starter.ssh;
|
||||
|
||||
import lombok.Data;
|
||||
/**
|
||||
*
|
||||
* @author: gc.x
|
||||
* @date: 2024/1/21
|
||||
*/
|
||||
@Data
|
||||
public class SSHProxy {
|
||||
private String sshId;
|
||||
|
||||
//跳板机服务器公网IP
|
||||
private String host;
|
||||
//跳板机服务器登录名
|
||||
private String username;
|
||||
//跳板机登陆密码
|
||||
private String password;
|
||||
//本地的端口
|
||||
private int localPort;
|
||||
|
||||
//需代理服务器端口号
|
||||
private int remotePort;
|
||||
//需代理服务器ip
|
||||
private String remoteHost;
|
||||
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package org.dromara.neutrinoproxy.client.starter.ssh;
|
||||
/**
|
||||
*
|
||||
* @author: gc.x
|
||||
* @date: 2024/1/21
|
||||
*/
|
||||
public interface SSHProxyFactory {
|
||||
void openTunnel();
|
||||
void closeTunnel();
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
package org.dromara.neutrinoproxy.client.starter.ssh;
|
||||
|
||||
import com.jcraft.jsch.JSch;
|
||||
import com.jcraft.jsch.Session;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
/**
|
||||
*
|
||||
* @author: gc.x
|
||||
* @date: 2024/1/21
|
||||
*/
|
||||
@Slf4j
|
||||
public class SSHProxyFactoryImpl implements SSHProxyFactory {
|
||||
private SSHProxy connection;
|
||||
private Session session;
|
||||
|
||||
public SSHProxyFactoryImpl(SSHProxy connection) {
|
||||
this.connection = connection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openTunnel() {
|
||||
try {
|
||||
JSch jsch = new JSch();
|
||||
session = jsch.getSession(connection.getUsername(), connection.getHost(), 22);
|
||||
session.setPassword(connection.getPassword());
|
||||
// 开启调试模式,打印更多详细日志
|
||||
java.util.Properties config = new java.util.Properties();
|
||||
config.put("StrictHostKeyChecking", "no");
|
||||
config.put("userauth.gssapi-with-mic", "no");
|
||||
config.put("compression.s2c", "[email protected],zlib,none");
|
||||
config.put("compression.c2s", "[email protected],zlib,none");
|
||||
session.setConfig(config);
|
||||
session.setDaemonThread(true);
|
||||
JSch.setLogger(new com.jcraft.jsch.Logger() {
|
||||
public boolean isEnabled(int level) {
|
||||
return true;
|
||||
}
|
||||
public void log(int level, String message) {
|
||||
log.info("JSch - " + level + ": " + message);
|
||||
}
|
||||
});
|
||||
|
||||
int assignedPort = session.setPortForwardingL(connection.getLocalPort(), connection.getRemoteHost(), connection.getRemotePort());
|
||||
session.connect(10000);
|
||||
if (assignedPort != -1) {
|
||||
log.info("SSH connection established successfully!");
|
||||
} else {
|
||||
log.info("Failed to establish SSH connection!");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// 异常处理
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeTunnel() {
|
||||
if (session != null && session.isConnected()) {
|
||||
session.disconnect();
|
||||
log.info("SSH connection closed successfully!");
|
||||
}
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
package org.dromara.neutrinoproxy.client.starter.util;
|
||||
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.beans.factory.support.GenericBeanDefinition;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
/**
|
||||
* ApplicaitonContext工具类
|
||||
* @author: gc.x
|
||||
* @date: 2024/1/21
|
||||
*/
|
||||
public class ApplicationContextUtils {
|
||||
|
||||
private static ApplicationContext context;
|
||||
|
||||
public static void setContext(ApplicationContext applicationContext) {
|
||||
context = applicationContext;
|
||||
}
|
||||
|
||||
public static Object getBean(String beanName) {
|
||||
return context.getBean(beanName);
|
||||
}
|
||||
public static void stop(){
|
||||
SpringApplication.exit(context);
|
||||
}
|
||||
public static <T> T getBean(String beanName,Class<T> t) {
|
||||
return context.getBean(beanName,t);
|
||||
}
|
||||
public static <T> T getBean(Class<T> t) {
|
||||
return context.getBean(t);
|
||||
}
|
||||
|
||||
public static void addBean(String beanName,Object bean){
|
||||
// 获取BeanFactory
|
||||
DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory) context.getAutowireCapableBeanFactory();
|
||||
// 创建Bean信息
|
||||
GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
|
||||
beanDefinition.setBeanClass(bean.getClass());
|
||||
beanDefinition.setInstanceSupplier(() -> bean);
|
||||
// 注入Bean
|
||||
beanFactory.registerBeanDefinition(beanName, beanDefinition);
|
||||
}
|
||||
}
|
||||
+139
@@ -0,0 +1,139 @@
|
||||
package org.dromara.neutrinoproxy.client.starter.util;
|
||||
|
||||
import com.jcraft.jsch.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.io.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
/**
|
||||
* 远程发布工具类
|
||||
* @author: gc.x
|
||||
* @date: 2024/1/21
|
||||
*/
|
||||
@Slf4j
|
||||
public class RemoteDeployUtil {
|
||||
|
||||
public static void uploadAndStartJar(List<String> localFilePaths, String remoteDirectory, String remoteStartCommand,
|
||||
String remoteUsername, String remoteHost, String remotePassword) {
|
||||
log.info("Start=================");
|
||||
JSch jsch = new JSch();
|
||||
Session session = null;
|
||||
ChannelSftp channelSftp = null;
|
||||
try {
|
||||
session = jsch.getSession(remoteUsername, remoteHost, 22);
|
||||
session.setPassword(remotePassword);
|
||||
session.setConfig("StrictHostKeyChecking", "no");
|
||||
session.connect();
|
||||
channelSftp = (ChannelSftp) session.openChannel("sftp");
|
||||
channelSftp.connect();
|
||||
// 创建远程目录(如果不存在)
|
||||
try {
|
||||
channelSftp.cd(remoteDirectory);
|
||||
} catch (SftpException e) {
|
||||
channelSftp.mkdir(remoteDirectory);
|
||||
channelSftp.cd(remoteDirectory);
|
||||
}
|
||||
// 上传本地文件到远程服务器指定目录
|
||||
for (String localFilePath : localFilePaths) {
|
||||
uploadFileWithProgress(channelSftp, localFilePath, remoteDirectory);
|
||||
}
|
||||
channelSftp.disconnect();
|
||||
// 执行远程命令启动jar包
|
||||
log.info("Command:"+remoteStartCommand);
|
||||
ChannelExec channelExec = (ChannelExec) session.openChannel("exec");
|
||||
channelExec.setCommand(remoteStartCommand);
|
||||
ByteArrayOutputStream commandOutput = new ByteArrayOutputStream();
|
||||
channelExec.setOutputStream(commandOutput);
|
||||
channelExec.connect();
|
||||
// 使用新线程读取并打印命令输出
|
||||
Thread outputThread = new Thread(() -> {
|
||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(channelExec.getInputStream()))) {
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
System.out.println(line);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
outputThread.start();
|
||||
// 等待命令执行完成
|
||||
while (!channelExec.isClosed()) {
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
// 等待命令输出线程结束
|
||||
outputThread.join();
|
||||
channelExec.disconnect();
|
||||
log.info("=================End");
|
||||
} catch (JSchException | SftpException | InterruptedException | IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (channelSftp != null) {
|
||||
channelSftp.disconnect();
|
||||
}
|
||||
if (session != null) {
|
||||
session.disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void uploadFileWithProgress(ChannelSftp channelSftp, String localFilePath, String remoteDirectory) throws SftpException, IOException {
|
||||
File file = new File(localFilePath);
|
||||
String fileName = file.getName();
|
||||
String remoteFilePath = remoteDirectory + File.separator + fileName;
|
||||
AtomicLong uploadedSize = new AtomicLong();
|
||||
try (InputStream inputStream = new FileInputStream(file)) {
|
||||
// 如果远程目录已经存在同名文件,则先备份原文件
|
||||
if (fileExists(channelSftp, remoteFilePath)) {
|
||||
backupRemoteFile(channelSftp, remoteFilePath);
|
||||
}
|
||||
channelSftp.put(inputStream, remoteFilePath, new SftpProgressMonitor() {
|
||||
@Override
|
||||
public void init(int op, String src, String dest, long max) {
|
||||
// 初始化回调函数,可以做一些准备工作
|
||||
}
|
||||
@Override
|
||||
public void end() {
|
||||
// 上传结束回调函数,可以做一些清理工作
|
||||
}
|
||||
@Override
|
||||
public boolean count(long count) {
|
||||
uploadedSize.addAndGet(count);
|
||||
// 计算上传进度
|
||||
int progress = (int) ((uploadedSize.get() * 100) / file.length());
|
||||
|
||||
// 每上传 10% 显示一次进度,可根据实际情况调整
|
||||
if (progress % 10 == 0) {
|
||||
log.info(fileName+"-----Upload progress: " + progress + "%");
|
||||
}
|
||||
// 返回 true 则继续传输,否则中止传输
|
||||
return true;
|
||||
}
|
||||
}, ChannelSftp.RESUME);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean fileExists(ChannelSftp channelSftp, String remoteFilePath) {
|
||||
try {
|
||||
channelSftp.lstat(remoteFilePath);
|
||||
return true;
|
||||
} catch (SftpException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static void backupRemoteFile(ChannelSftp channelSftp, String remoteFilePath) throws SftpException {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
|
||||
String backupTime = now.format(formatter);
|
||||
String backupFilePath = remoteFilePath + "." + backupTime;
|
||||
channelSftp.rename(remoteFilePath, backupFilePath);
|
||||
log.info("Remote file already exists. Backing up the original file as: " + backupFilePath);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
+122
@@ -0,0 +1,122 @@
|
||||
package org.dromara.neutrinoproxy.client.starter.util;
|
||||
|
||||
import com.jcraft.jsch.*;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Scanner;
|
||||
/**
|
||||
* 简易ssh客户端
|
||||
* @author: gc.x
|
||||
* @date: 2024/1/21
|
||||
*/
|
||||
public class SSHClient {
|
||||
|
||||
private static final String COMMAND_UPLOAD = "upload";
|
||||
private Session session;
|
||||
|
||||
public void connect(String remoteHost, String remoteUsername, String remotePassword) {
|
||||
JSch jsch = new JSch();
|
||||
try {
|
||||
session = jsch.getSession(remoteUsername, remoteHost, 22);
|
||||
session.setPassword(remotePassword);
|
||||
session.setConfig("StrictHostKeyChecking", "no");
|
||||
session.connect();
|
||||
System.out.println("Connected to " + remoteHost);
|
||||
} catch (JSchException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
public void startShell() {
|
||||
if (session == null || !session.isConnected()) {
|
||||
System.out.println("Not connected to a remote host");
|
||||
return;
|
||||
}
|
||||
Channel channel;
|
||||
try {
|
||||
channel = session.openChannel("shell");
|
||||
channel.connect();
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
String line;
|
||||
while (true) {
|
||||
System.out.print("$ ");
|
||||
line = scanner.nextLine();
|
||||
if (line.equals("exit")) {
|
||||
break;
|
||||
} else if (line.startsWith(COMMAND_UPLOAD)) {
|
||||
processUploadCommand(line);
|
||||
} else {
|
||||
System.out.println("Executing command: " + line);
|
||||
executeCommand(line);
|
||||
}
|
||||
}
|
||||
} catch (JSchException e) {
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
public void disconnect() {
|
||||
if (session != null && session.isConnected()) {
|
||||
session.disconnect();
|
||||
System.out.println("Disconnected from remote host");
|
||||
}
|
||||
}
|
||||
|
||||
private void processUploadCommand(String command) {
|
||||
String[] parts = command.split("\\s+");
|
||||
if (parts.length < 3) {
|
||||
System.out.println("Invalid upload command");
|
||||
return;
|
||||
}
|
||||
String localFilePath = parts[1];
|
||||
String remoteDirectory = parts[2];
|
||||
String remoteFilename = Paths.get(localFilePath).getFileName().toString();
|
||||
if (parts.length >= 4) {
|
||||
remoteFilename = parts[3];
|
||||
}
|
||||
uploadFile(localFilePath, remoteDirectory, remoteFilename);
|
||||
}
|
||||
|
||||
private void uploadFile(String localFilePath, String remoteDirectory, String remoteFilename) {
|
||||
ChannelSftp channelSftp = null;
|
||||
try {
|
||||
channelSftp = (ChannelSftp) session.openChannel("sftp");
|
||||
channelSftp.connect();
|
||||
channelSftp.cd(remoteDirectory);
|
||||
System.out.println("Uploading file: " + localFilePath + " to: " + remoteDirectory + "/" + remoteFilename);
|
||||
channelSftp.put(localFilePath, remoteFilename);
|
||||
System.out.println("File uploaded successfully");
|
||||
} catch (JSchException | SftpException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (channelSftp != null) {
|
||||
channelSftp.disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
private void executeCommand(String command) {
|
||||
ChannelExec channelExec = null;
|
||||
|
||||
try {
|
||||
channelExec = (ChannelExec) session.openChannel("exec");
|
||||
channelExec.setCommand(command);
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(channelExec.getInputStream()));
|
||||
channelExec.connect();
|
||||
String line;
|
||||
while ((line = in.readLine()) != null) {
|
||||
System.out.println(line);
|
||||
}
|
||||
channelExec.disconnect();
|
||||
} catch (JSchException | IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (channelExec != null) {
|
||||
channelExec.disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
server:
|
||||
port: 8201
|
||||
spring:
|
||||
application:
|
||||
name: neutrino-proxy-client
|
||||
neutrino:
|
||||
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: 120
|
||||
write-idle-time: 20
|
||||
all-idle-time-seconds: 0
|
||||
tunnel:
|
||||
# 线程池相关配置,用于技术调优,可忽略
|
||||
thread-count: 50
|
||||
# 隧道SSL证书配置
|
||||
key-store-password: ${STORE_PASS:123456}
|
||||
jks-path: ${JKS_PATH:classpath:/test.jks}
|
||||
# 服务端IP
|
||||
server-ip: ${SERVER_IP:}
|
||||
# 服务端端口(对应服务端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}
|
||||
# 是否开启心跳日志
|
||||
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}
|
||||
enable: true
|
||||
sshEnable: false
|
||||
sshProxys[0]:
|
||||
host:
|
||||
username:
|
||||
password:
|
||||
localPort:
|
||||
remotePort:
|
||||
remoteHost:
|
||||
|
||||
@@ -1,39 +1,36 @@
|
||||
"use strict";
|
||||
const path = require("path");
|
||||
const utils = require("./utils");
|
||||
const webpack = require("webpack");
|
||||
const config = require("../config");
|
||||
const merge = require("webpack-merge");
|
||||
const baseWebpackConfig = require("./webpack.base.conf");
|
||||
const HtmlWebpackPlugin = require("html-webpack-plugin");
|
||||
const FriendlyErrorsPlugin = require("friendly-errors-webpack-plugin");
|
||||
const portfinder = require("portfinder");
|
||||
'use strict'
|
||||
const path = require('path')
|
||||
const utils = require('./utils')
|
||||
const webpack = require('webpack')
|
||||
const config = require('../config')
|
||||
const merge = require('webpack-merge')
|
||||
const baseWebpackConfig = require('./webpack.base.conf')
|
||||
const HtmlWebpackPlugin = require('html-webpack-plugin')
|
||||
const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin')
|
||||
const portfinder = require('portfinder')
|
||||
|
||||
function resolve(dir) {
|
||||
return path.join(__dirname, "..", dir);
|
||||
function resolve (dir) {
|
||||
return path.join(__dirname, '..', dir)
|
||||
}
|
||||
|
||||
const HOST = process.env.HOST;
|
||||
const PORT = process.env.PORT && Number(process.env.PORT);
|
||||
const HOST = process.env.HOST
|
||||
const PORT = process.env.PORT && Number(process.env.PORT)
|
||||
|
||||
const devWebpackConfig = merge(baseWebpackConfig, {
|
||||
module: {
|
||||
rules: utils.styleLoaders({
|
||||
sourceMap: config.dev.cssSourceMap,
|
||||
usePostCSS: true
|
||||
})
|
||||
rules: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap, usePostCSS: true })
|
||||
},
|
||||
// cheap-module-eval-source-map is faster for development
|
||||
devtool: config.dev.devtool,
|
||||
|
||||
// these devServer options should be customized in /config/index.js
|
||||
devServer: {
|
||||
clientLogLevel: "warning",
|
||||
clientLogLevel: 'warning',
|
||||
historyApiFallback: true,
|
||||
hot: true,
|
||||
compress: true,
|
||||
host: HOST || config.dev.host,
|
||||
port: PORT || config.dev.port,
|
||||
allowedHosts: ["localhost", "server.com", ".server.com"],
|
||||
open: config.dev.autoOpenBrowser,
|
||||
overlay: config.dev.errorOverlay
|
||||
? { warnings: false, errors: true }
|
||||
@@ -42,54 +39,50 @@ const devWebpackConfig = merge(baseWebpackConfig, {
|
||||
proxy: config.dev.proxyTable,
|
||||
quiet: true, // necessary for FriendlyErrorsPlugin
|
||||
watchOptions: {
|
||||
poll: config.dev.poll
|
||||
poll: config.dev.poll,
|
||||
}
|
||||
},
|
||||
plugins: [
|
||||
new webpack.DefinePlugin({
|
||||
"process.env": require("../config/local.env")
|
||||
'process.env': require('../config/local.env')
|
||||
}),
|
||||
new webpack.HotModuleReplacementPlugin(),
|
||||
new webpack.NamedModulesPlugin(), // HMR shows correct file names in console on update.
|
||||
new webpack.NoEmitOnErrorsPlugin(),
|
||||
// https://github.com/ampedandwired/html-webpack-plugin
|
||||
new HtmlWebpackPlugin({
|
||||
filename: "index.html",
|
||||
template: "index.html",
|
||||
filename: 'index.html',
|
||||
template: 'index.html',
|
||||
inject: true,
|
||||
favicon: resolve("favicon.ico"),
|
||||
title: "vue-element-admin",
|
||||
favicon: resolve('favicon.ico'),
|
||||
title: 'vue-element-admin',
|
||||
path: config.dev.assetsPublicPath + config.dev.assetsSubDirectory
|
||||
})
|
||||
}),
|
||||
]
|
||||
});
|
||||
})
|
||||
|
||||
module.exports = new Promise((resolve, reject) => {
|
||||
portfinder.basePort = process.env.PORT || config.dev.port;
|
||||
portfinder.basePort = process.env.PORT || config.dev.port
|
||||
portfinder.getPort((err, port) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
reject(err)
|
||||
} else {
|
||||
// publish the new Port, necessary for e2e tests
|
||||
process.env.PORT = port;
|
||||
process.env.PORT = port
|
||||
// add port to devServer config
|
||||
devWebpackConfig.devServer.port = port;
|
||||
console.log('devWebpackConfig', devWebpackConfig)
|
||||
// Add FriendlyErrorsPlugin
|
||||
devWebpackConfig.plugins.push(
|
||||
new FriendlyErrorsPlugin({
|
||||
compilationSuccessInfo: {
|
||||
messages: [
|
||||
`Your application is running here: http://${devWebpackConfig.devServer.host}:${port}`
|
||||
]
|
||||
},
|
||||
onErrors: config.dev.notifyOnErrors
|
||||
? utils.createNotifierCallback()
|
||||
: undefined
|
||||
})
|
||||
);
|
||||
devWebpackConfig.devServer.port = port
|
||||
|
||||
resolve(devWebpackConfig);
|
||||
// Add FriendlyErrorsPlugin
|
||||
devWebpackConfig.plugins.push(new FriendlyErrorsPlugin({
|
||||
compilationSuccessInfo: {
|
||||
messages: [`Your application is running here: http://${devWebpackConfig.devServer.host}:${port}`],
|
||||
},
|
||||
onErrors: config.dev.notifyOnErrors
|
||||
? utils.createNotifierCallback()
|
||||
: undefined
|
||||
}))
|
||||
|
||||
resolve(devWebpackConfig)
|
||||
}
|
||||
});
|
||||
});
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
module.exports = {
|
||||
NODE_ENV: '"development"',
|
||||
ENV_CONFIG: '"dev"',
|
||||
BASE_API: '"http://localhost:8888/neutrino-proxy-server"',
|
||||
BASE_API: '"https://neutrino-proxy.asgc.fun/neutrino-proxy-server"',
|
||||
USER_NAME: '"visitor"',
|
||||
USER_PWD: '"123456"'
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ module.exports = {
|
||||
assetsSubDirectory: 'static',
|
||||
assetsPublicPath: '/',
|
||||
proxyTable: {},
|
||||
|
||||
// Various Dev Server settings
|
||||
host: 'localhost', // can be overwritten by process.env.HOST
|
||||
port: 9527, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
|
||||
@@ -55,8 +56,8 @@ module.exports = {
|
||||
assetsRoot: path.resolve(__dirname, '../dist'),
|
||||
assetsSubDirectory: 'static',
|
||||
|
||||
// you can set by youself according to actual condition
|
||||
assetsPublicPath: '/',
|
||||
// you can set by youself according to actual condition
|
||||
assetsPublicPath: './',
|
||||
|
||||
/**
|
||||
* Source Maps
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
module.exports = {
|
||||
NODE_ENV: '"production"',
|
||||
ENV_CONFIG: '"prod"',
|
||||
BASE_API: '"http://np.myone.cc"' // 后端访问地址与 server配置一致
|
||||
BASE_API: '"https://api-prod"'
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
"showdown": "1.8.5",
|
||||
"simplemde": "1.11.2",
|
||||
"sortablejs": "1.7.0",
|
||||
"vue": "2.5.17",
|
||||
"vue": "2.5.10",
|
||||
"vue-count-to": "1.0.13",
|
||||
"vue-i18n": "7.3.2",
|
||||
"vue-multiselect": "2.0.8",
|
||||
@@ -70,7 +70,7 @@
|
||||
"friendly-errors-webpack-plugin": "1.6.1",
|
||||
"html-webpack-plugin": "2.30.1",
|
||||
"node-notifier": "5.1.2",
|
||||
"node-sass": "4.13.1",
|
||||
"node-sass": "^9.0.0",
|
||||
"optimize-css-assets-webpack-plugin": "3.2.0",
|
||||
"ora": "1.3.0",
|
||||
"portfinder": "1.0.13",
|
||||
@@ -88,7 +88,7 @@
|
||||
"url-loader": "0.6.2",
|
||||
"vue-loader": "13.5.0",
|
||||
"vue-style-loader": "3.0.3",
|
||||
"vue-template-compiler": "2.5.17",
|
||||
"vue-template-compiler": "2.5.10",
|
||||
"webpack": "3.10.0",
|
||||
"webpack-bundle-analyzer": "2.9.1",
|
||||
"webpack-dev-server": "2.9.7",
|
||||
|
||||
@@ -1,61 +1,8 @@
|
||||
import request from '@/utils/request'
|
||||
|
||||
|
||||
export function fetchList(query) {
|
||||
export function domainNameBindInfo(query) {
|
||||
return request({
|
||||
url: '/domain/page',
|
||||
method: 'get',
|
||||
params: query
|
||||
})
|
||||
}
|
||||
|
||||
export function mappingModify(data) {
|
||||
return request({
|
||||
url: '/domain/modify',
|
||||
method: 'post',
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
export function deleteMapping(id) {
|
||||
return request({
|
||||
url: '/domain/delete/' + id,
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
|
||||
export function updateEnableStatus(id, enable) {
|
||||
return request({
|
||||
url: '/domain/update/enable-status',
|
||||
method: 'post',
|
||||
data: {
|
||||
id: id,
|
||||
enable: enable
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export function portMappingBindSecurityGroup(id, securityGroupId) {
|
||||
return request({
|
||||
url: '/domain/bind/security-group',
|
||||
method: 'post',
|
||||
data: {
|
||||
id: id,
|
||||
securityGroupId: securityGroupId
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export function portMappingUnbindSecurityGroup(id) {
|
||||
return request({
|
||||
url: `/domain/unbind/security-group?id=${id}`,
|
||||
method: 'post'
|
||||
})
|
||||
}
|
||||
|
||||
export function domainAvailable(query) {
|
||||
return request({
|
||||
url: '/domain/available',
|
||||
url: '/domain-name/bind-info',
|
||||
method: 'get',
|
||||
params: query
|
||||
})
|
||||
|
||||
@@ -54,24 +54,6 @@
|
||||
prop: 'name',
|
||||
label: 'License',
|
||||
align: 'center'
|
||||
},
|
||||
{
|
||||
prop: 'isOnline',
|
||||
label: 'isOnline',
|
||||
align: 'center',
|
||||
render: (h, params) => {
|
||||
switch (params.row.isOnline) {
|
||||
case 1:
|
||||
return h('el-tag', {
|
||||
props: {type: 'success'}
|
||||
}, '在线')
|
||||
|
||||
case 2:
|
||||
return h('el-tag', {props:{type: 'danger'}}, '离线')
|
||||
default:
|
||||
return h('el-tag', {props:{type: 'danger'}}, '离线')
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
popVisible: false,
|
||||
|
||||
@@ -55,7 +55,6 @@ export default {
|
||||
proxy: '代理配置',
|
||||
license: 'License管理',
|
||||
portMapping: '端口映射',
|
||||
domainMapping: '域名解析',
|
||||
jobManager: '调度管理',
|
||||
jobLog: '调度日志',
|
||||
log: '日志管理',
|
||||
|
||||
@@ -61,8 +61,7 @@ export const asyncRouterMap = [
|
||||
},
|
||||
children: [
|
||||
{ path: 'license', component: _import('proxy/license'), name: 'license', meta: { title: 'license' }},
|
||||
{ path: 'portMapping', component: _import('proxy/portMapping'), name: 'portMapping', meta: { title: 'portMapping' }},
|
||||
{ path: 'domainMapping', component: _import('proxy/domainMapping'), name: 'domainMapping', meta: { title: 'domainMapping' }}
|
||||
{ path: 'portMapping', component: _import('proxy/portMapping'), name: 'portMapping', meta: { title: 'portMapping' }}
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -1,408 +0,0 @@
|
||||
<template>
|
||||
<div class="app-container calendar-list-container">
|
||||
<div class="filter-container" style="display:flex">
|
||||
<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" 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;">
|
||||
<el-option v-for="item in protocalList" :key="item.name" :label="item.name" :value="item.name" :disabled="!item.enable" />
|
||||
</el-select> -->
|
||||
<el-input v-model="listQuery.domain" type="text" style="width:145px;margin-right:10px" class="filter-item" placeholder="请输入域名关键词" />
|
||||
<el-select v-model="listQuery.isOnline" placeholder="请选择在线状态" clearable style="width:145px;margin-right:10px">
|
||||
<el-option v-for="(value, key) in onlineOptions" :key="key" :label="value" :value="key" />
|
||||
</el-select>
|
||||
<el-select v-model="listQuery.enable" placeholder="请选择启用状态" clearable style="width:145px;margin-right:10px">
|
||||
<el-option v-for="(value, key) in statusOptions" :key="key" :label="value" :value="key" />
|
||||
</el-select>
|
||||
<el-input v-model="listQuery.description" type="text" style="width:145px;margin-right:10px" class="filter-item" placeholder="请输入描述详情" show-word-limit />
|
||||
<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>
|
||||
</div>
|
||||
|
||||
<el-table :key='tableKey' :data="list" v-loading="listLoading" element-loading-text="给我一点时间" border fit highlight-current-row style="width: 100%">
|
||||
<el-table-column align="center" :label="$t('table.id')" width="80">
|
||||
<template slot-scope="scope">
|
||||
<span>{{ scope.row.id }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column align="center" :label="$t('table.userName')" width="80">
|
||||
<template slot-scope="scope">
|
||||
<span>{{ scope.row.userName }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column align="center" :label="$t('table.licenseName')" width="140">
|
||||
<template slot-scope="scope">
|
||||
<span>{{ scope.row.licenseName }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column align="center" :label="$t('table.protocalName')" width="80">
|
||||
<template slot-scope="scope">
|
||||
<span>{{ scope.row.protocal }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column align="center" :label="$t('table.desc')" width="180">
|
||||
<template slot-scope="scope">
|
||||
<span>{{ scope.row.description }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column align="left" :label="$t('table.domainName')" width="180">
|
||||
<template slot-scope="scope">
|
||||
<el-link target="_blank" @click="handleOpenWebPage(scope.row)">http(s)://{{ scope.row.domain }}</el-link>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column align="center" :label="$t('目标路径')" width="240">
|
||||
<template slot-scope="scope">
|
||||
<span v-html="scope.row.targetPath.replace(/(\n\r|\r\n|\r|\n)/g, '<br/>')"> </span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column align="center" :label="$t('限速')" width="160">
|
||||
<template slot-scope="scope">
|
||||
<span>{{ scope.row.upLimitRate ? scope.row.upLimitRate : '--' }} / {{ scope.row.downLimitRate ? scope.row.downLimitRate : '--' }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<!-- <el-table-column width="150px" align="center" :label="$t('table.createTime')">-->
|
||||
<!-- <template slot-scope="scope">-->
|
||||
<!-- <span>{{ scope.row.createTime | parseTime('{y}-{m}-{d} {h}:{i}') }}</span>-->
|
||||
<!-- </template>-->
|
||||
<!-- </el-table-column>-->
|
||||
<el-table-column width="150px" align="center" :label="$t('table.updateTime')">
|
||||
<template slot-scope="scope">
|
||||
<span>{{ scope.row.updateTime | parseTime('{y}-{m}-{d} {h}:{i}') }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column class-name="status-col" :label="$t('table.enableStatus')" width="100">
|
||||
<template slot-scope="scope">
|
||||
<el-tag :type="colorOption[scope.row.enable]">{{ statusOptions[scope.row.enable] }}</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column class-name="status-col" :label="$t('table.isOnline')" width="100">
|
||||
<template slot-scope="scope">
|
||||
<el-tag :type="colorOption[scope.row.isOnline]">{{ onlineOptions[scope.row.isOnline] }}</el-tag>
|
||||
</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="toModify(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 == '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)">{{ $t('table.delete') }}</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<div class="pagination-container">
|
||||
<el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-pageInfo.sync="listQuery.current" :pageInfo-sizes="[10, 20, 30, 50]"
|
||||
:pageInfo-size="listQuery.size" layout="total, sizes, prev, pager, next, jumper" :total="total">
|
||||
</el-pagination>
|
||||
</div>
|
||||
|
||||
<el-dialog :title="textMap[dialogStatus]" :close-on-click-modal="false" :visible.sync="dialogFormVisible" top="20px">
|
||||
<el-form :rules="rules" ref="dataForm" :model="temp" label-position="right" label-width="110px">
|
||||
<el-form-item :label="$t('License')" prop="licenseId">
|
||||
<DropdownTable v-model="temp.licenseId" :name.sync="temp.licenseName" :tableData="licenseAuthList" @selectedData="selectedFeeItem" placeholder="请选择" :width="500" />
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('域名')" prop="domain">
|
||||
<el-input v-model="temp.domain">
|
||||
<template slot="prepend">http(s)://</template>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('目标地址')" prop="targetPath">
|
||||
<el-input type="textarea" v-model="temp.targetPath" rows="3" placeholder="请输入目标地址,多个可实现负载均衡,如:
|
||||
127.0.0.1:80
|
||||
127.0.0.1:90"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('描述')" prop="description">
|
||||
<el-input v-model="temp.description" type="textarea" placeholder="请输入描述"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('请求头部信息')" prop="requestHeader">
|
||||
<el-input v-model="temp.requestHeader" type="textarea" placeholder="请输入请求头如:Cache-Control: no-cache"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('table.securityGroup')" prop="securityGroup">
|
||||
<el-select style="width: 280px;" class="filter-item" v-model="temp.securityGroupId" clearable>
|
||||
<el-option v-for="item in securityGroupList" :key="item.id" :label="item.name" :value="item.id">
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('上传限速')" prop="upLimitRate">
|
||||
<el-input v-model="temp.upLimitRate" placeholder="如:10240B、500K、1M"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('下载限速')" prop="downLimitRate">
|
||||
<el-input v-model="temp.downLimitRate" placeholder="如:10240B、500K、1M"></el-input>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<div slot="footer" class="dialog-footer">
|
||||
<el-button @click="dialogFormVisible = false">{{ $t('table.cancel') }}</el-button>
|
||||
<el-button v-if="dialogStatus == 'create'" type="primary" @click="modifyData">{{ $t('table.confirm')
|
||||
}}</el-button>
|
||||
<el-button v-else type="primary" @click="modifyData">{{ $t('table.confirm') }}</el-button>
|
||||
</div>
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog title="Reading statistics" :visible.sync="dialogPvVisible">
|
||||
<el-table :data="pvData" border fit highlight-current-row style="width: 100%">
|
||||
<el-table-column prop="key" label="Channel"> </el-table-column>
|
||||
<el-table-column prop="pv" label="Pv"> </el-table-column>
|
||||
</el-table>
|
||||
<span slot="footer" class="dialog-footer">
|
||||
<el-button type="primary" @click="dialogPvVisible = false">{{ $t('table.confirm') }}</el-button>
|
||||
</span>
|
||||
</el-dialog>
|
||||
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { fetchList, mappingModify, updateEnableStatus, deleteMapping, domainAvailable } from '@/api/domain'
|
||||
import { fetchGroupList } from '@/api/securityGroup'
|
||||
import { licenseList, licenseAuthList } from '@/api/license'
|
||||
import { userList } from '@/api/user'
|
||||
import waves from '@/directive/waves' // 水波纹指令
|
||||
import { parseTime } from '@/utils'
|
||||
import ButtonPopover from '../../components/Button/buttonPopover'
|
||||
import DropdownTable from '../../components/Dropdown/DropdownTable'
|
||||
export default {
|
||||
name: 'DmainMaping',
|
||||
directives: {
|
||||
waves
|
||||
},
|
||||
components: {
|
||||
DropdownTable,
|
||||
ButtonPopover
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
tableKey: 0,
|
||||
list: null,
|
||||
total: null,
|
||||
listLoading: true,
|
||||
listQuery: {
|
||||
current: 1,
|
||||
size: 10,
|
||||
domain: null,
|
||||
title: undefined,
|
||||
type: undefined,
|
||||
userId: undefined,
|
||||
license: undefined,
|
||||
port: undefined,
|
||||
isOnline: undefined,
|
||||
enable: undefined,
|
||||
description: undefined
|
||||
},
|
||||
userList: [],
|
||||
licenseList: [],
|
||||
licenseAuthList: [],
|
||||
showReviewer: false,
|
||||
temp: {
|
||||
id: undefined,
|
||||
licenseId: undefined,
|
||||
licenseName: undefined,
|
||||
domain: undefined,
|
||||
targetPath: undefined,
|
||||
requestHeader: undefined
|
||||
},
|
||||
statusOptions: {
|
||||
1: '启用',
|
||||
2: '禁用',
|
||||
},
|
||||
onlineOptions: {
|
||||
1: '在线',
|
||||
2: '离线'
|
||||
},
|
||||
colorOption: {
|
||||
1: 'success',
|
||||
2: 'danger'
|
||||
},
|
||||
dialogFormVisible: false,
|
||||
dialogStatus: '',
|
||||
textMap: {
|
||||
update: '编辑',
|
||||
create: '新增'
|
||||
},
|
||||
dialogPvVisible: false,
|
||||
pvData: [],
|
||||
rules: {
|
||||
licenseId: [{ required: true, message: '请选择License', trigger: 'blur,change' }],
|
||||
domain: [{ required: true, message: '请输入域名', trigger: 'blur' },
|
||||
{ pattern: '^(?=^.{3,255}$)[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+$', message: '域名格式不正确,请检查后重试', trigger: 'blur' },
|
||||
{ validator: this.isDomainAvailable, trigger: 'blur' }
|
||||
],
|
||||
targetPath: [{ required: true, message: '请输入目标地址', trigger: 'blur' }],
|
||||
},
|
||||
more: true,
|
||||
securityGroupList: []
|
||||
}
|
||||
},
|
||||
// filters: {
|
||||
// },
|
||||
created() {
|
||||
this.getDataList()
|
||||
this.getLicenseList()
|
||||
this.getLicenseAuthList()
|
||||
this.fetchSecurityGroupList()
|
||||
},
|
||||
methods: {
|
||||
isDomainAvailable(rule, value, callback) {
|
||||
if (value != null) {
|
||||
const param = { domain: value, id: this.temp.id }
|
||||
domainAvailable(param).then(res => {
|
||||
console.log(res)
|
||||
if (!res.data.data) {
|
||||
return callback(new Error('域名已被占用'))
|
||||
} else {
|
||||
callback()
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
getList() {
|
||||
this.listLoading = true
|
||||
fetchList(this.listQuery).then(response => {
|
||||
this.list = response.data.data.records
|
||||
this.total = response.data.data.total
|
||||
this.listLoading = false
|
||||
})
|
||||
},
|
||||
getDataList() {
|
||||
const loginName = this.$store.state.user.loginName
|
||||
userList().then(response => {
|
||||
this.userList = response.data.data
|
||||
const curUser = this.userList.find((val) => val.loginName === loginName)
|
||||
if (curUser) {
|
||||
this.listQuery.userId = curUser.id
|
||||
}
|
||||
this.getList()
|
||||
})
|
||||
},
|
||||
fetchSecurityGroupList() {
|
||||
fetchGroupList().then(res => {
|
||||
if (res.data.code == 0) {
|
||||
this.securityGroupList = res.data.data
|
||||
}
|
||||
})
|
||||
},
|
||||
getAllUserList() {
|
||||
userList().then(response => {
|
||||
this.userList = response.data.data
|
||||
})
|
||||
},
|
||||
getLicenseList() {
|
||||
licenseList().then(response => {
|
||||
this.licenseList = response.data.data
|
||||
})
|
||||
},
|
||||
getLicenseAuthList() {
|
||||
licenseAuthList().then(response => {
|
||||
this.licenseAuthList = response.data.data
|
||||
})
|
||||
},
|
||||
handleFilter() {
|
||||
this.listQuery.current = 1
|
||||
this.getList()
|
||||
},
|
||||
handleSizeChange(val) {
|
||||
this.listQuery.size = val
|
||||
this.getList()
|
||||
},
|
||||
handleCurrentChange(val) {
|
||||
this.listQuery.current = val
|
||||
this.getList()
|
||||
},
|
||||
handleModifyStatus(row, enable) {
|
||||
console.log('route', this.$route)
|
||||
updateEnableStatus(row.id, enable).then(response => {
|
||||
if (response.data.data.code === 0) {
|
||||
this.$message({
|
||||
message: '操作成功',
|
||||
type: 'success'
|
||||
})
|
||||
}
|
||||
this.getList()
|
||||
})
|
||||
},
|
||||
resetTemp() {
|
||||
this.temp = {
|
||||
id: undefined,
|
||||
licenseId: undefined,
|
||||
licenseName: undefined,
|
||||
clientIp: '127.0.0.1',
|
||||
clientPort: undefined,
|
||||
userId: undefined,
|
||||
proxyResponses: undefined,
|
||||
proxyTimeoutMs: undefined
|
||||
}
|
||||
this.more = true;
|
||||
},
|
||||
handleCreate() {
|
||||
this.resetTemp()
|
||||
this.dialogStatus = 'create'
|
||||
this.dialogFormVisible = true
|
||||
this.$nextTick(() => {
|
||||
this.$refs['dataForm'].clearValidate()
|
||||
})
|
||||
},
|
||||
modifyData() {
|
||||
this.$refs['dataForm'].validate((valid) => {
|
||||
if (valid) {
|
||||
mappingModify(this.temp).then(response => {
|
||||
if (response.data.code === 0) {
|
||||
this.dialogFormVisible = false
|
||||
this.$notify({
|
||||
title: '成功',
|
||||
message: '操作成功',
|
||||
type: 'success',
|
||||
duration: 2000
|
||||
})
|
||||
this.getList()
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
handleOpenWebPage(row) {
|
||||
open(location.protocol + '//' + row.domain)
|
||||
},
|
||||
toModify(row) {
|
||||
this.temp = Object.assign({}, row) // copy obj
|
||||
if (row.securityGroupId === 0) {
|
||||
this.temp.securityGroupId = null
|
||||
}
|
||||
this.temp.timestamp = new Date(this.temp.timestamp)
|
||||
this.dialogStatus = 'update'
|
||||
this.dialogFormVisible = true
|
||||
this.$nextTick(() => {
|
||||
this.$refs['dataForm'].clearValidate()
|
||||
})
|
||||
},
|
||||
selectedFeeItem(row, list) {
|
||||
if (this.temp.licenseId !== row.id) {
|
||||
this.temp.licenseId = row.id
|
||||
this.temp.licenseName = row.name
|
||||
this.temp.serverPort = null
|
||||
}
|
||||
},
|
||||
handleDelete(row) {
|
||||
this.$confirm('确定要删除吗?', '提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}).then(() => {
|
||||
deleteMapping(row.id).then(response => {
|
||||
if (response.data.code === 0) {
|
||||
this.$notify({
|
||||
title: '成功',
|
||||
message: '删除成功',
|
||||
type: 'success',
|
||||
duration: 2000
|
||||
})
|
||||
this.getList()
|
||||
}
|
||||
})
|
||||
}).catch(() => { })
|
||||
},
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -63,13 +63,12 @@
|
||||
</el-table-column>
|
||||
<el-table-column align="center" :label="$t('table.actions')" width="330" class-name="small-padding fixed-width">
|
||||
<template slot-scope="scope">
|
||||
<!-- v-if="scope.row.id != 1" -->
|
||||
<el-button type="primary" size="mini" @click="handleUpdate(scope.row)">{{$t('table.edit')}}</el-button>
|
||||
<el-button size="mini" type="primary" @click="handleReset(scope.row)">{{$t('table.resetKey')}}</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>
|
||||
<!-- v-if="scope.row.id != 1" -->
|
||||
<el-button size="mini" type="danger" @click="handleDelete(scope.row)">{{$t('table.delete')}}</el-button>
|
||||
<!-- <el-button size="mini" type="danger" @click="handleDelete(scope.row,'deleted')">{{$t('table.delete')}}</el-button>-->
|
||||
<ButtonPopover @handleCommitClick="handleDelete2(scope.row)" style="margin-left: 10px"/>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
@@ -123,6 +122,20 @@
|
||||
import { userList } from '@/api/user'
|
||||
import waves from '@/directive/waves' // 水波纹指令
|
||||
import { parseTime } from '@/utils'
|
||||
import ButtonPopover from '../../components/Button/buttonPopover'
|
||||
|
||||
const calendarTypeOptions = [
|
||||
{ key: 'CN', display_name: 'China' },
|
||||
{ key: 'US', display_name: 'USA' },
|
||||
{ key: 'JP', display_name: 'Japan' },
|
||||
{ key: 'EU', display_name: 'Eurozone' }
|
||||
]
|
||||
|
||||
// arr to obj ,such as { CN : "China", US : "USA" }
|
||||
const calendarTypeKeyValue = calendarTypeOptions.reduce((acc, cur) => {
|
||||
acc[cur.key] = cur.display_name
|
||||
return acc
|
||||
}, {})
|
||||
|
||||
export default {
|
||||
name: 'complexTable',
|
||||
@@ -130,6 +143,7 @@
|
||||
waves
|
||||
},
|
||||
components: {
|
||||
ButtonPopover
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
@@ -145,6 +159,7 @@
|
||||
userId: null
|
||||
},
|
||||
importanceOptions: [1, 2, 3],
|
||||
calendarTypeOptions,
|
||||
userList: [],
|
||||
sortOptions: [{ label: 'ID Ascending', key: '+id' }, { label: 'ID Descending', key: '-id' }],
|
||||
statusOptions: ['published', 'draft', 'deleted'],
|
||||
@@ -199,6 +214,9 @@
|
||||
}
|
||||
return statusMap[status]
|
||||
},
|
||||
typeFilter(type) {
|
||||
return calendarTypeKeyValue[type]
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.getDataList()
|
||||
@@ -350,6 +368,19 @@
|
||||
})
|
||||
}).catch(() => {})
|
||||
},
|
||||
handleDelete2(row) {
|
||||
deleteLicense(row.id).then(response => {
|
||||
if (response.data.code === 0) {
|
||||
this.$notify({
|
||||
title: '成功',
|
||||
message: '删除成功',
|
||||
type: 'success',
|
||||
duration: 2000
|
||||
})
|
||||
this.getList()
|
||||
}
|
||||
})
|
||||
},
|
||||
handleDownload() {
|
||||
this.downloadLoading = true
|
||||
import('@/vendor/Export2Excel').then(excel => {
|
||||
|
||||
@@ -49,11 +49,11 @@
|
||||
<span>{{ scope.row.protocal }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<!-- <el-table-column align="center" :label="$t('table.domainName')" width="180">
|
||||
<el-table-column align="center" :label="$t('table.domainName')" width="180">
|
||||
<template slot-scope="scope">
|
||||
<span>{{ scope.row.domain }}</span>
|
||||
</template>
|
||||
</el-table-column> -->
|
||||
</el-table-column>
|
||||
<el-table-column align="center" :label="$t('table.serverPort')" width="80">
|
||||
<template slot-scope="scope">
|
||||
<span>{{ scope.row.serverPort }}</span>
|
||||
@@ -105,7 +105,9 @@
|
||||
<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 == '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)">{{$t('table.delete')}}</el-button>
|
||||
<!-- <el-button size="mini" type="danger" @click="handleDelete(scope.row,'deleted')">{{$t('table.delete')}}</el-button>-->
|
||||
<ButtonPopover @handleCommitClick="handleDelete2(scope.row)" style="margin-left: 10px" />
|
||||
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
@@ -117,22 +119,39 @@
|
||||
</el-pagination>
|
||||
</div>
|
||||
|
||||
<el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible" top="20px">
|
||||
<el-form :rules="rules" ref="dataForm" :model="temp" label-position="right" label-width="120px"
|
||||
style='width:500px;margin-left:50px;'>
|
||||
<el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible">
|
||||
<el-form :rules="rules" ref="dataForm" :model="temp" label-position="left" label-width="120px"
|
||||
style='width: 400px; margin-left:50px;'>
|
||||
<!-- <el-form-item :label="$t('License')" prop="licenseId">-->
|
||||
<!-- <el-select style="width: 280px;" class="filter-item" v-model="temp.licenseId" placeholder="请选择" :disabled="dialogStatus=='update'">-->
|
||||
<!-- <el-option v-for="item in licenseList" :key="item.id" :label="item.name" :value="item.id">-->
|
||||
<!-- </el-option>-->
|
||||
<!-- </el-select>-->
|
||||
<!-- </el-form-item>-->
|
||||
|
||||
<el-form-item :label="$t('License')" prop="licenseId">
|
||||
<DropdownTable v-model="temp.licenseId" :name.sync="temp.licenseName" :tableData="licenseAuthList"
|
||||
@selectedData="selectedFeeItem" placeholder="请选择" :width="500" :disabled="dialogStatus === 'update'" />
|
||||
@selectedData="selectedFeeItem" placeholder="请选择" :width="280" :disabled="dialogStatus === 'update'" />
|
||||
<!-- <DropdownTable
|
||||
:columns="countryColumns"
|
||||
:data="licenseList"
|
||||
v-model="temp.licenseId"
|
||||
:value="temp.licenseName"
|
||||
@rowClick="selectedFeeItem"
|
||||
disabled
|
||||
:disabled="dialogStatus==='update'"
|
||||
style="width: 280px"
|
||||
/>-->
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('协议')" prop="protocal">
|
||||
<el-select style="width: 380px;" class="filter-item" v-model="temp.protocal" placeholder="请选择">
|
||||
<el-select style="width: 280px;" class="filter-item" v-model="temp.protocal" placeholder="请选择">
|
||||
<el-option v-for="item in protocalList" :key="item.name" :label="item.name" :value="item.name"
|
||||
:disabled="!item.enable">
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('服务端端口')" prop="serverPort" >
|
||||
<load-select style="width: 380px;" class="filter-item"
|
||||
<load-select style="width: 280px;" class="filter-item"
|
||||
v-model="temp.serverPort"
|
||||
:data="serverPortList"
|
||||
:page="loadServerPortQuery.page"
|
||||
@@ -146,13 +165,13 @@
|
||||
<el-input v-model="temp.clientIp"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('客户端端口')" prop="clientPort">
|
||||
<el-input v-model="temp.clientPort" type="number" :step="1" controls-position="right" ></el-input>
|
||||
<el-input v-model="temp.clientPort"></el-input>
|
||||
</el-form-item>
|
||||
<!-- <el-form-item :label="$t('域名')" prop="subdomain" v-if="(temp.protocal === 'HTTP' || temp.protocal === 'HTTP(S)') && 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>
|
||||
<el-form-item :label="$t('响应数量')" prop="proxyResponses" v-if="temp.protocal === 'UDP'">
|
||||
<el-input v-model="temp.proxyResponses"></el-input>
|
||||
</el-form-item>
|
||||
@@ -162,7 +181,7 @@
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('table.securityGroup')" prop="securityGroup">
|
||||
<el-select style="width: 380px;" class="filter-item" v-model="temp.securityGroupId" clearable >
|
||||
<el-select style="width: 280px;" class="filter-item" v-model="temp.securityGroupId" clearable >
|
||||
<el-option v-for="item in securityGroupList" :key="item.id" :label="item.name" :value="item.id">
|
||||
</el-option>
|
||||
</el-select>
|
||||
@@ -206,12 +225,27 @@ import { availablePortList, portAvailable } from '@/api/portPool'
|
||||
import { licenseList, licenseAuthList } from '@/api/license'
|
||||
import { protocalList } from '@/api/protocal'
|
||||
import { userList } from '@/api/user'
|
||||
import { domainNameBindInfo } from '@/api/domain'
|
||||
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' },
|
||||
{ key: 'US', display_name: 'USA' },
|
||||
{ key: 'JP', display_name: 'Japan' },
|
||||
{ key: 'EU', display_name: 'Eurozone' }
|
||||
]
|
||||
|
||||
// arr to obj ,such as { CN : "China", US : "USA" }
|
||||
const calendarTypeKeyValue = calendarTypeOptions.reduce((acc, cur) => {
|
||||
acc[cur.key] = cur.display_name
|
||||
return acc
|
||||
}, {})
|
||||
|
||||
export default {
|
||||
name: 'complexTable',
|
||||
directives: {
|
||||
@@ -243,6 +277,7 @@ export default {
|
||||
listQuery: {
|
||||
current: 1,
|
||||
size: 10,
|
||||
importance: undefined,
|
||||
title: undefined,
|
||||
type: undefined,
|
||||
userId: undefined,
|
||||
@@ -253,6 +288,8 @@ export default {
|
||||
description: undefined
|
||||
|
||||
},
|
||||
importanceOptions: [1, 2, 3],
|
||||
calendarTypeOptions,
|
||||
sortOptions: [{ label: 'ID Ascending', key: '+id' }, { label: 'ID Descending', key: '-id' }],
|
||||
statusOptions: ['published', 'draft', 'deleted'],
|
||||
userList: [],
|
||||
@@ -291,9 +328,7 @@ export default {
|
||||
// { validator: isPortAvailable, trigger: 'change' }
|
||||
],
|
||||
clientIp: [{ required: true, message: '请输入客户端IP', trigger: 'blur' }],
|
||||
clientPort: [{ required: true, message: '请输入客户端端口', trigger: 'blur' },
|
||||
{ pattern: /^([0-9]|[1-9]\d|[1-9]\d{2}|[1-9]\d{3}|[1-5]\d{4}|6[0-4]\d{3}|65[0-4]\d{2}|655[0-2]\d|6553[0-5])$/,message: '端口号请选择0-65535间的数字',trigger: 'blur'}
|
||||
],
|
||||
clientPort: [{ required: true, message: '请输入客户端端口', trigger: 'blur' }],
|
||||
protocal: [{ required: true, message: '请选择协议', trigger: 'blur' }]
|
||||
},
|
||||
downloadLoading: false,
|
||||
@@ -332,8 +367,12 @@ export default {
|
||||
}
|
||||
return statusMap[status]
|
||||
},
|
||||
typeFilter(type) {
|
||||
return calendarTypeKeyValue[type]
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.getDomainNameBindInfo()
|
||||
this.getDataList()
|
||||
this.getLicenseList()
|
||||
this.getLicenseAuthList()
|
||||
@@ -367,6 +406,11 @@ export default {
|
||||
}
|
||||
})
|
||||
},
|
||||
getDomainNameBindInfo() {
|
||||
domainNameBindInfo().then(response => {
|
||||
this.domainName = response.data.data
|
||||
})
|
||||
},
|
||||
getAvailablePortList(licenseId) {
|
||||
this.loadServerPortQuery.licenseId = licenseId;
|
||||
this.serverPortList = []; //清掉数据
|
||||
@@ -527,6 +571,29 @@ export default {
|
||||
})
|
||||
}).catch(() => { })
|
||||
},
|
||||
handleDelete2(row) {
|
||||
deletePortMapping(row.id).then(response => {
|
||||
if (response.data.code === 0) {
|
||||
this.$notify({
|
||||
title: '成功',
|
||||
message: '删除成功',
|
||||
type: 'success',
|
||||
duration: 2000
|
||||
})
|
||||
this.getList()
|
||||
}
|
||||
})
|
||||
},
|
||||
handleDownload() {
|
||||
this.downloadLoading = true
|
||||
import('@/vendor/Export2Excel').then(excel => {
|
||||
const tHeader = ['timestamp', 'title', 'type', 'importance', 'status']
|
||||
const filterVal = ['timestamp', 'title', 'type', 'importance', 'status']
|
||||
const data = this.formatJson(filterVal, this.list)
|
||||
excel.export_json_to_excel(tHeader, data, 'table-list')
|
||||
this.downloadLoading = false
|
||||
})
|
||||
},
|
||||
formatJson(filterVal, jsonData) {
|
||||
return jsonData.map(v => filterVal.map(j => {
|
||||
if (j === 'timestamp') {
|
||||
|
||||
@@ -63,8 +63,7 @@
|
||||
<el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible">
|
||||
<el-form :rules="rules" ref="dataForm" :model="temp" label-position="left" label-width="70px" style='width: 400px; margin-left:50px;'>
|
||||
<el-form-item :label="$t('table.port')" prop="port">
|
||||
<!-- <el-input :placeholder="$t('table.portOrRange')" v-model="temp.port" :disabled="dialogStatus=='update'"></el-input> -->
|
||||
<el-input :placeholder="$t('table.portOrRange')" type="number" v-model="temp.port" :step="1" controls-position="right" :disabled="dialogStatus=='update'"></el-input>
|
||||
<el-input :placeholder="$t('table.portOrRange')" v-model="temp.port" :disabled="dialogStatus=='update'"></el-input>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item :label="$t('table.group')" prop="group">
|
||||
@@ -159,10 +158,7 @@ const calendarTypeOptions = [
|
||||
dialogPvVisible: false,
|
||||
pvData: [],
|
||||
rules: {
|
||||
port: [
|
||||
{ required: true, message: '端口必填', trigger: 'blur' },
|
||||
{ pattern: /^([0-9]|[1-9]\d|[1-9]\d{2}|[1-9]\d{3}|[1-5]\d{4}|6[0-4]\d{3}|65[0-4]\d{2}|655[0-2]\d|6553[0-5])$/,message: '端口号请选择0-65535间的数字',trigger: 'blur'}
|
||||
]
|
||||
port: [{ required: true, message: '端口必填', trigger: 'blur' }]
|
||||
},
|
||||
downloadLoading: false,
|
||||
checkBoxData:[], //表单勾选的行
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
FROM openjdk:21-jdk-oracle
|
||||
#同步时间
|
||||
#RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && \
|
||||
# apk update && apk add wget unzip vim && apk add -U tzdata && \
|
||||
# ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone
|
||||
# 设置时区为北京时间
|
||||
ENV TZ=Asia/Shanghai
|
||||
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
|
||||
RUN mkdir -p /root/neutrino-proxy/config
|
||||
WORKDIR /root/neutrino-proxy
|
||||
COPY ./target/neutrino-proxy-client.jar /root/neutrino-proxy/neutrino-proxy-client.jar
|
||||
COPY ./src/main/resources/app-copy.yml /root/neutrino-proxy/config/app.yml
|
||||
#VOLUME ["/root/neutrino-proxy"]
|
||||
ENTRYPOINT ["java","-jar","neutrino-proxy-client.jar","config=./config/app.yml"]
|
||||
|
||||
#docker run -it -d --restart=always --name np_client -e SERVER_IP=127.0.0.1
|
||||
@@ -0,0 +1,96 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>neutrino-proxy</artifactId>
|
||||
<groupId>org.dromara.neutrino-proxy</groupId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>neutrino-proxy-client-sdk</artifactId>
|
||||
<version>${revision}</version>
|
||||
<packaging>jar</packaging>
|
||||
<properties>
|
||||
<revision>2.0.1</revision>
|
||||
<!-- <lombok.version>1.18.30</lombok.version>-->
|
||||
<hutool.version>5.8.20</hutool.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.dromara.neutrino-proxy</groupId>
|
||||
<artifactId>neutrino-proxy-core</artifactId>
|
||||
<version>${revision}</version>
|
||||
<!-- <exclusions>-->
|
||||
<!-- <exclusion>-->
|
||||
<!-- <groupId>org.noear</groupId>-->
|
||||
<!-- <artifactId>solon-test</artifactId>-->
|
||||
<!-- </exclusion>-->
|
||||
<!-- <exclusion>-->
|
||||
<!-- <groupId>org.noear</groupId>-->
|
||||
<!-- <artifactId>solon.aot</artifactId>-->
|
||||
<!-- </exclusion>-->
|
||||
<!-- <exclusion>-->
|
||||
<!-- <groupId>org.noear</groupId>-->
|
||||
<!-- <artifactId>solon.logging.logback</artifactId>-->
|
||||
<!-- </exclusion>-->
|
||||
<!-- <exclusion>-->
|
||||
<!-- <groupId>cn.hutool</groupId>-->
|
||||
<!-- <artifactId>hutool-core</artifactId>-->
|
||||
<!-- </exclusion>-->
|
||||
<!-- <exclusion>-->
|
||||
<!-- <groupId>cn.hutool</groupId>-->
|
||||
<!-- <artifactId>hutool-cache</artifactId>-->
|
||||
<!-- </exclusion>-->
|
||||
<!-- </exclusions>-->
|
||||
</dependency>
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.projectlombok</groupId>-->
|
||||
<!-- <artifactId>lombok</artifactId>-->
|
||||
<!-- <scope>${lombok.version}</scope>-->
|
||||
<!-- </dependency>-->
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-slf4j-impl</artifactId>
|
||||
<version>2.20.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
<version>${hutool.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
<includes>
|
||||
<include>*.yml</include>
|
||||
</includes>
|
||||
</resource>
|
||||
<resource>
|
||||
<directory>${project.basedir}/src/main/resources</directory>
|
||||
<filtering>false</filtering>
|
||||
|
||||
<excludes>
|
||||
<exclude>app-dev.yml</exclude>
|
||||
</excludes>
|
||||
</resource>
|
||||
</resources>
|
||||
<!-- <plugins>-->
|
||||
<!-- <!– 配置打包插件(并打包成胖包) –>-->
|
||||
<!-- <plugin>-->
|
||||
<!-- <groupId>org.noear</groupId>-->
|
||||
<!-- <artifactId>solon-maven-plugin</artifactId>-->
|
||||
<!-- </plugin>-->
|
||||
<!-- </plugins>-->
|
||||
</build>
|
||||
|
||||
</project>
|
||||
+185
@@ -0,0 +1,185 @@
|
||||
package org.dromara.neutrinoproxy.client.sdk.config;
|
||||
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
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.sdk.core.*;
|
||||
import org.dromara.neutrinoproxy.client.sdk.util.ProxyUtil;
|
||||
import org.dromara.neutrinoproxy.core.ProxyMessageDecoder;
|
||||
import org.dromara.neutrinoproxy.core.ProxyMessageEncoder;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
/**
|
||||
* 代理配置
|
||||
* @author: aoshiguchen
|
||||
* @date: 2022/10/8
|
||||
*/
|
||||
|
||||
public abstract class IProxyConfiguration {
|
||||
|
||||
|
||||
public NioEventLoopGroup tunnelWorkGroup(ProxyConfig proxyConfig) {
|
||||
return new NioEventLoopGroup(proxyConfig.getTunnel().getThreadCount());
|
||||
}
|
||||
|
||||
public NioEventLoopGroup tcpRealServerWorkGroup(ProxyConfig proxyConfig) {
|
||||
// 暂时先公用此配置
|
||||
return new NioEventLoopGroup(proxyConfig.getTunnel().getThreadCount());
|
||||
}
|
||||
|
||||
public NioEventLoopGroup udpServerGroup(ProxyConfig proxyConfig) {
|
||||
// 暂时先公用此配置
|
||||
return new NioEventLoopGroup(proxyConfig.getClient().getUdp().getBossThreadCount());
|
||||
}
|
||||
|
||||
public NioEventLoopGroup udpWorkGroup(ProxyConfig proxyConfig) {
|
||||
// 暂时先公用此配置
|
||||
return new NioEventLoopGroup(proxyConfig.getClient().getUdp().getWorkThreadCount());
|
||||
}
|
||||
|
||||
public Bootstrap cmdTunnelBootstrap(ProxyConfig proxyConfig,
|
||||
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;
|
||||
}
|
||||
|
||||
public Bootstrap tcpProxyTunnelBootstrap(ProxyConfig proxyConfig,
|
||||
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;
|
||||
}
|
||||
public Bootstrap udpProxyTunnelBootstrap(ProxyConfig proxyConfig,
|
||||
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;
|
||||
}
|
||||
|
||||
public Bootstrap realServerBootstrap(ProxyConfig proxyConfig,
|
||||
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;
|
||||
}
|
||||
|
||||
public Bootstrap udpServerBootstrap(ProxyConfig proxyConfig,
|
||||
NioEventLoopGroup udpServerGroup,
|
||||
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;
|
||||
}
|
||||
|
||||
// public NeutrinoCoreRuntimeNativeRegistrar neutrinoCoreRuntimeNativeRegistrar() {
|
||||
// return new NeutrinoCoreRuntimeNativeRegistrar();
|
||||
// }
|
||||
|
||||
}
|
||||
+1
-7
@@ -1,8 +1,6 @@
|
||||
package org.dromara.neutrinoproxy.client.config;
|
||||
package org.dromara.neutrinoproxy.client.sdk.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.noear.solon.annotation.Component;
|
||||
import org.noear.solon.annotation.Inject;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -10,13 +8,9 @@ import org.noear.solon.annotation.Inject;
|
||||
* @date: 2022/6/16
|
||||
*/
|
||||
@Data
|
||||
@Component
|
||||
public class ProxyConfig {
|
||||
@Inject("${neutrino.proxy.protocol}")
|
||||
private Protocol protocol;
|
||||
@Inject("${neutrino.proxy.tunnel}")
|
||||
private Tunnel tunnel;
|
||||
@Inject("${neutrino.proxy.client}")
|
||||
private Client client;
|
||||
|
||||
@Data
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
package org.dromara.neutrinoproxy.client.constant;
|
||||
package org.dromara.neutrinoproxy.client.sdk.constant;
|
||||
|
||||
import io.netty.util.AttributeKey;
|
||||
import org.dromara.neutrinoproxy.client.util.UdpChannelBindInfo;
|
||||
import org.dromara.neutrinoproxy.client.sdk.util.UdpChannelBindInfo;
|
||||
|
||||
/**
|
||||
* @author: aoshiguchen
|
||||
+18
-13
@@ -1,17 +1,17 @@
|
||||
package org.dromara.neutrinoproxy.client.core;
|
||||
package org.dromara.neutrinoproxy.client.sdk.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;
|
||||
import org.dromara.neutrinoproxy.client.sdk.config.ProxyConfig;
|
||||
import org.dromara.neutrinoproxy.client.sdk.handler.ProxyMessageFactory;
|
||||
import org.dromara.neutrinoproxy.client.sdk.util.ProxyUtil;
|
||||
import org.dromara.neutrinoproxy.core.Constants;
|
||||
import org.dromara.neutrinoproxy.core.ProxyMessage;
|
||||
import org.dromara.neutrinoproxy.core.dispatcher.Dispatcher;
|
||||
|
||||
/**
|
||||
* 处理与服务端之间的数据传输
|
||||
@@ -19,22 +19,25 @@ import org.noear.solon.Solon;
|
||||
* @date: 2022/6/16
|
||||
*/
|
||||
@Slf4j
|
||||
public class CmdChannelHandler extends SimpleChannelInboundHandler<ProxyMessage> {
|
||||
public class CmdChannelHandler extends SimpleChannelInboundHandler<ProxyMessage>{
|
||||
private static volatile Boolean transferLogEnable = Boolean.FALSE;
|
||||
|
||||
|
||||
public CmdChannelHandler() {
|
||||
ProxyConfig proxyConfig = Solon.context().getBean(ProxyConfig.class);
|
||||
ProxyConfig proxyConfig = (ProxyConfig) ProxyMessageFactory.beanManager.get("proxyConfig").getBean();
|
||||
if (null != proxyConfig.getClient() && null != proxyConfig.getTunnel().getHeartbeatLogEnable()) {
|
||||
transferLogEnable = proxyConfig.getTunnel().getHeartbeatLogEnable();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void channelRead0(ChannelHandlerContext ctx, ProxyMessage proxyMessage) throws Exception {
|
||||
protected void channelRead0(ChannelHandlerContext ctx, ProxyMessage proxyMessage){
|
||||
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);
|
||||
// beanHandler.getDispatcher().dispatch(ctx, proxyMessage);
|
||||
Dispatcher dispatcher = (Dispatcher) ProxyMessageFactory.beanManager.get("dispatcher").getBean();
|
||||
dispatcher.dispatch(ctx,proxyMessage);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -43,6 +46,7 @@ public class CmdChannelHandler extends SimpleChannelInboundHandler<ProxyMessage>
|
||||
if (realServerChannel != null) {
|
||||
realServerChannel.config().setOption(ChannelOption.AUTO_READ, ctx.channel().isWritable());
|
||||
}
|
||||
|
||||
super.channelWritabilityChanged(ctx);
|
||||
}
|
||||
|
||||
@@ -56,13 +60,13 @@ public class CmdChannelHandler extends SimpleChannelInboundHandler<ProxyMessage>
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause){
|
||||
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 {
|
||||
public void userEventTriggered(ChannelHandlerContext ctx, Object evt){
|
||||
if(evt instanceof IdleStateEvent) {
|
||||
IdleStateEvent event = (IdleStateEvent)evt;
|
||||
switch (event.state()) {
|
||||
@@ -81,4 +85,5 @@ public class CmdChannelHandler extends SimpleChannelInboundHandler<ProxyMessage>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+2
-4
@@ -19,7 +19,7 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package org.dromara.neutrinoproxy.client.core;
|
||||
package org.dromara.neutrinoproxy.client.sdk.core;
|
||||
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
@@ -35,9 +35,7 @@ public class CustomThreadFactory implements ThreadFactory {
|
||||
private final String namePrefix;
|
||||
|
||||
public CustomThreadFactory(String prefix) {
|
||||
SecurityManager s = System.getSecurityManager();
|
||||
group = (s != null) ? s.getThreadGroup() :
|
||||
Thread.currentThread().getThreadGroup();
|
||||
group = Thread.currentThread().getThreadGroup();
|
||||
namePrefix = prefix + "-thread-";
|
||||
}
|
||||
|
||||
+126
@@ -0,0 +1,126 @@
|
||||
package org.dromara.neutrinoproxy.client.sdk.core;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelFuture;
|
||||
import io.netty.channel.ChannelFutureListener;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.neutrinoproxy.client.sdk.config.ProxyConfig;
|
||||
import org.dromara.neutrinoproxy.client.sdk.util.ProxyUtil;
|
||||
import org.dromara.neutrinoproxy.client.sdk.util.UdpServerUtil;
|
||||
import org.dromara.neutrinoproxy.core.ProxyMessage;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
|
||||
/**
|
||||
* 代理客户端服务
|
||||
* @author: aoshiguchen
|
||||
* @date: 2022/6/16
|
||||
*/
|
||||
@Slf4j
|
||||
@Data
|
||||
public class IAbProxyClientService {
|
||||
|
||||
public ProxyConfig proxyConfig;
|
||||
|
||||
public Bootstrap cmdTunnelBootstrap;
|
||||
|
||||
public Bootstrap udpServerBootstrap;
|
||||
|
||||
public Boolean isAotRuntime;
|
||||
|
||||
private volatile Channel channel;
|
||||
/**
|
||||
* 重连次数
|
||||
*/
|
||||
private volatile int reconnectCount = 0;
|
||||
|
||||
/**
|
||||
* 重连服务执行器
|
||||
*/
|
||||
public static final ScheduledExecutorService reconnectExecutor = Executors.newSingleThreadScheduledExecutor(new CustomThreadFactory("ClientReconnect"));
|
||||
|
||||
public void init(){
|
||||
reconnectExecutor.scheduleWithFixedDelay(this::reconnect, 10, proxyConfig.getTunnel().getReconnection().getIntervalSeconds(), TimeUnit.SECONDS);
|
||||
try {
|
||||
this.start();
|
||||
UdpServerUtil.initCache(proxyConfig, udpServerBootstrap,isAotRuntime);
|
||||
} catch (Exception e) {
|
||||
// 启动连不上也做一下重连,因此先catch异常
|
||||
log.error("[CmdChannel] start error", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void start() {
|
||||
if (StrUtil.isEmpty(proxyConfig.getTunnel().getServerIp())) {
|
||||
log.error("not found server-ip config.");
|
||||
return;
|
||||
}
|
||||
if (null == proxyConfig.getTunnel().getServerPort()) {
|
||||
log.error("not found server-port config.");
|
||||
return;
|
||||
}
|
||||
if (null != proxyConfig.getTunnel().getSslEnable() && proxyConfig.getTunnel().getSslEnable()
|
||||
&& StrUtil.isEmpty(proxyConfig.getTunnel().getJksPath())) {
|
||||
log.error("not found jks-path config.");
|
||||
return;
|
||||
}
|
||||
if (StrUtil.isEmpty(proxyConfig.getTunnel().getLicenseKey())) {
|
||||
log.error("not found license-key config.");
|
||||
return;
|
||||
}
|
||||
if (null == channel || !channel.isActive()) {
|
||||
try {
|
||||
connectProxyServer();
|
||||
} catch (Exception e) {
|
||||
log.error("client start error", e);
|
||||
}
|
||||
} else {
|
||||
channel.writeAndFlush(ProxyMessage.buildAuthMessage(proxyConfig.getTunnel().getLicenseKey(), ProxyUtil.getClientId(proxyConfig)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接代理服务器
|
||||
*/
|
||||
private void connectProxyServer() throws InterruptedException {
|
||||
cmdTunnelBootstrap.connect()
|
||||
.addListener(new ChannelFutureListener() {
|
||||
|
||||
@Override
|
||||
public void operationComplete(ChannelFuture future) throws Exception {
|
||||
if (future.isSuccess()) {
|
||||
channel = future.channel();
|
||||
// 连接成功,向服务器发送客户端认证信息(licenseKey)
|
||||
ProxyUtil.setCmdChannel(future.channel());
|
||||
future.channel().writeAndFlush(ProxyMessage.buildAuthMessage(proxyConfig.getTunnel().getLicenseKey(), ProxyUtil.getClientId(proxyConfig)));
|
||||
log.info("[CmdChannel] connect proxy server {}:{} success. channelId:{}", proxyConfig.getTunnel().getServerIp(), proxyConfig.getTunnel().getServerPort(), future.channel().id().asLongText());
|
||||
|
||||
// reconnectServiceEnable = true;
|
||||
reconnectCount = 0;
|
||||
} else {
|
||||
log.info("[CmdChannel] connect proxy server {}:{} failed!", proxyConfig.getTunnel().getServerIp(), proxyConfig.getTunnel().getServerPort());
|
||||
}
|
||||
}
|
||||
}).sync();
|
||||
}
|
||||
|
||||
protected synchronized void reconnect() {
|
||||
if (null != channel) {
|
||||
if (channel.isActive()) {
|
||||
return;
|
||||
}
|
||||
channel.close();
|
||||
}
|
||||
|
||||
log.info("[CmdChannel] client reconnect seq:{}", ++reconnectCount);
|
||||
try {
|
||||
connectProxyServer();
|
||||
} catch (Exception e) {
|
||||
log.error("[CmdChannel] reconnect error", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -20,7 +20,7 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package org.dromara.neutrinoproxy.client.core;
|
||||
package org.dromara.neutrinoproxy.client.sdk.core;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
|
||||
+3
-10
@@ -20,10 +20,10 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package org.dromara.neutrinoproxy.client.core;
|
||||
package org.dromara.neutrinoproxy.client.sdk.core;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.neutrinoproxy.client.util.ProxyUtil;
|
||||
import org.dromara.neutrinoproxy.client.sdk.util.ProxyUtil;
|
||||
import org.dromara.neutrinoproxy.core.Constants;
|
||||
import org.dromara.neutrinoproxy.core.ProxyMessage;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
@@ -67,18 +67,11 @@ public class RealServerChannelHandler extends SimpleChannelInboundHandler<ByteBu
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通道激活时触发,当客户端connect成功后,服务端就会接收到这个事件,从而可以把客户端的Channel记录下来,供后面复用
|
||||
* @param ctx
|
||||
* @throws Exception
|
||||
*/
|
||||
@Override
|
||||
public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
||||
super.channelActive(ctx);
|
||||
}
|
||||
/**
|
||||
* 客户端 失去连接
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
||||
Channel realServerChannel = ctx.channel();
|
||||
+7
-6
@@ -1,4 +1,4 @@
|
||||
package org.dromara.neutrinoproxy.client.core;
|
||||
package org.dromara.neutrinoproxy.client.sdk.core;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
@@ -6,11 +6,11 @@ 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.client.sdk.handler.ProxyMessageFactory;
|
||||
import org.dromara.neutrinoproxy.client.sdk.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;
|
||||
|
||||
/**
|
||||
* 处理与服务端之间的数据传输
|
||||
@@ -26,7 +26,8 @@ public class TcpProxyChannelHandler extends SimpleChannelInboundHandler<ProxyMes
|
||||
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);
|
||||
Dispatcher dispatcher = (Dispatcher) ProxyMessageFactory.beanManager.get("dispatcher").getBean();
|
||||
dispatcher.dispatch(ctx,proxyMessage);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -52,13 +53,13 @@ public class TcpProxyChannelHandler extends SimpleChannelInboundHandler<ProxyMes
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
|
||||
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 {
|
||||
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
|
||||
if(evt instanceof IdleStateEvent) {
|
||||
IdleStateEvent event = (IdleStateEvent)evt;
|
||||
switch (event.state()) {
|
||||
+8
-8
@@ -1,4 +1,4 @@
|
||||
package org.dromara.neutrinoproxy.client.core;
|
||||
package org.dromara.neutrinoproxy.client.sdk.core;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
@@ -6,11 +6,11 @@ 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.client.sdk.handler.ProxyMessageFactory;
|
||||
import org.dromara.neutrinoproxy.client.sdk.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;
|
||||
|
||||
/**
|
||||
* 处理与服务端之间的数据传输
|
||||
@@ -20,13 +20,13 @@ import org.noear.solon.Solon;
|
||||
@Slf4j
|
||||
public class UdpProxyChannelHandler extends SimpleChannelInboundHandler<ProxyMessage> {
|
||||
|
||||
|
||||
@Override
|
||||
protected void channelRead0(ChannelHandlerContext ctx, ProxyMessage proxyMessage) throws Exception {
|
||||
protected void channelRead0(ChannelHandlerContext ctx, ProxyMessage proxyMessage) {
|
||||
if (ProxyMessage.TYPE_HEARTBEAT != proxyMessage.getType()) {
|
||||
log.debug("[UDP Proxy Channel]Client ProxyChannel recieved proxy message, type is {}", proxyMessage.getType());
|
||||
}
|
||||
Solon.context().getBean(Dispatcher.class).dispatch(ctx, proxyMessage);
|
||||
Dispatcher dispatcher = (Dispatcher) ProxyMessageFactory.beanManager.get("dispatcher").getBean();
|
||||
dispatcher.dispatch(ctx,proxyMessage);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -52,13 +52,13 @@ public class UdpProxyChannelHandler extends SimpleChannelInboundHandler<ProxyMes
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
|
||||
log.error("[UDP Proxy Channel]Client ProxyChannel Error channelId:{}", ctx.channel().id().asLongText(), cause);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
|
||||
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
|
||||
if(evt instanceof IdleStateEvent) {
|
||||
IdleStateEvent event = (IdleStateEvent)evt;
|
||||
switch (event.state()) {
|
||||
+3
-3
@@ -1,11 +1,11 @@
|
||||
package org.dromara.neutrinoproxy.client.core;
|
||||
package org.dromara.neutrinoproxy.client.sdk.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.client.sdk.constant.Constants;
|
||||
import org.dromara.neutrinoproxy.client.sdk.util.UdpChannelBindInfo;
|
||||
import org.dromara.neutrinoproxy.core.ProxyMessage;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
+14
-12
@@ -1,17 +1,15 @@
|
||||
package org.dromara.neutrinoproxy.client.handler;
|
||||
package org.dromara.neutrinoproxy.client.sdk.handler;
|
||||
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.neutrinoproxy.client.config.ProxyConfig;
|
||||
import org.dromara.neutrinoproxy.client.sdk.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 org.noear.snack.ONode;
|
||||
import org.noear.solon.Solon;
|
||||
import org.noear.solon.annotation.Component;
|
||||
import org.noear.solon.annotation.Inject;
|
||||
|
||||
/**
|
||||
* 认证信息处理器
|
||||
@@ -20,22 +18,26 @@ import org.noear.solon.annotation.Inject;
|
||||
*/
|
||||
@Slf4j
|
||||
@Match(type = Constants.ProxyDataTypeName.AUTH)
|
||||
@Component
|
||||
public class ProxyMessageAuthHandler implements ProxyMessageHandler {
|
||||
@Inject
|
||||
private ProxyConfig proxyConfig;
|
||||
private final ProxyConfig proxyConfig;
|
||||
private final Runnable stop;
|
||||
|
||||
public ProxyMessageAuthHandler(ProxyConfig proxyConfig,Runnable stop){
|
||||
this.proxyConfig=proxyConfig;
|
||||
this.stop=stop;
|
||||
}
|
||||
@Override
|
||||
public void handle(ChannelHandlerContext context, ProxyMessage proxyMessage) {
|
||||
String info = proxyMessage.getInfo();
|
||||
ONode load = ONode.load(info);
|
||||
Integer code = load.get("code").getInt();
|
||||
JSONObject load = JSONUtil.parseObj(info);
|
||||
Integer code = load.getInt("code");
|
||||
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();
|
||||
stop.run();
|
||||
}
|
||||
} else if (ExceptionEnum.CONNECT_FAILED.getCode().equals(code) ||
|
||||
ExceptionEnum.LICENSE_CANNOT_REPEAT_CONNECT.getCode().equals(code)
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
package org.dromara.neutrinoproxy.client.sdk.handler;
|
||||
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
import io.netty.channel.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.neutrinoproxy.client.sdk.config.ProxyConfig;
|
||||
import org.dromara.neutrinoproxy.client.sdk.core.ProxyChannelBorrowListener;
|
||||
import org.dromara.neutrinoproxy.client.sdk.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;
|
||||
|
||||
/**
|
||||
* 连接信息处理器
|
||||
* @author: aoshiguchen
|
||||
* @date: 2022/6/16
|
||||
*/
|
||||
@Slf4j
|
||||
@Match(type = Constants.ProxyDataTypeName.CONNECT)
|
||||
public class ProxyMessageConnectHandler implements ProxyMessageHandler {
|
||||
|
||||
private final Bootstrap tcpProxyTunnelBootstrap;
|
||||
private final Bootstrap realServerBootstrap;
|
||||
private final ProxyConfig proxyConfig;
|
||||
|
||||
public ProxyMessageConnectHandler(Bootstrap tcpProxyTunnelBootstrap,Bootstrap realServerBootstrap,ProxyConfig proxyConfig){
|
||||
this.proxyConfig=proxyConfig;
|
||||
this.realServerBootstrap=realServerBootstrap;
|
||||
this.tcpProxyTunnelBootstrap=tcpProxyTunnelBootstrap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(ChannelHandlerContext ctx, ProxyMessage proxyMessage) {
|
||||
final Channel cmdChannel = ctx.channel();
|
||||
final String visitorId = proxyMessage.getInfo();
|
||||
String[] serverInfo = new String(proxyMessage.getData()).split(":");
|
||||
String ip = serverInfo[0];
|
||||
int port = Integer.parseInt(serverInfo[1]);
|
||||
// 连接真实的、被代理的服务
|
||||
realServerBootstrap.connect(ip, port).addListener((ChannelFutureListener) future -> {
|
||||
// 连接后端服务器成功
|
||||
if (future.isSuccess()) {
|
||||
final Channel realServerChannel = future.channel();
|
||||
|
||||
realServerChannel.config().setOption(ChannelOption.AUTO_READ, false);
|
||||
|
||||
// 获取连接
|
||||
ProxyUtil.borrowTcpProxyChanel(tcpProxyTunnelBootstrap, new ProxyChannelBorrowListener() {
|
||||
|
||||
@Override
|
||||
public void success(Channel channel) {
|
||||
// 连接绑定
|
||||
channel.attr(Constants.NEXT_CHANNEL).set(realServerChannel);
|
||||
realServerChannel.attr(Constants.NEXT_CHANNEL).set(channel);
|
||||
|
||||
// 远程绑定
|
||||
channel.writeAndFlush(ProxyMessage.buildConnectMessage(visitorId + "@" + proxyConfig.getTunnel().getLicenseKey()));
|
||||
|
||||
realServerChannel.config().setOption(ChannelOption.AUTO_READ, true);
|
||||
ProxyUtil.addRealServerChannel(visitorId, realServerChannel);
|
||||
ProxyUtil.setRealServerChannelVisitorId(realServerChannel, visitorId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(Throwable cause) {
|
||||
ProxyMessage proxyMessage1 = new ProxyMessage();
|
||||
proxyMessage1.setType(ProxyMessage.TYPE_DISCONNECT);
|
||||
proxyMessage1.setInfo(visitorId);
|
||||
cmdChannel.writeAndFlush(proxyMessage1);
|
||||
}
|
||||
});
|
||||
|
||||
} else {
|
||||
cmdChannel.writeAndFlush(ProxyMessage.buildDisconnectMessage(visitorId));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return ProxyDataTypeEnum.CONNECT.getDesc();
|
||||
}
|
||||
|
||||
}
|
||||
+8
-8
@@ -1,24 +1,24 @@
|
||||
package org.dromara.neutrinoproxy.client.handler;
|
||||
package org.dromara.neutrinoproxy.client.sdk.handler;
|
||||
|
||||
import org.dromara.neutrinoproxy.client.util.ProxyUtil;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelFutureListener;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.neutrinoproxy.client.sdk.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 io.netty.buffer.Unpooled;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelFutureListener;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import org.noear.solon.annotation.Component;
|
||||
|
||||
/**
|
||||
* 断开连接信息处理器
|
||||
* @author: aoshiguchen
|
||||
* @date: 2022/6/16
|
||||
*/
|
||||
@Slf4j
|
||||
@Match(type = Constants.ProxyDataTypeName.DISCONNECT)
|
||||
@Component
|
||||
public class ProxyMessageDisconnectHandler implements ProxyMessageHandler {
|
||||
|
||||
@Override
|
||||
+7
-11
@@ -1,15 +1,11 @@
|
||||
package org.dromara.neutrinoproxy.client.handler;
|
||||
package org.dromara.neutrinoproxy.client.sdk.handler;
|
||||
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.neutrinoproxy.core.Constants;
|
||||
import org.dromara.neutrinoproxy.core.ExceptionEnum;
|
||||
import org.dromara.neutrinoproxy.core.ProxyDataTypeEnum;
|
||||
import org.dromara.neutrinoproxy.core.ProxyMessage;
|
||||
import org.dromara.neutrinoproxy.core.ProxyMessageHandler;
|
||||
import org.dromara.neutrinoproxy.core.*;
|
||||
import org.dromara.neutrinoproxy.core.dispatcher.Match;
|
||||
import org.noear.snack.ONode;
|
||||
import org.noear.solon.annotation.Component;
|
||||
|
||||
/**
|
||||
* 异常信息处理器
|
||||
@@ -18,14 +14,13 @@ import org.noear.solon.annotation.Component;
|
||||
*/
|
||||
@Slf4j
|
||||
@Match(type = Constants.ProxyDataTypeName.ERROR)
|
||||
@Component
|
||||
public class ProxyMessageErrorHandler implements ProxyMessageHandler {
|
||||
|
||||
@Override
|
||||
public void handle(ChannelHandlerContext ctx, ProxyMessage proxyMessage) {
|
||||
log.info("error: {}", proxyMessage.getInfo());
|
||||
ONode load = ONode.load(proxyMessage.getInfo());
|
||||
Integer code = load.get("code").getInt();
|
||||
JSONObject load = JSONUtil.parseObj(proxyMessage.getInfo());
|
||||
Integer code = load.getInt("code");
|
||||
if (ExceptionEnum.AUTH_FAILED.getCode().equals(code)) {
|
||||
System.exit(0);
|
||||
}
|
||||
@@ -35,4 +30,5 @@ public class ProxyMessageErrorHandler implements ProxyMessageHandler {
|
||||
public String name() {
|
||||
return ProxyDataTypeEnum.DISCONNECT.getDesc();
|
||||
}
|
||||
|
||||
}
|
||||
+91
@@ -0,0 +1,91 @@
|
||||
package org.dromara.neutrinoproxy.client.sdk.handler;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.nio.NioEventLoopGroup;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.dromara.neutrinoproxy.client.sdk.config.IProxyConfiguration;
|
||||
import org.dromara.neutrinoproxy.client.sdk.config.ProxyConfig;
|
||||
import org.dromara.neutrinoproxy.client.sdk.core.IAbProxyClientService;
|
||||
import org.dromara.neutrinoproxy.core.ProxyDataTypeEnum;
|
||||
import org.dromara.neutrinoproxy.core.ProxyMessage;
|
||||
import org.dromara.neutrinoproxy.core.ProxyMessageHandler;
|
||||
import org.dromara.neutrinoproxy.core.dispatcher.DefaultDispatcher;
|
||||
import org.dromara.neutrinoproxy.core.dispatcher.Dispatcher;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author: gc.x
|
||||
* @date: 2024/1/21
|
||||
*/
|
||||
public abstract class ProxyMessageFactory extends IProxyConfiguration {
|
||||
|
||||
public abstract void stop();
|
||||
public abstract boolean isAotRuntime();
|
||||
public static Map<String,BeanInfo> beanManager=new ConcurrentHashMap<>();
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public static class BeanInfo<T>{
|
||||
private String beanName;
|
||||
private T bean;
|
||||
private Class<?> beanClass;
|
||||
}
|
||||
|
||||
public void start(ProxyConfig proxyConfig){
|
||||
init(proxyConfig);
|
||||
IAbProxyClientService clientService=new IAbProxyClientService();
|
||||
clientService.setProxyConfig(proxyConfig);
|
||||
clientService.setCmdTunnelBootstrap((Bootstrap)beanManager.get("cmdTunnelBootstrap").getBean());
|
||||
clientService.setUdpServerBootstrap((Bootstrap)beanManager.get("udpServerBootstrap").getBean());
|
||||
clientService.setIsAotRuntime(isAotRuntime());
|
||||
clientService.init();
|
||||
}
|
||||
|
||||
public void init(ProxyConfig proxyConfig){
|
||||
beanManager.put("proxyConfig",BeanInfo.builder().bean(proxyConfig).beanName("proxyConfig").beanClass(ProxyConfig.class).build());
|
||||
NioEventLoopGroup tunnelWorkGroup = super.tunnelWorkGroup(proxyConfig);
|
||||
beanManager.put("tunnelWorkGroup",BeanInfo.builder().bean(tunnelWorkGroup).beanName("tunnelWorkGroup").beanClass(NioEventLoopGroup.class).build());
|
||||
NioEventLoopGroup tcpRealServerWorkGroup = super.tcpRealServerWorkGroup(proxyConfig);
|
||||
beanManager.put("tcpRealServerWorkGroup",BeanInfo.builder().bean(tcpRealServerWorkGroup).beanName("tcpRealServerWorkGroup").beanClass(NioEventLoopGroup.class).build());
|
||||
NioEventLoopGroup udpServerGroup = super.udpServerGroup(proxyConfig);
|
||||
beanManager.put("udpServerGroup",BeanInfo.builder().bean(udpServerGroup).beanName("udpServerGroup").beanClass(NioEventLoopGroup.class).build());
|
||||
NioEventLoopGroup udpWorkGroup = super.udpWorkGroup(proxyConfig);
|
||||
beanManager.put("udpWorkGroup",BeanInfo.builder().bean(udpWorkGroup).beanName("udpWorkGroup").beanClass(NioEventLoopGroup.class).build());
|
||||
Bootstrap cmdTunnelBootstrap = super.cmdTunnelBootstrap(proxyConfig, tunnelWorkGroup);
|
||||
beanManager.put("cmdTunnelBootstrap",BeanInfo.builder().bean(cmdTunnelBootstrap).beanName("cmdTunnelBootstrap").beanClass(Bootstrap.class).build());
|
||||
Bootstrap tcpProxyTunnelBootstrap = super.tcpProxyTunnelBootstrap(proxyConfig, tunnelWorkGroup);
|
||||
beanManager.put("tcpProxyTunnelBootstrap",BeanInfo.builder().bean(tcpProxyTunnelBootstrap).beanName("tcpProxyTunnelBootstrap").beanClass(Bootstrap.class).build());
|
||||
Bootstrap udpProxyTunnelBootstrap = super.udpProxyTunnelBootstrap(proxyConfig, tunnelWorkGroup);
|
||||
beanManager.put("udpProxyTunnelBootstrap",BeanInfo.builder().bean(udpProxyTunnelBootstrap).beanName("udpProxyTunnelBootstrap").beanClass(Bootstrap.class).build());
|
||||
Bootstrap realServerBootstrap = super.realServerBootstrap(proxyConfig, tcpRealServerWorkGroup);
|
||||
beanManager.put("realServerBootstrap",BeanInfo.builder().bean(realServerBootstrap).beanName("realServerBootstrap").beanClass(Bootstrap.class).build());
|
||||
Bootstrap udpServerBootstrap = super.udpServerBootstrap(proxyConfig, udpServerGroup, udpWorkGroup);
|
||||
beanManager.put("udpServerBootstrap",BeanInfo.builder().bean(udpServerBootstrap).beanName("udpServerBootstrap").beanClass(Bootstrap.class).build());
|
||||
dispatcher(proxyConfig, tcpProxyTunnelBootstrap, realServerBootstrap);
|
||||
}
|
||||
public void dispatcher(ProxyConfig proxyConfig, Bootstrap tcpProxyTunnelBootstrap, Bootstrap realServerBootstrap) {
|
||||
List<ProxyMessageHandler> list = Lists.newArrayList(
|
||||
new ProxyMessageAuthHandler(proxyConfig, this::stop),
|
||||
new ProxyMessageConnectHandler(tcpProxyTunnelBootstrap,realServerBootstrap,proxyConfig),
|
||||
new ProxyMessageDisconnectHandler(),
|
||||
new ProxyMessageErrorHandler(),
|
||||
new ProxyMessageTransferHandler(),
|
||||
new UdpProxyMessageConnectHandler(proxyConfig,tcpProxyTunnelBootstrap),
|
||||
new UdpProxyMessageTransferHandler()
|
||||
);
|
||||
Dispatcher<ChannelHandlerContext, ProxyMessage> dispatcher = new DefaultDispatcher<>("MessageDispatcher", list,
|
||||
proxyMessage -> ProxyDataTypeEnum.of((int)proxyMessage.getType()) == null ?
|
||||
null : ProxyDataTypeEnum.of((int)proxyMessage.getType()).getName());
|
||||
beanManager.put("dispatcher",BeanInfo.builder().bean(dispatcher).beanName("dispatcher").beanClass(Dispatcher.class).build());
|
||||
}
|
||||
}
|
||||
+6
-6
@@ -1,14 +1,14 @@
|
||||
package org.dromara.neutrinoproxy.client.handler;
|
||||
package org.dromara.neutrinoproxy.client.sdk.handler;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
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 io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import org.noear.solon.annotation.Component;
|
||||
|
||||
/**
|
||||
* 传输信息处理器
|
||||
@@ -16,7 +16,7 @@ import org.noear.solon.annotation.Component;
|
||||
* @date: 2022/6/16
|
||||
*/
|
||||
@Match(type = Constants.ProxyDataTypeName.TRANSFER)
|
||||
@Component
|
||||
@Slf4j
|
||||
public class ProxyMessageTransferHandler implements ProxyMessageHandler {
|
||||
|
||||
@Override
|
||||
+16
-13
@@ -1,20 +1,18 @@
|
||||
package org.dromara.neutrinoproxy.client.handler;
|
||||
package org.dromara.neutrinoproxy.client.sdk.handler;
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
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.client.sdk.config.ProxyConfig;
|
||||
import org.dromara.neutrinoproxy.client.sdk.core.ProxyChannelBorrowListener;
|
||||
import org.dromara.neutrinoproxy.client.sdk.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.snack.ONode;
|
||||
import org.noear.solon.annotation.Component;
|
||||
import org.noear.solon.annotation.Inject;
|
||||
|
||||
/**
|
||||
* @author: aoshiguchen
|
||||
@@ -22,17 +20,21 @@ import org.noear.solon.annotation.Inject;
|
||||
*/
|
||||
@Slf4j
|
||||
@Match(type = Constants.ProxyDataTypeName.UDP_CONNECT)
|
||||
@Component
|
||||
public class UdpProxyMessageConnectHandler implements ProxyMessageHandler {
|
||||
@Inject
|
||||
private ProxyConfig proxyConfig;
|
||||
@Inject("udpProxyTunnelBootstrap")
|
||||
private Bootstrap udpProxyTunnelBootstrap;
|
||||
|
||||
private final ProxyConfig proxyConfig;
|
||||
private final Bootstrap udpProxyTunnelBootstrap;
|
||||
|
||||
public UdpProxyMessageConnectHandler(ProxyConfig proxyConfig,Bootstrap udpProxyTunnelBootstrap){
|
||||
this.proxyConfig=proxyConfig;
|
||||
this.udpProxyTunnelBootstrap=udpProxyTunnelBootstrap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(ChannelHandlerContext ctx, ProxyMessage proxyMessage) {
|
||||
final Channel cmdChannel = ctx.channel();
|
||||
final ProxyMessage.UdpBaseInfo udpBaseInfo = ONode.deserialize(proxyMessage.getInfo(), ProxyMessage.UdpBaseInfo.class);
|
||||
String info = proxyMessage.getInfo();
|
||||
final ProxyMessage.UdpBaseInfo udpBaseInfo = JSONUtil.toBean(info,ProxyMessage.UdpBaseInfo.class);
|
||||
log.info("[UDP connect]info:{}", proxyMessage.getInfo());
|
||||
|
||||
// 获取连接
|
||||
@@ -61,4 +63,5 @@ public class UdpProxyMessageConnectHandler implements ProxyMessageHandler {
|
||||
public String name() {
|
||||
return ProxyDataTypeEnum.UDP_CONNECT.getDesc();
|
||||
}
|
||||
|
||||
}
|
||||
+5
-6
@@ -1,19 +1,18 @@
|
||||
package org.dromara.neutrinoproxy.client.handler;
|
||||
package org.dromara.neutrinoproxy.client.sdk.handler;
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
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.client.sdk.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.snack.ONode;
|
||||
import org.noear.solon.annotation.Component;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
@@ -23,12 +22,11 @@ import java.net.InetSocketAddress;
|
||||
*/
|
||||
@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 = ONode.deserialize(proxyMessage.getInfo(), ProxyMessage.UdpBaseInfo.class);
|
||||
final ProxyMessage.UdpBaseInfo udpBaseInfo = JSONUtil.toBean(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) {
|
||||
@@ -45,4 +43,5 @@ public class UdpProxyMessageTransferHandler implements ProxyMessageHandler {
|
||||
public String name() {
|
||||
return ProxyDataTypeEnum.UDP_TRANSFER.getDesc();
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package org.dromara.neutrinoproxy.client.util;
|
||||
package org.dromara.neutrinoproxy.client.sdk.util;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import lombok.Data;
|
||||
+9
-11
@@ -19,23 +19,22 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package org.dromara.neutrinoproxy.client.util;
|
||||
package org.dromara.neutrinoproxy.client.sdk.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;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelFutureListener;
|
||||
import io.netty.channel.ChannelHandler;
|
||||
import io.netty.channel.ChannelOption;
|
||||
import io.netty.handler.ssl.SslHandler;
|
||||
import io.netty.util.AttributeKey;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.dromara.neutrinoproxy.client.sdk.config.ProxyConfig;
|
||||
import org.dromara.neutrinoproxy.client.sdk.core.ProxyChannelBorrowListener;
|
||||
import org.dromara.neutrinoproxy.core.Constants;
|
||||
import org.dromara.neutrinoproxy.core.util.FileUtil;
|
||||
import org.noear.solon.Solon;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLEngine;
|
||||
@@ -180,11 +179,10 @@ public class ProxyUtil {
|
||||
realServerChannels.clear();
|
||||
}
|
||||
|
||||
public static String getClientId() {
|
||||
public static String getClientId(ProxyConfig proxyConfig) {
|
||||
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;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package org.dromara.neutrinoproxy.client.util;
|
||||
package org.dromara.neutrinoproxy.client.sdk.util;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import lombok.Data;
|
||||
+7
-7
@@ -1,4 +1,4 @@
|
||||
package org.dromara.neutrinoproxy.client.util;
|
||||
package org.dromara.neutrinoproxy.client.sdk.util;
|
||||
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
import io.netty.buffer.Unpooled;
|
||||
@@ -7,11 +7,11 @@ 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.client.sdk.config.ProxyConfig;
|
||||
import org.dromara.neutrinoproxy.client.sdk.constant.Constants;
|
||||
import org.dromara.neutrinoproxy.client.sdk.core.CustomThreadFactory;
|
||||
import org.dromara.neutrinoproxy.core.ProxyMessage;
|
||||
import org.noear.solon.core.runtime.NativeDetector;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
@@ -46,9 +46,9 @@ public class UdpServerUtil {
|
||||
* 2、维护一个UDP服务池,用于需要响应的UDP转发
|
||||
* @param proxyConfig
|
||||
*/
|
||||
public static void initCache(ProxyConfig proxyConfig, Bootstrap udpServerBootstrap) {
|
||||
public static void initCache(ProxyConfig proxyConfig, Bootstrap udpServerBootstrap,Boolean isAotRuntime) {
|
||||
// aot 阶段,不初始化UDP服务
|
||||
if (NativeDetector.isAotRuntime()) {
|
||||
if (isAotRuntime) {
|
||||
return;
|
||||
}
|
||||
if (null == proxyConfig.getClient().getUdp() || StringUtils.isEmpty(proxyConfig.getClient().getUdp().getPuppetPortRange())) {
|
||||
@@ -16,13 +16,18 @@
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.dromara.neutrino-proxy</groupId>
|
||||
<artifactId>neutrino-proxy-core</artifactId>
|
||||
<artifactId>neutrino-proxy-client-sdk</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.noear</groupId>
|
||||
<artifactId>solon-lib</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.noear</groupId>
|
||||
<artifactId>solon.aot</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
+13
@@ -1,5 +1,6 @@
|
||||
package org.dromara.neutrinoproxy.client.config;
|
||||
|
||||
import org.dromara.neutrinoproxy.client.sdk.config.ProxyConfig;
|
||||
import org.noear.solon.annotation.Component;
|
||||
import org.noear.solon.aot.RuntimeNativeMetadata;
|
||||
import org.noear.solon.aot.RuntimeNativeRegistrar;
|
||||
@@ -16,11 +17,23 @@ public class NeutrinoClientRuntimeNativeRegistrar implements RuntimeNativeRegist
|
||||
public void register(AppContext context, RuntimeNativeMetadata metadata) {
|
||||
metadata.registerResourceInclude("test.jks");
|
||||
|
||||
// sdk - ProxyConfig
|
||||
metadata.registerReflection(ProxyConfig.class, MemberCategory.DECLARED_FIELDS, MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS, MemberCategory.INVOKE_DECLARED_METHODS);
|
||||
metadata.registerReflection(ProxyConfig.Protocol.class, MemberCategory.DECLARED_FIELDS, MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS, MemberCategory.INVOKE_DECLARED_METHODS);
|
||||
metadata.registerReflection(ProxyConfig.Client.class, MemberCategory.DECLARED_FIELDS, MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS, MemberCategory.INVOKE_DECLARED_METHODS);
|
||||
metadata.registerReflection(ProxyConfig.Tunnel.class, MemberCategory.DECLARED_FIELDS, MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS, MemberCategory.INVOKE_DECLARED_METHODS);
|
||||
metadata.registerReflection(ProxyConfig.Tcp.class, MemberCategory.DECLARED_FIELDS, MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS, MemberCategory.INVOKE_DECLARED_METHODS);
|
||||
metadata.registerReflection(ProxyConfig.Udp.class, MemberCategory.DECLARED_FIELDS, MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS, MemberCategory.INVOKE_DECLARED_METHODS);
|
||||
metadata.registerReflection(ProxyConfig.Reconnection.class, MemberCategory.DECLARED_FIELDS, MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS, MemberCategory.INVOKE_DECLARED_METHODS);
|
||||
|
||||
// client - SolonProxyConfig
|
||||
metadata.registerReflection(SolonProxyConfig.class, MemberCategory.DECLARED_FIELDS, MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS, MemberCategory.INVOKE_DECLARED_METHODS);
|
||||
metadata.registerReflection(SolonProxyConfig.Protocol.class, MemberCategory.DECLARED_FIELDS, MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS, MemberCategory.INVOKE_DECLARED_METHODS);
|
||||
metadata.registerReflection(SolonProxyConfig.Client.class, MemberCategory.DECLARED_FIELDS, MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS, MemberCategory.INVOKE_DECLARED_METHODS);
|
||||
metadata.registerReflection(SolonProxyConfig.Tunnel.class, MemberCategory.DECLARED_FIELDS, MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS, MemberCategory.INVOKE_DECLARED_METHODS);
|
||||
metadata.registerReflection(SolonProxyConfig.Tcp.class, MemberCategory.DECLARED_FIELDS, MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS, MemberCategory.INVOKE_DECLARED_METHODS);
|
||||
metadata.registerReflection(SolonProxyConfig.Udp.class, MemberCategory.DECLARED_FIELDS, MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS, MemberCategory.INVOKE_DECLARED_METHODS);
|
||||
metadata.registerReflection(SolonProxyConfig.Reconnection.class, MemberCategory.DECLARED_FIELDS, MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS, MemberCategory.INVOKE_DECLARED_METHODS);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+9
-190
@@ -1,30 +1,11 @@
|
||||
package org.dromara.neutrinoproxy.client.config;
|
||||
|
||||
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.client.sdk.handler.ProxyMessageFactory;
|
||||
import org.dromara.neutrinoproxy.core.aot.NeutrinoCoreRuntimeNativeRegistrar;
|
||||
import org.dromara.neutrinoproxy.core.dispatcher.DefaultDispatcher;
|
||||
import org.dromara.neutrinoproxy.core.dispatcher.Dispatcher;
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
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;
|
||||
import org.noear.solon.core.runtime.NativeDetector;
|
||||
|
||||
/**
|
||||
* 代理配置
|
||||
@@ -32,182 +13,20 @@ import java.util.List;
|
||||
* @date: 2022/10/8
|
||||
*/
|
||||
@Configuration
|
||||
public class ProxyConfiguration implements LifecycleBean {
|
||||
public class ProxyConfiguration extends ProxyMessageFactory {
|
||||
|
||||
@Override
|
||||
public void start() throws Throwable {
|
||||
List<ProxyMessageHandler> list = Solon.context().getBeansOfType(ProxyMessageHandler.class);
|
||||
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);
|
||||
public void stop() {
|
||||
Solon.stop();
|
||||
}
|
||||
|
||||
@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")
|
||||
public 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(@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;
|
||||
@Override
|
||||
public boolean isAotRuntime() {
|
||||
return NativeDetector.isAotRuntime();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public NeutrinoCoreRuntimeNativeRegistrar neutrinoCoreRuntimeNativeRegistrar() {
|
||||
public NeutrinoCoreRuntimeNativeRegistrar neutrinoCoreRuntimeNativeRegistrar(){
|
||||
return new NeutrinoCoreRuntimeNativeRegistrar();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
package org.dromara.neutrinoproxy.client.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.noear.solon.annotation.Component;
|
||||
import org.noear.solon.annotation.Inject;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author: aoshiguchen
|
||||
* @date: 2022/6/16
|
||||
*/
|
||||
@Data
|
||||
@Component
|
||||
public class SolonProxyConfig {
|
||||
@Inject("${neutrino.proxy.protocol}")
|
||||
private Protocol protocol;
|
||||
@Inject("${neutrino.proxy.tunnel}")
|
||||
private Tunnel tunnel;
|
||||
@Inject("${neutrino.proxy.client}")
|
||||
private Client client;
|
||||
|
||||
@Data
|
||||
public static class Protocol {
|
||||
private Integer maxFrameLength;
|
||||
private Integer lengthFieldOffset;
|
||||
private Integer lengthFieldLength;
|
||||
private Integer initialBytesToStrip;
|
||||
private Integer lengthAdjustment;
|
||||
private Integer readIdleTime;
|
||||
private Integer writeIdleTime;
|
||||
private Integer allIdleTimeSeconds;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Tunnel {
|
||||
private String keyStorePassword;
|
||||
private String jksPath;
|
||||
private String serverIp;
|
||||
private Integer serverPort;
|
||||
private Boolean sslEnable;
|
||||
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;
|
||||
}
|
||||
}
|
||||
+13
-112
@@ -1,22 +1,14 @@
|
||||
package org.dromara.neutrinoproxy.client.core;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
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 io.netty.bootstrap.Bootstrap;
|
||||
import io.netty.channel.*;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.noear.solon.Solon;
|
||||
import org.dromara.neutrinoproxy.client.config.ProxyConfiguration;
|
||||
import org.dromara.neutrinoproxy.client.config.SolonProxyConfig;
|
||||
import org.dromara.neutrinoproxy.client.sdk.config.ProxyConfig;
|
||||
import org.noear.solon.annotation.Component;
|
||||
import org.noear.solon.annotation.Init;
|
||||
import org.noear.solon.annotation.Inject;
|
||||
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 代理客户端服务
|
||||
* @author: aoshiguchen
|
||||
@@ -24,107 +16,16 @@ import java.util.concurrent.TimeUnit;
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class ProxyClientService {
|
||||
@Inject
|
||||
private ProxyConfig proxyConfig;
|
||||
@Inject("cmdTunnelBootstrap")
|
||||
private Bootstrap cmdTunnelBootstrap;
|
||||
@Inject("udpServerBootstrap")
|
||||
private Bootstrap udpServerBootstrap;
|
||||
private volatile Channel channel;
|
||||
/**
|
||||
* 重连次数
|
||||
*/
|
||||
private volatile int reconnectCount = 0;
|
||||
/**
|
||||
* 重连服务执行器
|
||||
*/
|
||||
private static final ScheduledExecutorService reconnectExecutor = Executors.newSingleThreadScheduledExecutor(new CustomThreadFactory("ClientReconnect"));
|
||||
|
||||
public class ProxyClientService{
|
||||
@Inject
|
||||
private ProxyConfiguration proxyConfiguration;
|
||||
@Inject
|
||||
private SolonProxyConfig solonProxyConfig;
|
||||
@Init
|
||||
public void init() {
|
||||
this.reconnectExecutor.scheduleWithFixedDelay(this::reconnect, 10, proxyConfig.getTunnel().getReconnection().getIntervalSeconds(), TimeUnit.SECONDS);
|
||||
|
||||
try {
|
||||
this.start();
|
||||
UdpServerUtil.initCache(proxyConfig, udpServerBootstrap);
|
||||
} catch (Exception e) {
|
||||
// 启动连不上也做一下重连,因此先catch异常
|
||||
log.error("[CmdChannel] start error", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void start() {
|
||||
if (StrUtil.isEmpty(proxyConfig.getTunnel().getServerIp())) {
|
||||
log.error("not found server-ip config.");
|
||||
Solon.stop();
|
||||
return;
|
||||
}
|
||||
if (null == proxyConfig.getTunnel().getServerPort()) {
|
||||
log.error("not found server-port config.");
|
||||
Solon.stop();
|
||||
return;
|
||||
}
|
||||
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.getTunnel().getLicenseKey())) {
|
||||
log.error("not found license-key config.");
|
||||
Solon.stop();
|
||||
return;
|
||||
}
|
||||
if (null == channel || !channel.isActive()) {
|
||||
try {
|
||||
connectProxyServer();
|
||||
} catch (Exception e) {
|
||||
log.error("client start error", e);
|
||||
}
|
||||
} else {
|
||||
channel.writeAndFlush(ProxyMessage.buildAuthMessage(proxyConfig.getTunnel().getLicenseKey(), ProxyUtil.getClientId()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接代理服务器
|
||||
*/
|
||||
private void connectProxyServer() throws InterruptedException {
|
||||
cmdTunnelBootstrap.connect()
|
||||
.addListener(new ChannelFutureListener() {
|
||||
|
||||
@Override
|
||||
public void operationComplete(ChannelFuture future) throws Exception {
|
||||
if (future.isSuccess()) {
|
||||
channel = future.channel();
|
||||
// 连接成功,向服务器发送客户端认证信息(licenseKey)
|
||||
ProxyUtil.setCmdChannel(future.channel());
|
||||
future.channel().writeAndFlush(ProxyMessage.buildAuthMessage(proxyConfig.getTunnel().getLicenseKey(), ProxyUtil.getClientId()));
|
||||
log.info("[CmdChannel] connect proxy server success. channelId:{}", future.channel().id().asLongText());
|
||||
|
||||
// reconnectServiceEnable = true;
|
||||
reconnectCount = 0;
|
||||
} else {
|
||||
log.info("[CmdChannel] connect proxy server failed!");
|
||||
}
|
||||
}
|
||||
}).sync();
|
||||
}
|
||||
|
||||
protected synchronized void reconnect() {
|
||||
if (null != channel) {
|
||||
if (channel.isActive()) {
|
||||
return;
|
||||
}
|
||||
channel.close();
|
||||
}
|
||||
|
||||
log.info("[CmdChannel] client reconnect seq:{}", ++reconnectCount);
|
||||
try {
|
||||
connectProxyServer();
|
||||
} catch (Exception e) {
|
||||
log.error("[CmdChannel] reconnect error", e);
|
||||
}
|
||||
log.info("start....");
|
||||
ProxyConfig proxyConfig = BeanUtil.toBean(solonProxyConfig, ProxyConfig.class);
|
||||
proxyConfiguration.start(proxyConfig);
|
||||
log.info("start success!");
|
||||
}
|
||||
}
|
||||
|
||||
-87
@@ -1,87 +0,0 @@
|
||||
package org.dromara.neutrinoproxy.client.handler;
|
||||
|
||||
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 io.netty.bootstrap.Bootstrap;
|
||||
import io.netty.channel.*;
|
||||
import org.noear.solon.annotation.Component;
|
||||
import org.noear.solon.annotation.Inject;
|
||||
|
||||
/**
|
||||
* 连接信息处理器
|
||||
* @author: aoshiguchen
|
||||
* @date: 2022/6/16
|
||||
*/
|
||||
@Match(type = Constants.ProxyDataTypeName.CONNECT)
|
||||
@Component
|
||||
public class ProxyMessageConnectHandler implements ProxyMessageHandler {
|
||||
@Inject("tcpProxyTunnelBootstrap")
|
||||
private Bootstrap tcpProxyTunnelBootstrap;
|
||||
@Inject("realServerBootstrap")
|
||||
private Bootstrap realServerBootstrap;
|
||||
@Inject
|
||||
private ProxyConfig proxyConfig;
|
||||
|
||||
@Override
|
||||
public void handle(ChannelHandlerContext ctx, ProxyMessage proxyMessage) {
|
||||
final Channel cmdChannel = ctx.channel();
|
||||
final String visitorId = proxyMessage.getInfo();
|
||||
String[] serverInfo = new String(proxyMessage.getData()).split(":");
|
||||
// @todo 在这里 处理负载均恒
|
||||
String ip = serverInfo[0];
|
||||
int port = Integer.parseInt(serverInfo[1]);
|
||||
// 连接真实的、被代理的服务
|
||||
realServerBootstrap.connect(ip, port).addListener(new ChannelFutureListener() {
|
||||
|
||||
@Override
|
||||
public void operationComplete(ChannelFuture future) throws Exception {
|
||||
|
||||
// 连接后端服务器成功
|
||||
if (future.isSuccess()) {
|
||||
final Channel realServerChannel = future.channel();
|
||||
realServerChannel.config().setOption(ChannelOption.AUTO_READ, false);
|
||||
|
||||
// 获取连接
|
||||
ProxyUtil.borrowTcpProxyChanel(tcpProxyTunnelBootstrap, new ProxyChannelBorrowListener() {
|
||||
|
||||
@Override
|
||||
public void success(Channel channel) {
|
||||
// 连接绑定
|
||||
channel.attr(Constants.NEXT_CHANNEL).set(realServerChannel);
|
||||
realServerChannel.attr(Constants.NEXT_CHANNEL).set(channel);
|
||||
|
||||
// 远程绑定
|
||||
channel.writeAndFlush(ProxyMessage.buildConnectMessage(visitorId + "@" + proxyConfig.getTunnel().getLicenseKey()));
|
||||
|
||||
realServerChannel.config().setOption(ChannelOption.AUTO_READ, true);
|
||||
ProxyUtil.addRealServerChannel(visitorId, realServerChannel);
|
||||
ProxyUtil.setRealServerChannelVisitorId(realServerChannel, visitorId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(Throwable cause) {
|
||||
ProxyMessage proxyMessage = new ProxyMessage();
|
||||
proxyMessage.setType(ProxyMessage.TYPE_DISCONNECT);
|
||||
proxyMessage.setInfo(visitorId);
|
||||
cmdChannel.writeAndFlush(proxyMessage);
|
||||
}
|
||||
});
|
||||
|
||||
} else {
|
||||
cmdChannel.writeAndFlush(ProxyMessage.buildDisconnectMessage(visitorId));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return ProxyDataTypeEnum.CONNECT.getDesc();
|
||||
}
|
||||
}
|
||||
@@ -38,13 +38,13 @@ neutrino:
|
||||
key-store-password: ${STORE_PASS:123456}
|
||||
jks-path: ${JKS_PATH:classpath:/test.jks}
|
||||
# 服务端IP
|
||||
server-ip: ${SERVER_IP:localhost}
|
||||
server-ip: ${SERVER_IP:}
|
||||
# 服务端端口(对应服务端app.yml中的tunnel.port、tunnel.ssl-port)
|
||||
server-port: ${SERVER_PORT:9002}
|
||||
# 是否启用SSL(注意:该配置必须和server-port对应上)
|
||||
ssl-enable: ${SSL_ENABLE:true}
|
||||
# 客户端连接唯一凭证
|
||||
license-key: ${LICENSE_KEY:ce554b47de80495b9d1996cd62084973}
|
||||
license-key: ${LICENSE_KEY:}
|
||||
# 客户端唯一身份标识(可忽略,若不设置首次启动会自动生成)
|
||||
client-id: ${CLIENT_ID:}
|
||||
# 是否开启隧道传输报文日志(日志级别为debug时开启才有效)
|
||||
|
||||
@@ -50,9 +50,6 @@ public interface Constants {
|
||||
AttributeKey<InetSocketAddress> SENDER = AttributeKey.newInstance("sender");
|
||||
|
||||
AttributeKey<Integer> SERVER_PORT = AttributeKey.newInstance("serverPort");
|
||||
|
||||
AttributeKey<String> DOMAIN = AttributeKey.newInstance("domain");
|
||||
|
||||
AttributeKey<String> REAL_REMOTE_IP = AttributeKey.newInstance("realRemoteIp");
|
||||
|
||||
|
||||
|
||||
+1
@@ -109,6 +109,7 @@ public class DBInitialize implements EventListener<AppLoadEndEvent> {
|
||||
}
|
||||
for (String tableName : initDataTableNameList) {
|
||||
// 表里没有数据的时候,才进行初始化操作
|
||||
|
||||
Object result = dbContext.exe(String.format("select count(1) from `%s`", tableName));
|
||||
if (result != null && ((Number) result).intValue() > 0) {
|
||||
continue;
|
||||
|
||||
+1
@@ -63,6 +63,7 @@ public class ProxyConfig {
|
||||
public static class Tcp {
|
||||
private Integer bossThreadCount;
|
||||
private Integer workThreadCount;
|
||||
private String domainName;
|
||||
private Integer httpProxyPort;
|
||||
private Integer httpsProxyPort;
|
||||
private String keyStorePassword;
|
||||
|
||||
+1
-6
@@ -16,7 +16,6 @@ import org.noear.solon.core.handle.Context;
|
||||
import org.noear.solon.core.handle.Handler;
|
||||
import org.noear.solon.core.route.RouterInterceptor;
|
||||
import org.noear.solon.core.route.RouterInterceptorChain;
|
||||
import org.noear.solon.validation.ValidatorException;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
@@ -82,12 +81,8 @@ public class BaseAuthInterceptor implements RouterInterceptor {
|
||||
return new ResponseBody<>()
|
||||
.setCode(exception.getCode())
|
||||
.setMsg(exception.getMsg());
|
||||
} else if (result instanceof ValidatorException) {
|
||||
return new ResponseBody<>()
|
||||
.setCode(ExceptionConstant.DONAME_PATTEN_ERROR.getCode())
|
||||
.setMsg(ExceptionConstant.DONAME_PATTEN_ERROR.getMsg())
|
||||
.setStack(ExceptionUtils.getStackTrace((Throwable) result));
|
||||
}
|
||||
|
||||
return new ResponseBody<>()
|
||||
.setCode(ExceptionConstant.SYSTEM_ERROR.getCode())
|
||||
.setMsg(ExceptionConstant.SYSTEM_ERROR.getMsg())
|
||||
|
||||
+3
-7
@@ -9,7 +9,6 @@ import org.noear.solon.annotation.Component;
|
||||
import org.noear.solon.core.handle.Context;
|
||||
import org.noear.solon.core.handle.Filter;
|
||||
import org.noear.solon.core.handle.FilterChain;
|
||||
import org.noear.solon.validation.ValidatorException;
|
||||
|
||||
/**
|
||||
* @author: aoshiguchen
|
||||
@@ -23,13 +22,9 @@ public class GlobalExceptionFilter implements Filter {
|
||||
public void doFilter(Context ctx, FilterChain chain) throws Throwable {
|
||||
try {
|
||||
chain.doFilter(ctx);
|
||||
} catch(ValidatorException ve){
|
||||
ctx.render(new ResponseBody<>()
|
||||
.setCode(ExceptionConstant.DONAME_PATTEN_ERROR.getCode())
|
||||
.setMsg(ExceptionConstant.DONAME_PATTEN_ERROR.getMsg())
|
||||
.setStack(ExceptionUtils.getStackTrace(ve)));
|
||||
} catch(Throwable e) {
|
||||
} catch (Throwable e) {
|
||||
log.error("global error", e);
|
||||
|
||||
if (e instanceof ServiceException) {
|
||||
ServiceException serviceException = (ServiceException) e;
|
||||
ctx.render(new ResponseBody<>()
|
||||
@@ -37,6 +32,7 @@ public class GlobalExceptionFilter implements Filter {
|
||||
.setMsg(serviceException.getMsg()));
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.render(new ResponseBody<>()
|
||||
.setCode(ExceptionConstant.SYSTEM_ERROR.getCode())
|
||||
.setMsg(ExceptionConstant.SYSTEM_ERROR.getMsg())
|
||||
|
||||
-3
@@ -61,9 +61,6 @@ public enum ExceptionConstant {
|
||||
AN_UNSUPPORTED_PROTOCOL(14002, "不支持的协议[{}]!"),
|
||||
PORT_MAPPING_SUBDONAME_CONNOT_REPEAT(14003, "子域名不能重复使用!"),
|
||||
|
||||
DONAME_CONNOT_REPEAT(14004, "域名不能重复解析!"),
|
||||
|
||||
DONAME_PATTEN_ERROR(14005, "域名格式不正确!"),
|
||||
// 调度管理(15000)
|
||||
JOB_INFO_NOT_EXIST(15000, "调度管理记录不存在"),
|
||||
SYSTEM_ERROR(500, "系统异常"),
|
||||
|
||||
-105
@@ -1,105 +0,0 @@
|
||||
package org.dromara.neutrinoproxy.server.controller;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.dromara.neutrinoproxy.server.base.page.PageInfo;
|
||||
import org.dromara.neutrinoproxy.server.base.page.PageQuery;
|
||||
import org.dromara.neutrinoproxy.server.base.proxy.ProxyConfig;
|
||||
import org.dromara.neutrinoproxy.server.constant.ExceptionConstant;
|
||||
import org.dromara.neutrinoproxy.server.constant.NetworkProtocolEnum;
|
||||
import org.dromara.neutrinoproxy.server.controller.req.proxy.*;
|
||||
import org.dromara.neutrinoproxy.server.controller.res.proxy.*;
|
||||
import org.dromara.neutrinoproxy.server.dal.entity.DomainMappingDO;
|
||||
import org.dromara.neutrinoproxy.server.service.DomainMappingService;
|
||||
import org.dromara.neutrinoproxy.server.util.ParamCheckUtil;
|
||||
import org.noear.solon.annotation.*;
|
||||
import org.noear.solon.validation.annotation.NotBlank;
|
||||
import org.noear.solon.validation.annotation.Valid;
|
||||
import org.noear.solon.validation.annotation.Validated;
|
||||
|
||||
/**
|
||||
* @author: aoshiguchen
|
||||
* @date: 2023/4/2
|
||||
*/
|
||||
@Slf4j
|
||||
@Valid
|
||||
@Mapping("/domain")
|
||||
@Controller
|
||||
public class DomainController {
|
||||
@Inject
|
||||
private ProxyConfig proxyConfig;
|
||||
|
||||
@Inject
|
||||
private DomainMappingService domainMappingService;
|
||||
|
||||
@Get
|
||||
@Mapping("/page")
|
||||
public PageInfo<DomainMappingDto> page(PageQuery pageQuery, DomainMappingDto req) {
|
||||
ParamCheckUtil.checkNotNull(pageQuery, "pageQuery");
|
||||
return domainMappingService.page(pageQuery, req);
|
||||
}
|
||||
|
||||
@Post
|
||||
@Mapping("/modify")
|
||||
public PortMappingCreateRes modify(@Validated DomainMappingDO req) {
|
||||
if (StringUtils.isBlank(req.getTargetPath())) {// targetPath,默认为127.0.0.1
|
||||
req.setTargetPath("127.0.0.1");
|
||||
}
|
||||
req.setProtocal(NetworkProtocolEnum.HTTP.getDesc());
|
||||
if (null == req.getSecurityGroupId()) {
|
||||
req.setSecurityGroupId(0);
|
||||
}
|
||||
return domainMappingService.modify(req);
|
||||
}
|
||||
|
||||
@Get
|
||||
@Mapping("/one/{id}")
|
||||
public DomainMappingDto one(Integer id) {
|
||||
return domainMappingService.one(id);
|
||||
}
|
||||
|
||||
@Post
|
||||
@Mapping("/update/enable-status")
|
||||
public PortMappingUpdateEnableStatusRes updateEnableStatus(PortMappingUpdateEnableStatusReq req) {
|
||||
return domainMappingService.updateEnableStatus(req);
|
||||
}
|
||||
|
||||
@Get
|
||||
@Mapping("/delete/{id}")
|
||||
public void delete(Integer id) {
|
||||
domainMappingService.delete(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定安全组
|
||||
* @param req portMappingId和securityGroupId
|
||||
*/
|
||||
@Post
|
||||
@Mapping("/bind/security-group")
|
||||
public void bindSecurityGroup(PortMappingBindSecurityGroupReq req) {
|
||||
domainMappingService.domainBindSecurityGroup(req.getId(), req.getSecurityGroupId());
|
||||
}
|
||||
|
||||
/**
|
||||
* 安全组解绑
|
||||
* @param id 端口映射Id
|
||||
*/
|
||||
@Post
|
||||
@Mapping("/unbind/security-group")
|
||||
public void unbindSecurityGroup(Integer id) {
|
||||
domainMappingService.domainUnbindSecurityGroup(id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 绑定安全组
|
||||
* @param domain
|
||||
*/
|
||||
@Get
|
||||
@Mapping("/available")
|
||||
public boolean exitDomain(@NotBlank String domain, Integer id) {
|
||||
return domainMappingService.exitDomain(domain, id);
|
||||
}
|
||||
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package org.dromara.neutrinoproxy.server.controller;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.neutrinoproxy.server.base.proxy.ProxyConfig;
|
||||
import org.noear.solon.annotation.Controller;
|
||||
import org.noear.solon.annotation.Get;
|
||||
import org.noear.solon.annotation.Inject;
|
||||
import org.noear.solon.annotation.Mapping;
|
||||
|
||||
/**
|
||||
* @author: aoshiguchen
|
||||
* @date: 2023/4/2
|
||||
*/
|
||||
@Slf4j
|
||||
@Mapping("/domain-name")
|
||||
@Controller
|
||||
public class DomainNameController {
|
||||
@Inject
|
||||
private ProxyConfig proxyConfig;
|
||||
|
||||
@Get
|
||||
@Mapping("/bind-info")
|
||||
public String bindInfo () {
|
||||
return proxyConfig.getServer().getTcp().getDomainName();
|
||||
}
|
||||
|
||||
}
|
||||
+6
-6
@@ -31,8 +31,6 @@ import org.dromara.neutrinoproxy.server.controller.res.proxy.*;
|
||||
import org.dromara.neutrinoproxy.server.service.LicenseService;
|
||||
import org.dromara.neutrinoproxy.server.util.ParamCheckUtil;
|
||||
import org.noear.solon.annotation.*;
|
||||
import org.noear.solon.validation.annotation.Valid;
|
||||
import org.noear.solon.validation.annotation.Validated;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -41,8 +39,6 @@ import java.util.List;
|
||||
* @author: aoshiguchen
|
||||
* @date: 2022/8/6
|
||||
*/
|
||||
|
||||
@Valid
|
||||
@Mapping("/license")
|
||||
@Controller
|
||||
public class LicenseController {
|
||||
@@ -105,14 +101,18 @@ public class LicenseController {
|
||||
@Post
|
||||
@Mapping("/update/enable-status")
|
||||
@Authorization(onlyAdmin = true)
|
||||
public LicenseUpdateEnableStatusRes updateEnableStatus(@Validated LicenseUpdateEnableStatusReq req) {
|
||||
public LicenseUpdateEnableStatusRes updateEnableStatus(LicenseUpdateEnableStatusReq req) {
|
||||
ParamCheckUtil.checkNotNull(req, "req");
|
||||
ParamCheckUtil.checkNotNull(req.getId(), "id");
|
||||
ParamCheckUtil.checkNotNull(req.getEnable(), "enable");
|
||||
|
||||
return licenseService.updateEnableStatus(req);
|
||||
}
|
||||
|
||||
@Post
|
||||
@Mapping("/delete")
|
||||
@Authorization(onlyAdmin = true)
|
||||
public void delete(@Validated LicenseDeleteReq req) {
|
||||
public void delete(LicenseDeleteReq req) {
|
||||
ParamCheckUtil.checkNotNull(req, "req");
|
||||
ParamCheckUtil.checkNotNull(req.getId(), "id");
|
||||
|
||||
|
||||
+8
-2
@@ -51,7 +51,10 @@ public class PortMappingController {
|
||||
}
|
||||
NetworkProtocolEnum networkProtocolEnum = NetworkProtocolEnum.of(req.getProtocal());
|
||||
ParamCheckUtil.checkNotNull(networkProtocolEnum, ExceptionConstant.AN_UNSUPPORTED_PROTOCOL, req.getProtocal());
|
||||
|
||||
if (networkProtocolEnum != NetworkProtocolEnum.HTTP) {
|
||||
// 目前仅HTTP支持绑定域名
|
||||
req.setSubdomain(null);
|
||||
}
|
||||
req.setProtocal(networkProtocolEnum.getDesc());
|
||||
if (null == req.getProxyResponses()) {
|
||||
req.setProxyResponses(0);
|
||||
@@ -83,7 +86,10 @@ public class PortMappingController {
|
||||
}
|
||||
NetworkProtocolEnum networkProtocolEnum = NetworkProtocolEnum.of(req.getProtocal());
|
||||
ParamCheckUtil.checkNotNull(networkProtocolEnum, ExceptionConstant.AN_UNSUPPORTED_PROTOCOL, req.getProtocal());
|
||||
|
||||
if (networkProtocolEnum != NetworkProtocolEnum.HTTP) {
|
||||
// 目前仅HTTP支持绑定域名
|
||||
req.setSubdomain(null);
|
||||
}
|
||||
req.setProtocal(networkProtocolEnum.getDesc());
|
||||
if (null == req.getProxyResponses()) {
|
||||
req.setProxyResponses(0);
|
||||
|
||||
-4
@@ -1,8 +1,6 @@
|
||||
package org.dromara.neutrinoproxy.server.controller.req.proxy;
|
||||
|
||||
import lombok.Data;
|
||||
import org.noear.solon.validation.annotation.Min;
|
||||
import org.noear.solon.validation.annotation.NotNull;
|
||||
|
||||
/**
|
||||
* license删除请求
|
||||
@@ -11,7 +9,5 @@ import org.noear.solon.validation.annotation.NotNull;
|
||||
*/
|
||||
@Data
|
||||
public class LicenseDeleteReq {
|
||||
@NotNull
|
||||
@Min(value=2, message="服务端禁止删除")
|
||||
private Integer id;
|
||||
}
|
||||
|
||||
+5
-8
@@ -23,7 +23,6 @@ package org.dromara.neutrinoproxy.server.controller.req.proxy;
|
||||
|
||||
import lombok.Data;
|
||||
import org.dromara.neutrinoproxy.server.constant.EnableStatusEnum;
|
||||
import org.noear.solon.validation.annotation.NotNull;
|
||||
|
||||
/**
|
||||
* 更新启用状态请求
|
||||
@@ -32,15 +31,13 @@ import org.noear.solon.validation.annotation.NotNull;
|
||||
*/
|
||||
@Data
|
||||
public class LicenseUpdateEnableStatusReq {
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
@NotNull
|
||||
private Integer id;
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
private Integer id;
|
||||
/**
|
||||
* 启用状态
|
||||
* {@link EnableStatusEnum}
|
||||
*/
|
||||
@NotNull
|
||||
private Integer enable;
|
||||
private Integer enable;
|
||||
}
|
||||
|
||||
+4
@@ -38,6 +38,10 @@ public class PortMappingCreateReq {
|
||||
* 协议
|
||||
*/
|
||||
private String protocal;
|
||||
/**
|
||||
* 子域名
|
||||
*/
|
||||
private String subdomain;
|
||||
/**
|
||||
* 服务端端口
|
||||
*/
|
||||
|
||||
-3
@@ -22,7 +22,6 @@
|
||||
package org.dromara.neutrinoproxy.server.controller.req.proxy;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.NonNull;
|
||||
|
||||
/**
|
||||
* 端口映射更新启用状态请求
|
||||
@@ -35,12 +34,10 @@ public class PortMappingUpdateEnableStatusReq {
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
@NonNull
|
||||
private Integer id;
|
||||
/**
|
||||
* 启用状态
|
||||
*/
|
||||
@NonNull
|
||||
private Integer enable;
|
||||
|
||||
}
|
||||
|
||||
+4
@@ -42,6 +42,10 @@ public class PortMappingUpdateReq {
|
||||
* 协议
|
||||
*/
|
||||
private String protocal;
|
||||
/**
|
||||
* 子域名
|
||||
*/
|
||||
private String subdomain;
|
||||
/**
|
||||
* 服务端端口
|
||||
*/
|
||||
|
||||
-31
@@ -1,31 +0,0 @@
|
||||
package org.dromara.neutrinoproxy.server.controller.res.proxy;
|
||||
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.dromara.neutrinoproxy.server.dal.entity.DomainMappingDO;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author xiaojie
|
||||
* @date
|
||||
*/
|
||||
@Accessors(chain = true)
|
||||
@Data
|
||||
public class DomainMappingDto extends DomainMappingDO {
|
||||
|
||||
/**
|
||||
* licenseId
|
||||
*/
|
||||
private String licenseName;
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
private Integer userId;
|
||||
|
||||
/**
|
||||
* 用户名称
|
||||
*/
|
||||
private String userName;
|
||||
}
|
||||
+4
@@ -43,6 +43,10 @@ public class PortMappingListRes {
|
||||
* 协议
|
||||
*/
|
||||
private String protocal;
|
||||
/**
|
||||
* 子域名
|
||||
*/
|
||||
private String subdomain;
|
||||
/**
|
||||
* 域名
|
||||
*/
|
||||
|
||||
-79
@@ -1,79 +0,0 @@
|
||||
package org.dromara.neutrinoproxy.server.dal;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.dromara.neutrinoproxy.server.constant.EnableStatusEnum;
|
||||
import org.dromara.neutrinoproxy.server.controller.req.proxy.PortMappingListReq;
|
||||
import org.dromara.neutrinoproxy.server.controller.res.proxy.DomainMappingDto;
|
||||
import org.dromara.neutrinoproxy.server.dal.entity.DomainMappingDO;
|
||||
import org.dromara.neutrinoproxy.server.dal.entity.DomainMappingDO;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author: aoshiguchen
|
||||
* @date: 2022/8/8
|
||||
*/
|
||||
@Mapper
|
||||
public interface DomainMappingMapper extends BaseMapper<DomainMappingDO> {
|
||||
|
||||
default DomainMappingDO findById(Integer id) {
|
||||
return this.selectById(id);
|
||||
}
|
||||
|
||||
default void updateEnableStatus(Integer id, Integer enable, Date updateTime) {
|
||||
this.update(null, new LambdaUpdateWrapper<DomainMappingDO>()
|
||||
.eq(DomainMappingDO::getId, id)
|
||||
.set(DomainMappingDO::getEnable, enable)
|
||||
.set(DomainMappingDO::getUpdateTime, updateTime)
|
||||
);
|
||||
}
|
||||
|
||||
default DomainMappingDO findByDomain(String domain, Set<Integer> excludeIds) {
|
||||
return this.selectOne(new LambdaQueryWrapper<DomainMappingDO>()
|
||||
.eq(DomainMappingDO::getDomain, domain)
|
||||
.notIn(!CollectionUtil.isEmpty(excludeIds), DomainMappingDO::getId, excludeIds)
|
||||
.last("limit 1")
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
default List<DomainMappingDO> findEnableListByLicenseId(Integer licenseId) {
|
||||
return this.selectList(new LambdaQueryWrapper<DomainMappingDO>()
|
||||
.eq(DomainMappingDO::getLicenseId, licenseId)
|
||||
.eq(DomainMappingDO::getEnable, EnableStatusEnum.ENABLE.getStatus())
|
||||
);
|
||||
}
|
||||
|
||||
default List<DomainMappingDO> findListByServerPort(String domain) {
|
||||
return this.selectList(new LambdaQueryWrapper<DomainMappingDO>()
|
||||
.eq(DomainMappingDO::getDomain, domain)
|
||||
);
|
||||
}
|
||||
|
||||
default List<DomainMappingDO> findListByLicenseId(Integer licenseId) {
|
||||
return this.selectList(new LambdaQueryWrapper<DomainMappingDO>()
|
||||
.eq(DomainMappingDO::getLicenseId, licenseId)
|
||||
);
|
||||
}
|
||||
|
||||
default DomainMappingDO findByLicenseIdAndServerPort(Integer licenseId, String domain) {
|
||||
return this.selectOne(new LambdaQueryWrapper<DomainMappingDO>()
|
||||
.eq(DomainMappingDO::getLicenseId, licenseId)
|
||||
.eq(DomainMappingDO::getDomain, domain)
|
||||
.last("limit 1")
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
List<DomainMappingDO> selectDomainMappingByCondition(IPage<DomainMappingDO> page, @Param("req") DomainMappingDto req);
|
||||
}
|
||||
+5
-12
@@ -26,7 +26,6 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.dromara.neutrinoproxy.server.dal.entity.LicenseDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.dromara.neutrinoproxy.server.proxy.domain.ProxyMapping;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
@@ -65,18 +64,16 @@ public interface LicenseMapper extends BaseMapper<LicenseDO> {
|
||||
|
||||
default void updateOnlineStatus(Integer id, Integer isOnline, Date updateTime) {
|
||||
this.update(null, new LambdaUpdateWrapper<LicenseDO>()
|
||||
.eq(LicenseDO::getId, id)
|
||||
.set(LicenseDO::getIsOnline, isOnline)
|
||||
.set(LicenseDO::getUpdateTime, updateTime)
|
||||
.eq(LicenseDO::getId, id)
|
||||
.set(LicenseDO::getIsOnline, isOnline)
|
||||
.set(LicenseDO::getUpdateTime, updateTime)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// .ne(LicenseDO::getId, 1)
|
||||
default void updateOnlineStatus(Integer isOnline, Date updateTime) {
|
||||
this.update(null, new LambdaUpdateWrapper<LicenseDO>()
|
||||
.set(LicenseDO::getIsOnline, isOnline)
|
||||
.set(LicenseDO::getUpdateTime, updateTime)
|
||||
.set(LicenseDO::getIsOnline, isOnline)
|
||||
.set(LicenseDO::getUpdateTime, updateTime)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -118,8 +115,4 @@ public interface LicenseMapper extends BaseMapper<LicenseDO> {
|
||||
.eq(LicenseDO::getKey, licenseKey)
|
||||
);
|
||||
}
|
||||
|
||||
List<ProxyMapping> findEnableProxyMappingListByLicenseId(Integer licenseId);
|
||||
|
||||
List<ProxyMapping> findAllProxyMappingListByLicenseId(Integer licenseId);
|
||||
}
|
||||
|
||||
+12
@@ -44,6 +44,18 @@ public interface PortMappingMapper extends BaseMapper<PortMappingDO> {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验子域名是否重复
|
||||
* @param subdomain
|
||||
* @return
|
||||
*/
|
||||
default Boolean checkRepeatBySubdomain(String subdomain, Set<Integer> excludeIds) {
|
||||
return StringUtils.isEmpty(subdomain)? Boolean.FALSE : this.selectCount(new LambdaQueryWrapper<PortMappingDO>()
|
||||
.eq(PortMappingDO::getSubdomain, subdomain)
|
||||
.notIn(!CollectionUtil.isEmpty(excludeIds), PortMappingDO::getId, excludeIds)
|
||||
).intValue() > 0;
|
||||
}
|
||||
|
||||
default List<PortMappingDO> findEnableListByLicenseId(Integer licenseId) {
|
||||
return this.selectList(new LambdaQueryWrapper<PortMappingDO>()
|
||||
.eq(PortMappingDO::getLicenseId, licenseId)
|
||||
|
||||
-120
@@ -1,120 +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.server.dal.entity;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.dromara.neutrinoproxy.server.constant.EnableStatusEnum;
|
||||
import org.dromara.neutrinoproxy.server.constant.OnlineStatusEnum;
|
||||
import org.dromara.neutrinoproxy.server.controller.res.proxy.DomainMappingDto;
|
||||
import org.noear.solon.validation.annotation.NotBlank;
|
||||
import org.noear.solon.validation.annotation.NotNull;
|
||||
import org.noear.solon.validation.annotation.Pattern;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 端口映射
|
||||
* @author: aoshiguchen
|
||||
* @date: 2022/8/8
|
||||
*/
|
||||
@ToString
|
||||
@Accessors(chain = true)
|
||||
@Data
|
||||
@TableName("domain_mapping")
|
||||
public class DomainMappingDO {
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Integer id;
|
||||
/**
|
||||
* licenseId
|
||||
*/
|
||||
@NotNull
|
||||
private Integer licenseId;
|
||||
/**
|
||||
* 协议
|
||||
*/
|
||||
private String protocal;
|
||||
/**
|
||||
* 域名 /^(\w+\.{1}\w+)$/g
|
||||
*/
|
||||
@NotBlank
|
||||
@Pattern("^(?=^.{3,255}$)[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+$")
|
||||
private String domain;
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
private String description;
|
||||
/**
|
||||
* 目标地址(licenseId客户端,ip:port)
|
||||
*/
|
||||
@NotBlank
|
||||
private String targetPath;
|
||||
|
||||
/**
|
||||
* 上传限速
|
||||
*/
|
||||
private String upLimitRate;
|
||||
/**
|
||||
* 下载限速
|
||||
*/
|
||||
private String downLimitRate;
|
||||
|
||||
/**
|
||||
* 是否在线
|
||||
* {@link OnlineStatusEnum}
|
||||
*/
|
||||
@TableField(exist=false)
|
||||
private Integer isOnline;
|
||||
|
||||
/**
|
||||
* 启用状态
|
||||
* {@link EnableStatusEnum}
|
||||
*/
|
||||
private Integer enable;
|
||||
|
||||
/**
|
||||
* 安全组Id
|
||||
*/
|
||||
private Integer securityGroupId = 0; // 设置为null不生效,不知道为啥
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private Date updateTime;
|
||||
|
||||
public DomainMappingDto toRes() {
|
||||
DomainMappingDto dto = new DomainMappingDto();
|
||||
BeanUtil.copyProperties(this, dto);
|
||||
return dto;
|
||||
}
|
||||
|
||||
}
|
||||
-17
@@ -87,23 +87,6 @@ public class LicenseDO {
|
||||
*/
|
||||
private Date updateTime;
|
||||
|
||||
|
||||
public LicenseDO() {
|
||||
}
|
||||
|
||||
public LicenseDO(Integer id, String name, String key, Integer userId, String upLimitRate, String downLimitRate, Integer isOnline, Integer enable, Date createTime, Date updateTime) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.key = key;
|
||||
this.userId = userId;
|
||||
this.upLimitRate = upLimitRate;
|
||||
this.downLimitRate = downLimitRate;
|
||||
this.isOnline = isOnline;
|
||||
this.enable = enable;
|
||||
this.createTime = createTime;
|
||||
this.updateTime = updateTime;
|
||||
}
|
||||
|
||||
public LicenseListRes toRes() {
|
||||
LicenseListRes res = new LicenseListRes();
|
||||
BeanUtil.copyProperties(this, res);
|
||||
|
||||
+4
-2
@@ -31,7 +31,6 @@ import lombok.Data;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.dromara.neutrinoproxy.server.controller.res.proxy.PortMappingListRes;
|
||||
import org.dromara.neutrinoproxy.server.proxy.domain.ProxyMapping;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@@ -55,6 +54,10 @@ public class PortMappingDO {
|
||||
* 协议
|
||||
*/
|
||||
private String protocal;
|
||||
/**
|
||||
* 子域名
|
||||
*/
|
||||
private String subdomain;
|
||||
/**
|
||||
* 服务端端口
|
||||
*/
|
||||
@@ -118,5 +121,4 @@ public class PortMappingDO {
|
||||
BeanUtil.copyProperties(this, res);
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ import org.noear.solon.annotation.Component;
|
||||
@Slf4j
|
||||
@Component
|
||||
@JobHandler(name = "DemoJob", cron = "0/10 * * * * ?", param = "{\"a\":1}")
|
||||
public class DemoJob implements IJobHandler {
|
||||
public class DemoJob implements IJobHandler {
|
||||
|
||||
@Override
|
||||
public void execute(String param) throws Exception {
|
||||
|
||||
+4
-4
@@ -63,9 +63,9 @@ public class ProxyTunnelServer implements EventListener<AppLoadEndEvent> {
|
||||
});
|
||||
try {
|
||||
bootstrap.bind(proxyConfig.getTunnel().getPort()).sync();
|
||||
log.info("ProxyTunnelServer,port:{}", proxyConfig.getTunnel().getPort());
|
||||
log.info("proxy server started,port:{}", proxyConfig.getTunnel().getPort());
|
||||
} catch (Exception e) {
|
||||
log.error("ProxyTunnelServer error", e);
|
||||
log.error("proxy server error", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,9 +84,9 @@ public class ProxyTunnelServer implements EventListener<AppLoadEndEvent> {
|
||||
});
|
||||
try {
|
||||
bootstrap.bind(proxyConfig.getTunnel().getSslPort()).sync();
|
||||
log.info("ProxyTunnelServer,SSL port: {}", proxyConfig.getTunnel().getSslPort());
|
||||
log.info("proxy server started,SSL port: {}", proxyConfig.getTunnel().getSslPort());
|
||||
} catch (Exception e) {
|
||||
log.error("ProxyTunnelServer error", e);
|
||||
log.error("proxy server error", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
-39
@@ -1,39 +0,0 @@
|
||||
package org.dromara.neutrinoproxy.server.proxy.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author xiaojie
|
||||
* @date
|
||||
*/
|
||||
@Data
|
||||
public class DomainMapping {
|
||||
|
||||
/**
|
||||
* domainMapping 主键id
|
||||
*/
|
||||
private Integer id;
|
||||
/**
|
||||
* License
|
||||
*/
|
||||
private Integer licenseId;
|
||||
/**
|
||||
* 客户端信息 IP:port
|
||||
*/
|
||||
private String domain;
|
||||
/**
|
||||
* 目标地址(其中含有\n隔离多个 目标地址)
|
||||
*/
|
||||
private String targetPath;
|
||||
|
||||
|
||||
public DomainMapping() {
|
||||
}
|
||||
|
||||
public DomainMapping(Integer id, Integer licenseId, String domain, String targetPath) {
|
||||
this.id = id;
|
||||
this.licenseId = licenseId;
|
||||
this.domain = domain;
|
||||
this.targetPath = targetPath;
|
||||
}
|
||||
}
|
||||
+3
-27
@@ -16,10 +16,6 @@ import java.util.List;
|
||||
@Accessors(chain = true)
|
||||
@Data
|
||||
public class ProxyMapping {
|
||||
/**
|
||||
* licenseId
|
||||
*/
|
||||
private Integer licenseId;
|
||||
/**
|
||||
* 服务端端口
|
||||
*/
|
||||
@@ -28,23 +24,8 @@ public class ProxyMapping {
|
||||
* 客户端信息 IP:port
|
||||
*/
|
||||
private String lanInfo;
|
||||
/**
|
||||
* 协议
|
||||
*/
|
||||
private String protocal;
|
||||
|
||||
|
||||
public ProxyMapping() {
|
||||
}
|
||||
|
||||
public ProxyMapping(Integer licenseId, Integer serverPort, String lanInfo, String protocal) {
|
||||
this.licenseId = licenseId;
|
||||
this.serverPort = serverPort;
|
||||
this.lanInfo = lanInfo;
|
||||
this.protocal = protocal;
|
||||
}
|
||||
|
||||
public static List<ProxyMapping> buildList(List<PortMappingDO> portMappingList) {
|
||||
public static List<ProxyMapping> buildList(List<PortMappingDO> portMappingList) {
|
||||
List<ProxyMapping> list = new ArrayList<>();
|
||||
if (CollectionUtil.isEmpty(portMappingList)) {
|
||||
return list;
|
||||
@@ -57,13 +38,8 @@ public class ProxyMapping {
|
||||
|
||||
public static ProxyMapping build(PortMappingDO portMappingDO) {
|
||||
return new ProxyMapping()
|
||||
.setLicenseId(portMappingDO.getLicenseId())
|
||||
.setServerPort(portMappingDO.getServerPort())
|
||||
.setLanInfo(String.format("%s:%s", portMappingDO.getClientIp(), portMappingDO.getClientPort()))
|
||||
.setProtocal(portMappingDO.getProtocal());
|
||||
.setServerPort(portMappingDO.getServerPort())
|
||||
.setLanInfo(String.format("%s:%s", portMappingDO.getClientIp(), portMappingDO.getClientPort()));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
+20
-41
@@ -1,9 +1,8 @@
|
||||
package org.dromara.neutrinoproxy.server.proxy.enhance;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import io.netty.bootstrap.ServerBootstrap;
|
||||
import io.netty.channel.ChannelFuture;
|
||||
import io.netty.channel.ChannelInitializer;
|
||||
import io.netty.channel.EventLoopGroup;
|
||||
import io.netty.channel.*;
|
||||
import io.netty.channel.nio.NioEventLoopGroup;
|
||||
import io.netty.channel.socket.SocketChannel;
|
||||
import io.netty.channel.socket.nio.NioServerSocketChannel;
|
||||
@@ -11,6 +10,7 @@ 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.dromara.neutrinoproxy.server.proxy.security.HttpVisitorSecurityChannelHandler;
|
||||
import org.dromara.neutrinoproxy.server.proxy.security.VisitorFlowLimiterChannelHandler;
|
||||
import org.noear.solon.annotation.Component;
|
||||
@@ -19,8 +19,7 @@ import org.noear.solon.core.event.AppLoadEndEvent;
|
||||
import org.noear.solon.core.event.EventListener;
|
||||
|
||||
/**
|
||||
* 应用加载完成事件(即启动完成)- 判断是否配置域名-配置了域名则启动HTTP代理
|
||||
* 默认端口 80
|
||||
* HTTP代理
|
||||
* @author: aoshiguchen
|
||||
* @date: 2023/4/2
|
||||
*/
|
||||
@@ -29,55 +28,35 @@ import org.noear.solon.core.event.EventListener;
|
||||
public class HttpProxy implements EventListener<AppLoadEndEvent> {
|
||||
@Inject
|
||||
private ProxyConfig proxyConfig;
|
||||
|
||||
/**
|
||||
* NioServerSocketChannel对应的future
|
||||
*/
|
||||
protected ChannelFuture httpFuture;
|
||||
@Override
|
||||
public void onEvent(AppLoadEndEvent appLoadEndEvent) throws Throwable {
|
||||
if (null == proxyConfig.getServer().getTcp().getHttpProxyPort()) {
|
||||
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() {
|
||||
// 处理网络连接---接受请求
|
||||
EventLoopGroup bossGroup = new NioEventLoopGroup(1);
|
||||
// 进行socketChannel的网络读写
|
||||
EventLoopGroup workerGroup = new NioEventLoopGroup();
|
||||
try {
|
||||
ServerBootstrap bootstrap = new ServerBootstrap();
|
||||
bootstrap.group(bossGroup, workerGroup)
|
||||
.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())
|
||||
.addLast(new HttpVisitorSecurityChannelHandler())
|
||||
.addLast("flowLimiter",new VisitorFlowLimiterChannelHandler())
|
||||
.addLast(new HttpVisitorChannelHandler());
|
||||
}
|
||||
});
|
||||
httpFuture = bootstrap.bind("0.0.0.0", proxyConfig.getServer().getTcp().getHttpProxyPort()).sync();
|
||||
log.info("Http proxy server started success!port:{}", proxyConfig.getServer().getTcp().getHttpProxyPort());
|
||||
//添加关闭重启的监听器,3秒后尝试重启
|
||||
// httpFuture.channel().closeFuture().addListener(genericFutureListener);
|
||||
// httpFuture.channel().closeFuture().sync();
|
||||
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 HttpVisitorSecurityChannelHandler(proxyConfig.getServer().getTcp().getDomainName()));
|
||||
ch.pipeline().addLast("flowLimiter",new VisitorFlowLimiterChannelHandler());
|
||||
ch.pipeline().addLast(new HttpVisitorChannelHandler());
|
||||
}
|
||||
});
|
||||
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);
|
||||
} finally {
|
||||
// bossGroup.shutdownGracefully();
|
||||
// workerGroup.shutdownGracefully();
|
||||
// httpFuture.channel().close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+8
-3
@@ -19,7 +19,6 @@ import org.noear.solon.Solon;
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
/**
|
||||
* HTTP 访客处理器
|
||||
* @author: aoshiguchen
|
||||
* @date: 2023/5/27
|
||||
*/
|
||||
@@ -31,7 +30,6 @@ public class HttpVisitorChannelHandler extends SimpleChannelInboundHandler<ByteB
|
||||
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) {
|
||||
@@ -39,11 +37,14 @@ public class HttpVisitorChannelHandler extends SimpleChannelInboundHandler<ByteB
|
||||
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();
|
||||
@@ -52,10 +53,11 @@ public class HttpVisitorChannelHandler extends SimpleChannelInboundHandler<ByteB
|
||||
|
||||
// 用户连接到代理服务器时,设置用户连接不可读,等待代理后端服务器连接成功后再改变为可读状态
|
||||
ctx.channel().config().setOption(ChannelOption.AUTO_READ, false);
|
||||
|
||||
|
||||
// 根据域名拿到绑定的映射对应的cmdChannel
|
||||
Integer serverPort = ctx.channel().attr(Constants.SERVER_PORT).get();
|
||||
Channel cmdChannel = ProxyUtil.getCmdChannelByServerPort(serverPort);
|
||||
|
||||
if (null == cmdChannel) {
|
||||
ctx.channel().close();
|
||||
return;
|
||||
@@ -65,6 +67,7 @@ public class HttpVisitorChannelHandler extends SimpleChannelInboundHandler<ByteB
|
||||
ctx.channel().close();
|
||||
return;
|
||||
}
|
||||
|
||||
visitorId = ProxyUtil.newVisitorId();
|
||||
ProxyUtil.addVisitorChannelToCmdChannel(NetworkProtocolEnum.HTTP, cmdChannel, visitorId, ctx.channel(), serverPort);
|
||||
ProxyUtil.addProxyConnectAttachment(visitorId, proxyAttachment);
|
||||
@@ -73,6 +76,7 @@ public class HttpVisitorChannelHandler extends SimpleChannelInboundHandler<ByteB
|
||||
|
||||
@Override
|
||||
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
||||
|
||||
// 通知代理客户端
|
||||
Channel visitorChannel = ctx.channel();
|
||||
InetSocketAddress sa = (InetSocketAddress) visitorChannel.localAddress();
|
||||
@@ -82,6 +86,7 @@ public class HttpVisitorChannelHandler extends SimpleChannelInboundHandler<ByteB
|
||||
// 该端口还没有代理客户端
|
||||
ctx.channel().close();
|
||||
} else {
|
||||
|
||||
// 用户连接断开,从控制连接中移除
|
||||
String visitorId = ProxyUtil.getVisitorIdByChannel(visitorChannel);
|
||||
ProxyUtil.removeVisitorChannelFromCmdChannel(cmdChannel, visitorId);
|
||||
|
||||
+22
-44
@@ -1,10 +1,8 @@
|
||||
package org.dromara.neutrinoproxy.server.proxy.enhance;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import io.netty.bootstrap.ServerBootstrap;
|
||||
import io.netty.channel.ChannelFuture;
|
||||
import io.netty.channel.ChannelHandler;
|
||||
import io.netty.channel.ChannelInitializer;
|
||||
import io.netty.channel.EventLoopGroup;
|
||||
import io.netty.channel.*;
|
||||
import io.netty.channel.nio.NioEventLoopGroup;
|
||||
import io.netty.channel.socket.SocketChannel;
|
||||
import io.netty.channel.socket.nio.NioServerSocketChannel;
|
||||
@@ -15,6 +13,7 @@ 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.dromara.neutrinoproxy.server.proxy.security.HttpVisitorSecurityChannelHandler;
|
||||
import org.dromara.neutrinoproxy.server.proxy.security.VisitorFlowLimiterChannelHandler;
|
||||
import org.noear.solon.annotation.Component;
|
||||
@@ -22,16 +21,12 @@ import org.noear.solon.annotation.Inject;
|
||||
import org.noear.solon.core.event.AppLoadEndEvent;
|
||||
import org.noear.solon.core.event.EventListener;
|
||||
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLEngine;
|
||||
import javax.net.ssl.TrustManager;
|
||||
import javax.net.ssl.*;
|
||||
import java.io.InputStream;
|
||||
import java.security.KeyStore;
|
||||
|
||||
/**
|
||||
* 应用加载完成事件(即启动完成)- 判断是否配置域名-配置了域名则启动HTTPS代理
|
||||
* 默认端口 443
|
||||
* HTTPS代理
|
||||
* @author: aoshiguchen
|
||||
* @date: 2023/4/2
|
||||
*/
|
||||
@@ -40,15 +35,10 @@ import java.security.KeyStore;
|
||||
public class HttpsProxy implements EventListener<AppLoadEndEvent> {
|
||||
@Inject
|
||||
private ProxyConfig proxyConfig;
|
||||
/**
|
||||
* NioServerSocketChannel对应的future
|
||||
*/
|
||||
private ChannelFuture httpsFuture;
|
||||
@Override
|
||||
public void onEvent(AppLoadEndEvent appLoadEndEvent) throws Throwable {
|
||||
if (null == proxyConfig.getServer().getTcp().getHttpsProxyPort() ||
|
||||
StringUtils.isEmpty(proxyConfig.getServer().getTcp().getJksPath()) ||
|
||||
StringUtils.isEmpty(proxyConfig.getServer().getTcp().getKeyStorePassword())) {
|
||||
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;
|
||||
}
|
||||
@@ -56,38 +46,26 @@ public class HttpsProxy implements EventListener<AppLoadEndEvent> {
|
||||
}
|
||||
|
||||
private void start() {
|
||||
// 处理网络连接---接受请求
|
||||
EventLoopGroup bossGroup = new NioEventLoopGroup(1);
|
||||
// 进行socketChannel的网络读写
|
||||
EventLoopGroup workerGroup = new NioEventLoopGroup();
|
||||
try {
|
||||
ServerBootstrap bootstrap = new ServerBootstrap();
|
||||
bootstrap.group(bossGroup, workerGroup);
|
||||
bootstrap.channel(NioServerSocketChannel.class);
|
||||
bootstrap.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())
|
||||
.addFirst(new BytesMetricsHandler())
|
||||
.addLast(new HttpVisitorSecurityChannelHandler())
|
||||
.addLast("flowLimiter", new VisitorFlowLimiterChannelHandler())
|
||||
.addLast(new HttpVisitorChannelHandler());
|
||||
}
|
||||
});
|
||||
httpsFuture = bootstrap.bind("0.0.0.0", proxyConfig.getServer().getTcp().getHttpsProxyPort()).sync();
|
||||
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 HttpVisitorSecurityChannelHandler(proxyConfig.getServer().getTcp().getDomainName()));
|
||||
ch.pipeline().addLast("flowLimiter",new VisitorFlowLimiterChannelHandler());
|
||||
ch.pipeline().addLast(new HttpVisitorChannelHandler());
|
||||
}
|
||||
});
|
||||
bootstrap.bind("0.0.0.0", proxyConfig.getServer().getTcp().getHttpsProxyPort()).sync();
|
||||
log.info("Https proxy server started!port:{}", proxyConfig.getServer().getTcp().getHttpsProxyPort());
|
||||
//添加关闭重启的监听器,3秒后尝试重启
|
||||
// httpsFuture.channel().closeFuture().addListener(genericFutureListener);
|
||||
// httpsFuture.channel().closeFuture().sync();
|
||||
} catch (Exception e) {
|
||||
log.error("https proxy start err!", e);
|
||||
} finally {
|
||||
// bossGroup.shutdownGracefully();
|
||||
// workerGroup.shutdownGracefully();
|
||||
// httpsFuture.channel().close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
@@ -24,6 +24,7 @@ package org.dromara.neutrinoproxy.server.proxy.handler;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import org.dromara.neutrinoproxy.core.*;
|
||||
import org.dromara.neutrinoproxy.core.*;
|
||||
import org.dromara.neutrinoproxy.core.dispatcher.Match;
|
||||
import org.dromara.neutrinoproxy.server.base.proxy.ProxyConfig;
|
||||
import org.dromara.neutrinoproxy.server.constant.ClientConnectTypeEnum;
|
||||
|
||||
+36
-15
@@ -1,5 +1,6 @@
|
||||
package org.dromara.neutrinoproxy.server.proxy.security;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||
@@ -8,59 +9,79 @@ import org.apache.commons.lang3.StringUtils;
|
||||
import org.dromara.neutrinoproxy.core.Constants;
|
||||
import org.dromara.neutrinoproxy.core.util.HttpUtil;
|
||||
import org.dromara.neutrinoproxy.core.util.IpUtil;
|
||||
import org.dromara.neutrinoproxy.server.proxy.domain.DomainMapping;
|
||||
import org.dromara.neutrinoproxy.server.service.PortMappingService;
|
||||
import org.dromara.neutrinoproxy.server.service.SecurityGroupService;
|
||||
import org.dromara.neutrinoproxy.server.util.ProxyUtil;
|
||||
import org.noear.solon.Solon;
|
||||
|
||||
/**
|
||||
* HTTP 访问安全检测
|
||||
* @author: aoshiguchen
|
||||
* @date: 2023/12/14
|
||||
*/
|
||||
@Slf4j
|
||||
public class HttpVisitorSecurityChannelHandler extends ChannelInboundHandlerAdapter {
|
||||
private SecurityGroupService securityGroupService = Solon.context().getBean(SecurityGroupService.class);
|
||||
private PortMappingService portMappingService = Solon.context().getBean(PortMappingService.class);
|
||||
private final SecurityGroupService securityGroupService = Solon.context().getBean(SecurityGroupService.class);
|
||||
private final PortMappingService portMappingService = Solon.context().getBean(PortMappingService.class);
|
||||
/**
|
||||
* 域名
|
||||
*/
|
||||
private String domainName;
|
||||
|
||||
public HttpVisitorSecurityChannelHandler(String domainName) {
|
||||
this.domainName = domainName;
|
||||
}
|
||||
@Override
|
||||
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
|
||||
// 未配置域名则不支持通过域名访问
|
||||
if (StrUtil.isBlank(domainName)) {
|
||||
ctx.channel().close();
|
||||
return;
|
||||
}
|
||||
|
||||
ByteBuf buf = (ByteBuf) msg;
|
||||
|
||||
Integer domainId = ctx.channel().attr(Constants.SERVER_PORT).get();
|
||||
if (null == domainId) {
|
||||
Integer serverPort = ctx.channel().attr(Constants.SERVER_PORT).get();
|
||||
if (null == serverPort) {
|
||||
// 获取Host请求头
|
||||
byte[] bytes = new byte[buf.readableBytes()];
|
||||
buf.readBytes(bytes);
|
||||
String httpContent = new String(bytes);
|
||||
String domain = HttpUtil.getHostIgnorePort(httpContent);
|
||||
String host = HttpUtil.getHostIgnorePort(httpContent);
|
||||
|
||||
log.debug("HttpProxy host: {}", domain);
|
||||
if (StringUtils.isBlank(domain)) {
|
||||
log.debug("HttpProxy host: {}", host);
|
||||
if (StringUtils.isBlank(host)) {
|
||||
ctx.channel().close();
|
||||
return;
|
||||
}
|
||||
// 未配置域名解析,不再解析
|
||||
if (!ProxyUtil.domainMapingMap.containsKey(domain)) {
|
||||
|
||||
// 根据Host匹配端口映射
|
||||
if (!host.endsWith(domainName)) {
|
||||
ctx.channel().close();
|
||||
return;
|
||||
}
|
||||
int index = host.lastIndexOf("." + domainName);
|
||||
String subdomain = host.substring(0, index);
|
||||
|
||||
// 根据域名拿到绑定的映射对应的cmdChannel
|
||||
serverPort = ProxyUtil.getServerPortBySubdomain(subdomain);
|
||||
if (null == serverPort) {
|
||||
ctx.channel().close();
|
||||
return;
|
||||
}
|
||||
DomainMapping dm = ProxyUtil.domainMapingMap.get(domain);
|
||||
|
||||
// 判断IP是否在该端口绑定的安全组允许的规则内
|
||||
String ip = IpUtil.getRealRemoteIp(httpContent);
|
||||
if (ip == null) {
|
||||
ip = IpUtil.getRemoteIp(ctx);
|
||||
}
|
||||
if (null==dm.getId() || !securityGroupService.judgeAllow(ip, portMappingService.getSecurityGroupIdByMappingPort(dm.getId()))) {
|
||||
if (!securityGroupService.judgeAllow(ip, portMappingService.getSecurityGroupIdByMappingPort(serverPort))) {
|
||||
// 不在安全组规则放行范围内
|
||||
ctx.channel().close();
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.channel().attr(Constants.REAL_REMOTE_IP).set(ip);
|
||||
ctx.channel().attr(Constants.SERVER_PORT).set(dm.getId());
|
||||
ctx.channel().attr(Constants.LICENSE_ID).set(dm.getLicenseId());
|
||||
ctx.channel().attr(Constants.SERVER_PORT).set(serverPort);
|
||||
}
|
||||
|
||||
// 继续传播
|
||||
|
||||
+1
@@ -31,6 +31,7 @@ public class UdpVisitorSecurityChannelHandler extends ChannelInboundHandlerAdapt
|
||||
if (!securityGroupService.judgeAllow(datagramPacket.sender().getAddress().getHostAddress(), portMappingService.getSecurityGroupIdByMappingPort(sa.getPort()))) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 继续传播
|
||||
ctx.channel().attr(Constants.SERVER_PORT).set(sa.getPort());
|
||||
ctx.fireChannelRead(msg);
|
||||
|
||||
-298
@@ -1,298 +0,0 @@
|
||||
package org.dromara.neutrinoproxy.server.service;
|
||||
|
||||
import cn.hutool.cache.Cache;
|
||||
import cn.hutool.cache.CacheUtil;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.solon.plugins.pagination.Page;
|
||||
import com.google.common.collect.Sets;
|
||||
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.proxy.ProxyConfig;
|
||||
import org.dromara.neutrinoproxy.server.base.rest.SystemContextHolder;
|
||||
import org.dromara.neutrinoproxy.server.constant.EnableStatusEnum;
|
||||
import org.dromara.neutrinoproxy.server.constant.ExceptionConstant;
|
||||
import org.dromara.neutrinoproxy.server.constant.NetworkProtocolEnum;
|
||||
import org.dromara.neutrinoproxy.server.constant.OnlineStatusEnum;
|
||||
import org.dromara.neutrinoproxy.server.controller.req.proxy.PortMappingCreateReq;
|
||||
import org.dromara.neutrinoproxy.server.controller.req.proxy.PortMappingListReq;
|
||||
import org.dromara.neutrinoproxy.server.controller.req.proxy.PortMappingUpdateEnableStatusReq;
|
||||
import org.dromara.neutrinoproxy.server.controller.req.proxy.PortMappingUpdateReq;
|
||||
import org.dromara.neutrinoproxy.server.controller.res.proxy.*;
|
||||
import org.dromara.neutrinoproxy.server.dal.DomainMappingMapper;
|
||||
import org.dromara.neutrinoproxy.server.dal.LicenseMapper;
|
||||
import org.dromara.neutrinoproxy.server.dal.PortPoolMapper;
|
||||
import org.dromara.neutrinoproxy.server.dal.UserMapper;
|
||||
import org.dromara.neutrinoproxy.server.dal.entity.*;
|
||||
import org.dromara.neutrinoproxy.server.proxy.domain.DomainMapping;
|
||||
import org.dromara.neutrinoproxy.server.proxy.domain.ProxyMapping;
|
||||
import org.dromara.neutrinoproxy.server.service.bo.FlowLimitBO;
|
||||
import org.dromara.neutrinoproxy.server.util.ParamCheckUtil;
|
||||
import org.dromara.neutrinoproxy.server.util.PortAvailableUtil;
|
||||
import org.dromara.neutrinoproxy.server.util.ProxyUtil;
|
||||
import org.dromara.neutrinoproxy.server.util.StringUtil;
|
||||
import org.noear.solon.annotation.Component;
|
||||
import org.noear.solon.annotation.Init;
|
||||
import org.noear.solon.annotation.Inject;
|
||||
import org.noear.solon.core.bean.LifecycleBean;
|
||||
import org.noear.solon.core.runtime.NativeDetector;
|
||||
import org.noear.solon.data.annotation.Tran;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
*
|
||||
* 域名解析 service
|
||||
* author xiaojie
|
||||
*/
|
||||
@Component
|
||||
public class DomainMappingService implements LifecycleBean {
|
||||
@Db
|
||||
private DomainMappingMapper domainMappingMapper;
|
||||
@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 LicenseService licenseService;
|
||||
|
||||
|
||||
public PageInfo<DomainMappingDto> page(PageQuery pageQuery, DomainMappingDto req) {
|
||||
if (StringUtils.isNotEmpty(req.getDescription())) {
|
||||
//描述字段为模糊查询,在应用层处理,否则sqlite不支持
|
||||
req.setDescription("%" + req.getDescription() + "%");
|
||||
}
|
||||
|
||||
// 协议名称转换
|
||||
if (StringUtils.isNotBlank(req.getProtocal())) {
|
||||
NetworkProtocolEnum networkProtocolEnum = NetworkProtocolEnum.of(req.getProtocal());
|
||||
req.setProtocal(networkProtocolEnum.getDesc());
|
||||
}
|
||||
|
||||
Page<DomainMappingDO> page = new Page<>(pageQuery.getCurrent(), pageQuery.getSize());
|
||||
List<DomainMappingDO> list = domainMappingMapper.selectDomainMappingByCondition(page, req);
|
||||
List<DomainMappingDto> respList = list.stream().map(DomainMappingDO::toRes).collect(Collectors.toList());
|
||||
if (CollectionUtils.isEmpty(list)) {
|
||||
return PageInfo.of(respList, page.getTotal(), pageQuery.getCurrent(), pageQuery.getSize());
|
||||
}
|
||||
|
||||
Set<Integer> licenseIds = respList.stream().map(DomainMappingDto::getLicenseId).collect(Collectors.toSet());
|
||||
List<LicenseDO> licenseList = licenseMapper.findByIds(licenseIds);
|
||||
if (CollectionUtil.isEmpty(licenseList)) {
|
||||
return PageInfo.of(respList, page.getTotal(), pageQuery.getCurrent(), pageQuery.getSize());
|
||||
}
|
||||
Set<Integer> userIds = licenseList.stream().map(LicenseDO::getUserId).collect(Collectors.toSet());
|
||||
List<UserDO> userList = userMapper.findByIds(userIds);
|
||||
Map<Integer, LicenseDO> licenseMap = licenseList.stream().collect(Collectors.toMap(LicenseDO::getId, Function.identity()));
|
||||
Map<Integer, UserDO> userMap = userList.stream().collect(Collectors.toMap(UserDO::getId, Function.identity()));
|
||||
|
||||
respList.forEach(item -> {
|
||||
LicenseDO license = licenseMap.get(item.getLicenseId());
|
||||
if (null == license) {
|
||||
return;
|
||||
}
|
||||
item.setLicenseName(license.getName());
|
||||
item.setUserId(license.getUserId());
|
||||
UserDO user = userMap.get(license.getUserId());
|
||||
if (null == user) {
|
||||
return;
|
||||
}
|
||||
item.setUserName(user.getName());
|
||||
if (NetworkProtocolEnum.HTTP.getDesc().equals(item.getProtocal())) {
|
||||
item.setProtocal("HTTP(S)");
|
||||
}
|
||||
});
|
||||
//sorted [userId asc] [licenseId asc] [createTime asc]
|
||||
respList = respList.stream()
|
||||
.filter(e -> null != e.getUserId())
|
||||
.sorted(Comparator.comparing(DomainMappingDto::getUserId).thenComparing(DomainMappingDto::getLicenseId).thenComparing(DomainMappingDto::getCreateTime)).collect(Collectors.toList());
|
||||
return PageInfo.of(respList, page.getTotal(), pageQuery.getCurrent(), pageQuery.getSize());
|
||||
}
|
||||
|
||||
@Tran
|
||||
public PortMappingCreateRes modify(DomainMappingDO dmd) {
|
||||
LicenseDO licenseDO = licenseMapper.findById(dmd.getLicenseId());
|
||||
ParamCheckUtil.checkNotNull(licenseDO, ExceptionConstant.LICENSE_NOT_EXIST);
|
||||
if (!SystemContextHolder.isAdmin()) {
|
||||
// 临时处理,如果当前用户不是管理员,则操作userId不能为1
|
||||
ParamCheckUtil.checkExpression(!licenseDO.getUserId().equals(1), ExceptionConstant.NO_PERMISSION_VISIT);
|
||||
}
|
||||
if (null != dmd.getId()) { // 编辑
|
||||
Date now = new Date();
|
||||
dmd.setEnable(EnableStatusEnum.ENABLE.getStatus());
|
||||
dmd.setUpdateTime(now);
|
||||
domainMappingMapper.updateById(dmd);
|
||||
// 更新VisitorChannel
|
||||
DomainMappingDO oldDmd = domainMappingMapper.findById(dmd.getId());
|
||||
ParamCheckUtil.checkNotNull(oldDmd, ExceptionConstant.PORT_MAPPING_NOT_EXIST);
|
||||
ProxyMapping oldProxy = new ProxyMapping(oldDmd.getLicenseId(),oldDmd.getId(),oldDmd.getTargetPath(), NetworkProtocolEnum.HTTP.getDesc());
|
||||
visitorChannelService.updateVisitorChannelByProxyMapping(oldProxy, new ProxyMapping(dmd.getLicenseId(),dmd.getId(),dmd.getTargetPath(), NetworkProtocolEnum.HTTP.getDesc()));
|
||||
} else { // 新增
|
||||
Date now = new Date();
|
||||
dmd.setEnable(EnableStatusEnum.ENABLE.getStatus());
|
||||
dmd.setCreateTime(now);
|
||||
dmd.setUpdateTime(now);
|
||||
domainMappingMapper.insert(dmd);
|
||||
// 新增
|
||||
visitorChannelService.addVisitorChannelByProxyMapping(new ProxyMapping(dmd.getLicenseId(),dmd.getId(),dmd.getTargetPath(), NetworkProtocolEnum.HTTP.getDesc()));
|
||||
}
|
||||
// 更新域名映射
|
||||
ProxyUtil.domainMapingMap.put(dmd.getDomain(), new DomainMapping(dmd.getId(), dmd.getLicenseId(), dmd.getDomain(), dmd.getTargetPath()));
|
||||
|
||||
return new PortMappingCreateRes();
|
||||
}
|
||||
@Tran
|
||||
public PortMappingUpdateEnableStatusRes updateEnableStatus(PortMappingUpdateEnableStatusReq req) {
|
||||
DomainMappingDO domainMappingDO = domainMappingMapper.findById(req.getId());
|
||||
ParamCheckUtil.checkNotNull(domainMappingDO, ExceptionConstant.PORT_MAPPING_NOT_EXIST);
|
||||
|
||||
LicenseDO licenseDO = licenseMapper.findById(domainMappingDO.getLicenseId());
|
||||
ParamCheckUtil.checkNotNull(licenseDO, ExceptionConstant.LICENSE_NOT_EXIST);
|
||||
if (!SystemContextHolder.isAdmin()) {
|
||||
ParamCheckUtil.checkExpression(!licenseDO.getUserId().equals(1), ExceptionConstant.NO_PERMISSION_VISIT);
|
||||
}
|
||||
|
||||
domainMappingMapper.updateEnableStatus(req.getId(), req.getEnable(), new Date());
|
||||
|
||||
// 更新VisitorChannel
|
||||
domainMappingDO.setEnable(req.getEnable());
|
||||
if (EnableStatusEnum.ENABLE == EnableStatusEnum.of(req.getEnable())) {
|
||||
visitorChannelService.addVisitorChannelByProxyMapping(new ProxyMapping(domainMappingDO.getLicenseId(),domainMappingDO.getId(),domainMappingDO.getTargetPath(), NetworkProtocolEnum.HTTP.getDesc()));
|
||||
} else {
|
||||
visitorChannelService.removeVisitorChannelByProxyMapping(new ProxyMapping(domainMappingDO.getLicenseId(),domainMappingDO.getId(),domainMappingDO.getTargetPath(), NetworkProtocolEnum.HTTP.getDesc()));
|
||||
}
|
||||
|
||||
return new PortMappingUpdateEnableStatusRes();
|
||||
}
|
||||
|
||||
public void delete(Integer id) {
|
||||
DomainMappingDO domain = domainMappingMapper.findById(id);
|
||||
ParamCheckUtil.checkNotNull(domain, ExceptionConstant.PORT_MAPPING_NOT_EXIST);
|
||||
|
||||
LicenseDO licenseDO = licenseMapper.findById(domain.getLicenseId());
|
||||
if (null != licenseDO && !SystemContextHolder.isAdmin()) {
|
||||
// 临时处理,如果当前用户不是管理员,则操作userId不能为1
|
||||
ParamCheckUtil.checkExpression(!licenseDO.getUserId().equals(1), ExceptionConstant.NO_PERMISSION_VISIT);
|
||||
}
|
||||
domainMappingMapper.deleteById(id);
|
||||
|
||||
// 更新VisitorChannel
|
||||
visitorChannelService.removeVisitorChannelByProxyMapping(new ProxyMapping(domain.getLicenseId(),domain.getId(),domain.getTargetPath(), NetworkProtocolEnum.HTTP.getDesc()));
|
||||
}
|
||||
|
||||
public void domainBindSecurityGroup(Integer portMappingId, Integer groupId) {
|
||||
DomainMappingDO mappingDO = domainMappingMapper.findById(portMappingId);
|
||||
if (mappingDO == null) {
|
||||
throw new RuntimeException("指定的端口映射不存在");
|
||||
}
|
||||
mappingDO.setSecurityGroupId(groupId);
|
||||
mappingDO.setUpdateTime(new Date());
|
||||
domainMappingMapper.updateById(mappingDO);
|
||||
}
|
||||
|
||||
public void domainUnbindSecurityGroup(Integer portMappingId) {
|
||||
DomainMappingDO mappingDO = domainMappingMapper.findById(portMappingId);
|
||||
if (mappingDO == null) {
|
||||
throw new RuntimeException("指定的端口映射不存在");
|
||||
}
|
||||
mappingDO.setSecurityGroupId(0);
|
||||
mappingDO.setUpdateTime(new Date());
|
||||
domainMappingMapper.updateById(mappingDO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据license查询可用的端口映射列表
|
||||
*
|
||||
* @param licenseId
|
||||
* @return
|
||||
*/
|
||||
public List<DomainMappingDO> findEnableListByLicenseId(Integer licenseId) {
|
||||
return domainMappingMapper.findEnableListByLicenseId(licenseId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 服务端项目停止、启动时,更新在线状态为离线
|
||||
*/
|
||||
@Init
|
||||
public void init() {
|
||||
// aot 阶段,不初始化
|
||||
if (NativeDetector.isAotRuntime()) {
|
||||
return;
|
||||
}
|
||||
List<DomainMappingDO> allMappingDOList = domainMappingMapper.selectList(Wrappers.lambdaQuery(DomainMappingDO.class));
|
||||
if(CollectionUtil.isNotEmpty(allMappingDOList)) {
|
||||
allMappingDOList.forEach(domain -> {
|
||||
ProxyUtil.domainMapingMap.put(domain.getDomain(),
|
||||
new DomainMapping(domain.getId(), domain.getLicenseId(), domain.getDomain(), domain.getTargetPath()));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void start() throws Throwable {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 服务端项目停止、启动时,更新在线状态为离线
|
||||
*/
|
||||
@Override
|
||||
public void stop() throws Throwable {
|
||||
// domainMappingMapper.updateOnlineStatus(OnlineStatusEnum.OFFLINE.getStatus(), new Date());
|
||||
}
|
||||
|
||||
public DomainMappingDto one(Integer id) {
|
||||
DomainMappingDO domainMappingDO = domainMappingMapper.findById(id);
|
||||
if (null == domainMappingDO) {
|
||||
return null;
|
||||
}
|
||||
DomainMappingDto res = (DomainMappingDto)domainMappingDO;
|
||||
|
||||
LicenseDO license = licenseMapper.findById(domainMappingDO.getLicenseId());
|
||||
if (null != license) {
|
||||
res.setLicenseName(license.getName());
|
||||
res.setUserId(license.getUserId());
|
||||
UserDO user = userMapper.findById(license.getUserId());
|
||||
if (null != user) {
|
||||
res.setUserName(user.getName());
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查端口是否被占用
|
||||
* 端口映射编辑时,如果端口号没有变动,则不验证。避免出现端口映射正在使用时,无法更新端口映射其他信息的问题
|
||||
* @param domain
|
||||
* @return
|
||||
*/
|
||||
public boolean exitDomain(String domain, Integer id) {
|
||||
DomainMappingDO domainMappingDO = domainMappingMapper.findByDomain(domain, ObjectUtil.isNotNull(id) ? new HashSet<>(){{add(id);}} : new HashSet());
|
||||
if (null == domainMappingDO) return Boolean.TRUE;
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
}
|
||||
+13
-24
@@ -40,7 +40,6 @@ import org.noear.solon.annotation.Init;
|
||||
import org.noear.solon.annotation.Inject;
|
||||
import org.noear.solon.core.bean.LifecycleBean;
|
||||
import org.noear.solon.core.runtime.NativeDetector;
|
||||
import org.noear.solon.data.annotation.Tran;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
@@ -108,16 +107,17 @@ public class LicenseService implements LifecycleBean {
|
||||
|
||||
private List<LicenseListRes> assembleConvertLicenses(List<LicenseDO> list) {
|
||||
List<LicenseListRes> licenseList = list.stream().map(LicenseDO::toRes).collect(Collectors.toList());
|
||||
// 插入用户名
|
||||
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());
|
||||
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()));
|
||||
}
|
||||
item.setKey(desensitization(item.getUserId(), item.getKey()));
|
||||
}
|
||||
return licenseList;
|
||||
}
|
||||
@@ -203,20 +203,10 @@ public class LicenseService implements LifecycleBean {
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
@Tran
|
||||
public LicenseUpdateEnableStatusRes updateEnableStatus(LicenseUpdateEnableStatusReq req) {
|
||||
// 服务端免通道 直接转发,所以无需建立客户端通道。启用即在线,禁用即离线 20240311 设计取消
|
||||
// if (req.getId() == 1) {
|
||||
// licenseMapper.update(null, new LambdaUpdateWrapper<LicenseDO>()
|
||||
// .eq(LicenseDO::getId, req.getId())
|
||||
// .set(LicenseDO::getEnable, req.getEnable())
|
||||
// .set(LicenseDO::getIsOnline, req.getEnable())
|
||||
// .set(LicenseDO::getUpdateTime, new Date()));
|
||||
// } else {
|
||||
licenseMapper.updateEnableStatus(req.getId(), req.getEnable(), new Date());
|
||||
// 更新VisitorChannel
|
||||
visitorChannelService.updateVisitorChannelByLicenseId(req.getId(), req.getEnable());
|
||||
// }
|
||||
licenseMapper.updateEnableStatus(req.getId(), req.getEnable(), new Date());
|
||||
// 更新VisitorChannel
|
||||
visitorChannelService.updateVisitorChannelByLicenseId(req.getId(), req.getEnable());
|
||||
return new LicenseUpdateEnableStatusRes();
|
||||
}
|
||||
|
||||
@@ -348,7 +338,6 @@ public class LicenseService implements LifecycleBean {
|
||||
.eq(LicenseDO::getEnable, EnableStatusEnum.ENABLE.getStatus())
|
||||
.eq(LicenseDO::getUserId, SystemContextHolder.getUserId())
|
||||
);
|
||||
if (CollectionUtil.isEmpty(list)) return null;
|
||||
List<LicenseListRes> licenseList = assembleConvertLicenses(list);
|
||||
return licenseList;
|
||||
}
|
||||
|
||||
+44
-6
@@ -39,7 +39,6 @@ import org.dromara.neutrinoproxy.server.dal.entity.LicenseDO;
|
||||
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.domain.ProxyMapping;
|
||||
import org.dromara.neutrinoproxy.server.service.bo.FlowLimitBO;
|
||||
import org.dromara.neutrinoproxy.server.util.ParamCheckUtil;
|
||||
import org.dromara.neutrinoproxy.server.util.ProxyUtil;
|
||||
@@ -131,6 +130,9 @@ public class PortMappingService implements LifecycleBean {
|
||||
return;
|
||||
}
|
||||
item.setUserName(user.getName());
|
||||
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)");
|
||||
}
|
||||
@@ -152,11 +154,13 @@ public class PortMappingService implements LifecycleBean {
|
||||
PortPoolDO portPoolDO = portPoolMapper.findByPort(req.getServerPort());
|
||||
ParamCheckUtil.checkNotNull(portPoolDO, ExceptionConstant.PORT_NOT_EXIST);
|
||||
ParamCheckUtil.checkExpression(null == portMappingMapper.findByPort(req.getServerPort(), null), ExceptionConstant.PORT_CANNOT_REPEAT_MAPPING, req.getServerPort());
|
||||
ParamCheckUtil.checkExpression(!portMappingMapper.checkRepeatBySubdomain(req.getSubdomain(), null), ExceptionConstant.PORT_MAPPING_SUBDONAME_CONNOT_REPEAT);
|
||||
|
||||
Date now = new Date();
|
||||
PortMappingDO portMappingDO = new PortMappingDO();
|
||||
portMappingDO.setLicenseId(req.getLicenseId());
|
||||
portMappingDO.setProtocal(req.getProtocal());
|
||||
portMappingDO.setSubdomain(req.getSubdomain());
|
||||
portMappingDO.setServerPort(req.getServerPort());
|
||||
portMappingDO.setClientIp(req.getClientIp());
|
||||
portMappingDO.setClientPort(req.getClientPort());
|
||||
@@ -171,7 +175,11 @@ public class PortMappingService implements LifecycleBean {
|
||||
portMappingDO.setUpdateTime(now);
|
||||
portMappingMapper.insert(portMappingDO);
|
||||
// 更新VisitorChannel
|
||||
visitorChannelService.addVisitorChannelByProxyMapping(ProxyMapping.build(portMappingDO));
|
||||
visitorChannelService.addVisitorChannelByPortMapping(portMappingDO);
|
||||
// 更新域名映射
|
||||
if (NetworkProtocolEnum.isHttp(portMappingDO.getProtocal()) && StrUtil.isNotBlank(proxyConfig.getServer().getTcp().getDomainName()) && StrUtil.isNotBlank(portMappingDO.getSubdomain())) {
|
||||
ProxyUtil.setSubdomainToServerPort(portMappingDO.getSubdomain(), portMappingDO.getServerPort());
|
||||
}
|
||||
|
||||
updateMappingPortToSecurityGroupMap(portMappingDO.getServerPort(), req.getSecurityGroupId());
|
||||
|
||||
@@ -195,6 +203,7 @@ public class PortMappingService implements LifecycleBean {
|
||||
PortPoolDO portPoolDO = portPoolMapper.findByPort(req.getServerPort());
|
||||
ParamCheckUtil.checkNotNull(portPoolDO, ExceptionConstant.PORT_NOT_EXIST);
|
||||
ParamCheckUtil.checkExpression(null == portMappingMapper.findByPort(req.getServerPort(), Sets.newHashSet(req.getId())), ExceptionConstant.PORT_CANNOT_REPEAT_MAPPING, req.getServerPort());
|
||||
ParamCheckUtil.checkExpression(!portMappingMapper.checkRepeatBySubdomain(req.getSubdomain(), Sets.newHashSet(req.getId())), ExceptionConstant.PORT_MAPPING_SUBDONAME_CONNOT_REPEAT);
|
||||
|
||||
// 查询原端口映射
|
||||
PortMappingDO oldPortMappingDO = portMappingMapper.findById(req.getId());
|
||||
@@ -204,6 +213,7 @@ public class PortMappingService implements LifecycleBean {
|
||||
portMappingMapper.update(null, new LambdaUpdateWrapper<PortMappingDO>()
|
||||
.eq(PortMappingDO::getId, req.getId())
|
||||
.set(PortMappingDO::getProtocal, req.getProtocal())
|
||||
.set(PortMappingDO::getSubdomain, req.getSubdomain())
|
||||
.set(PortMappingDO::getServerPort, req.getServerPort())
|
||||
.set(PortMappingDO::getClientIp, req.getClientIp())
|
||||
.set(PortMappingDO::getClientPort, req.getClientPort())
|
||||
@@ -218,7 +228,15 @@ public class PortMappingService implements LifecycleBean {
|
||||
|
||||
// 更新VisitorChannel
|
||||
PortMappingDO portMappingDO = portMappingMapper.findById(req.getId());
|
||||
visitorChannelService.updateVisitorChannelByProxyMapping(ProxyMapping.build(oldPortMappingDO), ProxyMapping.build(portMappingDO));
|
||||
visitorChannelService.updateVisitorChannelByPortMapping(oldPortMappingDO, portMappingDO);
|
||||
// 删除老的域名映射
|
||||
if (NetworkProtocolEnum.isHttp(oldPortMappingDO.getProtocal()) && StrUtil.isNotBlank(oldPortMappingDO.getSubdomain())) {
|
||||
ProxyUtil.removeSubdomainToServerPort(oldPortMappingDO.getSubdomain());
|
||||
}
|
||||
// 更新域名映射
|
||||
if (NetworkProtocolEnum.isHttp(portMappingDO.getProtocal()) && StrUtil.isNotBlank(proxyConfig.getServer().getTcp().getDomainName()) && StrUtil.isNotBlank(portMappingDO.getSubdomain())) {
|
||||
ProxyUtil.setSubdomainToServerPort(portMappingDO.getSubdomain(), portMappingDO.getServerPort());
|
||||
}
|
||||
|
||||
updateMappingPortToSecurityGroupMap(portMappingDO.getServerPort(), req.getSecurityGroupId());
|
||||
|
||||
@@ -276,9 +294,9 @@ public class PortMappingService implements LifecycleBean {
|
||||
// 更新VisitorChannel
|
||||
portMappingDO.setEnable(req.getEnable());
|
||||
if (EnableStatusEnum.ENABLE == EnableStatusEnum.of(req.getEnable())) {
|
||||
visitorChannelService.addVisitorChannelByProxyMapping(ProxyMapping.build(portMappingDO));
|
||||
visitorChannelService.addVisitorChannelByPortMapping(portMappingDO);
|
||||
} else {
|
||||
visitorChannelService.removeVisitorChannelByProxyMapping(ProxyMapping.build(portMappingDO));
|
||||
visitorChannelService.removeVisitorChannelByPortMapping(portMappingDO);
|
||||
}
|
||||
|
||||
return new PortMappingUpdateEnableStatusRes();
|
||||
@@ -297,8 +315,11 @@ public class PortMappingService implements LifecycleBean {
|
||||
portMappingMapper.deleteById(id);
|
||||
|
||||
// 更新VisitorChannel
|
||||
visitorChannelService.removeVisitorChannelByProxyMapping(ProxyMapping.build(portMappingDO));
|
||||
visitorChannelService.removeVisitorChannelByPortMapping(portMappingDO);
|
||||
// 更新域名映射
|
||||
if (NetworkProtocolEnum.isHttp(portMappingDO.getProtocal()) && StrUtil.isNotBlank(portMappingDO.getSubdomain())) {
|
||||
ProxyUtil.removeSubdomainToServerPort(portMappingDO.getSubdomain());
|
||||
}
|
||||
|
||||
updateMappingPortToSecurityGroupMap(portMappingDO.getServerPort(), null);
|
||||
|
||||
@@ -371,6 +392,23 @@ public class PortMappingService implements LifecycleBean {
|
||||
refreshFlowLimitCache(item.getId(), item.getUpLimitRate(), item.getDownLimitRate());
|
||||
});
|
||||
|
||||
// 未配置域名,则不需要处理域名映射逻辑
|
||||
if (StrUtil.isBlank(proxyConfig.getServer().getTcp().getDomainName())) {
|
||||
return;
|
||||
}
|
||||
List<PortMappingDO> portMappingDOList = allMappingDOList.stream()
|
||||
.filter(item -> NetworkProtocolEnum.HTTP.getDesc().equals(item.getProtocal()) && item.getSubdomain() != null)
|
||||
.collect(Collectors.toList());
|
||||
if (CollectionUtil.isEmpty(portMappingDOList)) {
|
||||
return;
|
||||
}
|
||||
portMappingDOList.forEach(item -> {
|
||||
if (StrUtil.isBlank(item.getSubdomain())) {
|
||||
return;
|
||||
}
|
||||
ProxyUtil.setSubdomainToServerPort(item.getSubdomain(), item.getServerPort());
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
-1
@@ -130,7 +130,6 @@ public class PortPoolService {
|
||||
log.warn("bulk add port err:{}",e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}else{
|
||||
throw ServiceException.create(PORT_RANGE_FAIL);
|
||||
}
|
||||
|
||||
+57
-57
@@ -59,18 +59,17 @@ public class VisitorChannelService {
|
||||
private PortPoolMapper portPoolMapper;
|
||||
|
||||
/**
|
||||
* 初始化 - 域名id/端口号,客户端通道绑定初始化
|
||||
* 初始化
|
||||
* @param licenseId
|
||||
*/
|
||||
public void initVisitorChannel(Integer licenseId, Channel cmdChannel) {
|
||||
// List<PortMappingDO> portMappingList = portMappingMapper.findEnableListByLicenseId(licenseId);
|
||||
List<ProxyMapping> proxyMappingList = licenseMapper.findEnableProxyMappingListByLicenseId(licenseId);
|
||||
List<PortMappingDO> portMappingList = portMappingMapper.findEnableListByLicenseId(licenseId);
|
||||
// 没有端口映射仍然保持连接
|
||||
ProxyUtil.initProxyInfo(licenseId, proxyMappingList); //ProxyMapping.buildList(portMappingList));
|
||||
ProxyUtil.initProxyInfo(licenseId, ProxyMapping.buildList(portMappingList));
|
||||
|
||||
ProxyUtil.addCmdChannel(licenseId, cmdChannel, proxyMappingList.stream().map(ProxyMapping::getServerPort).collect(Collectors.toSet()));
|
||||
ProxyUtil.addCmdChannel(licenseId, cmdChannel, portMappingList.stream().map(PortMappingDO::getServerPort).collect(Collectors.toSet()));
|
||||
|
||||
startUserPortServer(ProxyUtil.getAttachInfo(cmdChannel), proxyMappingList); // portMappingList
|
||||
startUserPortServer(ProxyUtil.getAttachInfo(cmdChannel), portMappingList);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -90,9 +89,9 @@ public class VisitorChannelService {
|
||||
EnableStatusEnum enableStatusEnum = EnableStatusEnum.of(enable);
|
||||
for (PortMappingDO portMappingDO : portMappingDOList) {
|
||||
if (EnableStatusEnum.DISABLE == enableStatusEnum) {
|
||||
removeVisitorChannelByProxyMapping(ProxyMapping.build(portMappingDO));
|
||||
removeVisitorChannelByPortMapping(portMappingDO);
|
||||
} else if (EnableStatusEnum.ENABLE == EnableStatusEnum.of(portMappingDO.getEnable())) {
|
||||
addVisitorChannelByProxyMapping(ProxyMapping.build(portMappingDO));
|
||||
addVisitorChannelByPortMapping(portMappingDO);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -131,82 +130,82 @@ public class VisitorChannelService {
|
||||
return;
|
||||
}
|
||||
EnableStatusEnum enableStatusEnum = EnableStatusEnum.of(enable);
|
||||
if (EnableStatusEnum.DISABLE == enableStatusEnum) { // 禁用删除,关闭所有链接及配置
|
||||
List<ProxyMapping> allProxyMappingList = licenseMapper.findAllProxyMappingListByLicenseId(licenseId);
|
||||
for (ProxyMapping proxy : allProxyMappingList) {
|
||||
removeVisitorChannelByProxyMapping(proxy);
|
||||
}
|
||||
} else { // if (EnableStatusEnum.ENABLE == enableStatusEnum) 如果实启用,则开启所有
|
||||
List<ProxyMapping> enableProxyMappingList = licenseMapper.findEnableProxyMappingListByLicenseId(licenseId);
|
||||
for (ProxyMapping eproxy : enableProxyMappingList) {
|
||||
addVisitorChannelByProxyMapping(eproxy);
|
||||
List<PortMappingDO> portMappingDOList = portMappingMapper.findListByLicenseId(licenseId);
|
||||
if (!CollectionUtil.isEmpty(portMappingDOList)) {
|
||||
for (PortMappingDO portMappingDO : portMappingDOList) {
|
||||
if (EnableStatusEnum.DISABLE == enableStatusEnum) {
|
||||
removeVisitorChannelByPortMapping(portMappingDO);
|
||||
} else if (EnableStatusEnum.ENABLE == EnableStatusEnum.of(portMappingDO.getEnable())) {
|
||||
addVisitorChannelByPortMapping(portMappingDO);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新
|
||||
* 触发时机:修改端口映射
|
||||
* @param oldProxyMapping
|
||||
* @param newProxyMapping
|
||||
* @param oldPortMappingDO
|
||||
* @param newPortMappingDO
|
||||
*/
|
||||
public void updateVisitorChannelByProxyMapping(ProxyMapping oldProxyMapping, ProxyMapping newProxyMapping) {
|
||||
if (null == oldProxyMapping || null == newProxyMapping) {
|
||||
public void updateVisitorChannelByPortMapping(PortMappingDO oldPortMappingDO, PortMappingDO newPortMappingDO) {
|
||||
if (null == oldPortMappingDO || null == newPortMappingDO) {
|
||||
return;
|
||||
}
|
||||
removeVisitorChannelByProxyMapping(oldProxyMapping);
|
||||
addVisitorChannelByProxyMapping(newProxyMapping);
|
||||
removeVisitorChannelByPortMapping(oldPortMappingDO);
|
||||
addVisitorChannelByPortMapping(newPortMappingDO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增VisitorChannel
|
||||
* 触发时机:新增端口映射、启用端口映射
|
||||
* @param proxyMapping
|
||||
* @param portMappingDO
|
||||
*/
|
||||
public void addVisitorChannelByProxyMapping(ProxyMapping proxyMapping) {
|
||||
if (null == proxyMapping) {
|
||||
public void addVisitorChannelByPortMapping(PortMappingDO portMappingDO) {
|
||||
if (null == portMappingDO) {
|
||||
return;
|
||||
}
|
||||
Channel cmdChannel = ProxyUtil.getCmdChannelByLicenseId(proxyMapping.getLicenseId());
|
||||
Channel cmdChannel = ProxyUtil.getCmdChannelByLicenseId(portMappingDO.getLicenseId());
|
||||
if (null == cmdChannel) {
|
||||
// 如果不存在有效的cmdChannel,则无需更新VisitorChannel
|
||||
return;
|
||||
}
|
||||
// 判断端口映射是否启用
|
||||
// if (EnableStatusEnum.DISABLE != EnableStatusEnum.of(portMappingDO.getEnable())) {
|
||||
LicenseDO licenseDO = licenseMapper.findById(proxyMapping.getLicenseId());
|
||||
if (EnableStatusEnum.DISABLE != EnableStatusEnum.of(portMappingDO.getEnable())) {
|
||||
LicenseDO licenseDO = licenseMapper.findById(portMappingDO.getLicenseId());
|
||||
// 判断license是否启用
|
||||
if (null != licenseDO && EnableStatusEnum.ENABLE == EnableStatusEnum.of(licenseDO.getEnable())) {
|
||||
UserDO userDO = userMapper.findById(licenseDO.getUserId());
|
||||
// 判断用户是否启用
|
||||
if (null != userDO && EnableStatusEnum.ENABLE == EnableStatusEnum.of(userDO.getEnable())) {
|
||||
PortPoolDO portPoolDO = portPoolMapper.findByPort(proxyMapping.getServerPort());
|
||||
// 端口池大于65535 为域名解析,小于65535为端口映射,端口映射要判断端口池是否启用
|
||||
if (proxyMapping.getServerPort() > 65535 || (null != portPoolDO && EnableStatusEnum.ENABLE == EnableStatusEnum.of(portPoolDO.getEnable()))) {
|
||||
PortPoolDO portPoolDO = portPoolMapper.findByPort(portMappingDO.getServerPort());
|
||||
// 判断端口池是否启用
|
||||
if (null != portPoolDO && EnableStatusEnum.ENABLE == EnableStatusEnum.of(portPoolDO.getEnable())) {
|
||||
// 未删除且未禁用,则开启代理
|
||||
ProxyUtil.addProxyInfo(proxyMapping.getLicenseId(), proxyMapping);
|
||||
ProxyUtil.addCmdChannel(proxyMapping.getLicenseId(), cmdChannel, Sets.newHashSet(proxyMapping.getServerPort()));
|
||||
startUserPortServer(ProxyUtil.getAttachInfo(cmdChannel), Lists.newArrayList(proxyMapping));
|
||||
ProxyUtil.addProxyInfo(portMappingDO.getLicenseId(), ProxyMapping.build(portMappingDO));
|
||||
ProxyUtil.addCmdChannel(portMappingDO.getLicenseId(), cmdChannel, Sets.newHashSet(portMappingDO.getServerPort()));
|
||||
startUserPortServer(ProxyUtil.getAttachInfo(cmdChannel), Lists.newArrayList(portMappingDO));
|
||||
}
|
||||
}
|
||||
}
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除VisitorChannel
|
||||
* 触发时机:删除端口映射、禁用端口映射
|
||||
* @param proxyMapping
|
||||
* @param portMappingDO
|
||||
*/
|
||||
public void removeVisitorChannelByProxyMapping(ProxyMapping proxyMapping) {
|
||||
if (null == proxyMapping) {
|
||||
public void removeVisitorChannelByPortMapping(PortMappingDO portMappingDO) {
|
||||
if (null == portMappingDO) {
|
||||
return;
|
||||
}
|
||||
Channel cmdChannel = ProxyUtil.getCmdChannelByLicenseId(proxyMapping.getLicenseId());
|
||||
Channel cmdChannel = ProxyUtil.getCmdChannelByLicenseId(portMappingDO.getLicenseId());
|
||||
if (null == cmdChannel) {
|
||||
// 如果不存在有效的cmdChannel,则无需更新VisitorChannel
|
||||
return;
|
||||
}
|
||||
Channel visitorChannel = ProxyUtil.getVisitorChannelByServerPort(proxyMapping.getServerPort());
|
||||
Channel visitorChannel = ProxyUtil.getVisitorChannelByServerPort(portMappingDO.getServerPort());
|
||||
if (null != visitorChannel) {
|
||||
Channel proxyChannel = visitorChannel.attr(Constants.NEXT_CHANNEL).get();
|
||||
if (null != proxyChannel) {
|
||||
@@ -215,28 +214,29 @@ public class VisitorChannelService {
|
||||
// TODO 此处如果时UDP的visitorChannel,则不能close,后续重构考虑
|
||||
// visitorChannel.close();
|
||||
}
|
||||
ProxyUtil.removeProxyInfo(proxyMapping.getServerPort());
|
||||
ProxyUtil.removeProxyInfo(portMappingDO.getServerPort());
|
||||
}
|
||||
|
||||
private void startUserPortServer(CmdChannelAttachInfo cmdChannelAttachInfo, List<ProxyMapping> proxyMappingList) {
|
||||
if (CollectionUtil.isEmpty(proxyMappingList)) {
|
||||
private void startUserPortServer(CmdChannelAttachInfo cmdChannelAttachInfo, List<PortMappingDO> portMappingList) {
|
||||
if (CollectionUtil.isEmpty(portMappingList)) {
|
||||
return;
|
||||
}
|
||||
for (ProxyMapping proxyMapping : proxyMappingList) {
|
||||
// if (EnableStatusEnum.DISABLE.getStatus().equals(proxyMapping.getEnable())) {
|
||||
// // 端口映射被禁用了,忽略 TODO 映射没被禁用,但端口被禁用了也需要处理 修改方案 20240306查询时就处理了【端口禁用】和【端口映射禁用】的情况,待验证
|
||||
// continue;
|
||||
// }
|
||||
try {
|
||||
proxyMutualService.bindServerPort(cmdChannelAttachInfo, proxyMapping.getServerPort());
|
||||
|
||||
NetworkProtocolEnum networkProtocolEnum = NetworkProtocolEnum.of(proxyMapping.getProtocal());
|
||||
for (PortMappingDO portMapping : portMappingList) {
|
||||
if (EnableStatusEnum.DISABLE.getStatus().equals(portMapping.getEnable())) {
|
||||
// 端口映射被禁用了,忽略 TODO 映射没被禁用,但端口被禁用了也需要处理
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
proxyMutualService.bindServerPort(cmdChannelAttachInfo, portMapping.getServerPort());
|
||||
|
||||
NetworkProtocolEnum networkProtocolEnum = NetworkProtocolEnum.of(portMapping.getProtocal());
|
||||
if (networkProtocolEnum == NetworkProtocolEnum.UDP) {
|
||||
udpServerBootstrap.bind(proxyMapping.getServerPort()).get();
|
||||
log.info("bind UDP user port: {}", proxyMapping.getServerPort());
|
||||
} else if (proxyMapping.getServerPort() <= 65535){// 大于65535 的端口号是域名解析无需绑定服务端端口号
|
||||
tcpServerBootstrap.bind(proxyMapping.getServerPort()).get();
|
||||
log.info("bind TCP ServerPort: {}", proxyMapping.getServerPort());
|
||||
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表示该端口已经绑定过
|
||||
|
||||
+34
-14
@@ -5,13 +5,13 @@ 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.base.proxy.ProxyConfig;
|
||||
import org.dromara.neutrinoproxy.server.constant.NetworkProtocolEnum;
|
||||
import org.dromara.neutrinoproxy.server.proxy.domain.*;
|
||||
import org.dromara.neutrinoproxy.server.proxy.domain.CmdChannelAttachInfo;
|
||||
import org.dromara.neutrinoproxy.server.proxy.domain.ProxyAttachment;
|
||||
import org.dromara.neutrinoproxy.server.proxy.domain.ProxyMapping;
|
||||
import org.dromara.neutrinoproxy.server.proxy.domain.VisitorChannelAttachInfo;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.util.AttributeKey;
|
||||
import org.dromara.neutrinoproxy.server.service.DomainMappingService;
|
||||
import org.noear.solon.annotation.Inject;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.*;
|
||||
@@ -60,19 +60,15 @@ public class ProxyUtil {
|
||||
* 代理 - connect附加映射
|
||||
*/
|
||||
private static Map<String, ProxyAttachment> proxyConnectAttachmentMap = new HashMap<>();
|
||||
|
||||
|
||||
/**
|
||||
* 域名 解析 映射
|
||||
*/
|
||||
public static final Map<String, DomainMapping> domainMapingMap = new HashMap<>();
|
||||
|
||||
/**
|
||||
* 子域名 - 服务端端口映射
|
||||
*/
|
||||
private static Map<String, Integer> subdomainToServerPort = new HashMap<>();
|
||||
/**
|
||||
* licenseId - 客户端Id映射
|
||||
*/
|
||||
private static Map<Integer, String> licenseIdToClientIdMap = new HashMap<>();
|
||||
@Inject
|
||||
private DomainMappingService domainMappingService;
|
||||
|
||||
/**
|
||||
* 初始化代理信息
|
||||
* @param licenseId licenseId
|
||||
@@ -83,7 +79,6 @@ public class ProxyUtil {
|
||||
addProxyInfo(licenseId, proxyMappingList);
|
||||
}
|
||||
|
||||
|
||||
public static void addProxyInfo(Integer licenseId, List<ProxyMapping> proxyMappingList) {
|
||||
if (!CollectionUtil.isEmpty(proxyMappingList)) {
|
||||
for (ProxyMapping proxyMapping : proxyMappingList) {
|
||||
@@ -343,6 +338,31 @@ public class ProxyUtil {
|
||||
proxyConnectAttachmentMap.remove(visitorId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置子域名到服务端端口的映射
|
||||
* @param subdomain
|
||||
* @param serverPort
|
||||
*/
|
||||
public static void setSubdomainToServerPort(String subdomain, Integer serverPort) {
|
||||
subdomainToServerPort.put(subdomain, serverPort);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除子域名到服务端端口的映射
|
||||
* @param subdomain
|
||||
*/
|
||||
public static void removeSubdomainToServerPort(String subdomain) {
|
||||
subdomainToServerPort.remove(subdomain);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据子域名获取外网端口
|
||||
* @param subdomain
|
||||
* @return
|
||||
*/
|
||||
public static Integer getServerPortBySubdomain(String subdomain) {
|
||||
return subdomainToServerPort.get(subdomain);
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭http响应channel
|
||||
|
||||
@@ -55,14 +55,14 @@ neutrino:
|
||||
boss-thread-count: 5
|
||||
work-thread-count: 20
|
||||
# http代理端口,默认80
|
||||
http-proxy-port: ${HTTP_PR0OXY_PORT:80}
|
||||
http-proxy-port: ${HTTP_PROXY_PORT:80}
|
||||
# https代理端口,默认443 (需要配置域名、证书)
|
||||
https-proxy-port: ${HTTPS_PROXY_PORT:443}
|
||||
# 如果不配置,则不支持域名映射
|
||||
domain-name: ${DOMAIN_NAME:server.com}
|
||||
domain-name: ${DOMAIN_NAME:}
|
||||
# https证书配置
|
||||
key-store-password: ${HTTPS_STORE_PASS:123456}
|
||||
jks-path: ${HTTPS_JKS_PATH:classpath:/test.jks}
|
||||
key-store-password: ${HTTPS_STORE_PASS:}
|
||||
jks-path: ${HTTPS_JKS_PATH:}
|
||||
# 是否开启代理服务报文日志(日志级别为debug时开启才有效)
|
||||
transfer-log-enable: ${SERVER_LOG:false}
|
||||
udp:
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="org.dromara.neutrinoproxy.server.dal.DomainMappingMapper">
|
||||
|
||||
<select id="selectDomainMappingByCondition" resultType="org.dromara.neutrinoproxy.server.dal.entity.DomainMappingDO">
|
||||
SELECT pm.*,l.is_online as isOnline
|
||||
FROM domain_mapping pm
|
||||
LEFT JOIN license l ON pm.license_id = l.`id`
|
||||
<where>
|
||||
<if test="req.userId != null">
|
||||
AND l.user_id = #{req.userId}
|
||||
</if>
|
||||
<if test="req.licenseId != null">
|
||||
AND pm.license_id = #{req.licenseId}
|
||||
</if>
|
||||
<if test="req.domain != null">
|
||||
AND pm.domain = #{req.domain}
|
||||
</if>
|
||||
<if test="req.isOnline != null">
|
||||
AND l.is_online = #{req.isOnline}
|
||||
</if>
|
||||
<if test="req.enable != null">
|
||||
AND pm.enable = #{req.enable}
|
||||
</if>
|
||||
<if test="req.protocal != null and req.protocal != ''">
|
||||
AND pm.protocal = #{req.protocal}
|
||||
</if>
|
||||
<if test="req.description != null and req.description != '' ">
|
||||
AND pm.description like #{req.description}
|
||||
</if>
|
||||
</where>
|
||||
order by pm.id asc
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -1,28 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="org.dromara.neutrinoproxy.server.dal.LicenseMapper">
|
||||
|
||||
<select id="findEnableProxyMappingListByLicenseId" resultType="org.dromara.neutrinoproxy.server.proxy.domain.ProxyMapping">
|
||||
SELECT pm.license_id as licenseId, pm.server_port as serverPort,CONCAT(pm.client_ip, ':', pm.client_port) as lanInfo, pm.protocal as protocal
|
||||
FROM port_mapping pm
|
||||
LEFT JOIN port_pool pp on pm.server_port = pp.port
|
||||
WHERE pm.enable = 1 AND pm.is_online = 1 AND pp.enable = 1 AND pm.license_id = #{licenseId}
|
||||
UNION ALL
|
||||
SELECT dm.license_id as licenseId, dm.id as serverPort,dm.target_path as lanInfo, 'HTTP' as protocal
|
||||
FROM domain_mapping dm
|
||||
LEFT JOIN license l on dm.license_id = l.`id`
|
||||
WHERE dm.enable = 1 AND l.is_online = 1 AND dm.license_id = #{licenseId}
|
||||
</select>
|
||||
|
||||
<select id="findAllProxyMappingListByLicenseId" resultType="org.dromara.neutrinoproxy.server.proxy.domain.ProxyMapping">
|
||||
SELECT pm.license_id as licenseId, pm.server_port as serverPort,CONCAT(pm.client_ip, ':', pm.client_port) as lanInfo, pm.protocal as protocal
|
||||
FROM port_mapping pm
|
||||
LEFT JOIN port_pool pp on pm.server_port = pp.port
|
||||
WHERE pm.license_id = #{licenseId}
|
||||
UNION ALL
|
||||
SELECT dm.id as serverPort,dm.target_path as lanInfo, 'HTTP' as protocal
|
||||
FROM domain_mapping dm
|
||||
LEFT JOIN license l on dm.license_id = l.`id`
|
||||
WHERE dm.license_id = #{licenseId}
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -48,7 +48,7 @@
|
||||
LEFT JOIN `user` u ON l.user_id = u.id
|
||||
LEFT JOIN (SELECT license_id,sum(write_bytes) write_bytes,sum(read_bytes) read_bytes from flow_report_month GROUP BY license_id) frm ON l.id = frm.license_id
|
||||
LEFT JOIN (SELECT license_id,sum(write_bytes) write_bytes,sum(read_bytes) read_bytes from flow_report_day
|
||||
WHERE date >= #{curMonthBeginDate} AND date <= #{curDayBeginDate}
|
||||
WHERE date >= #{curMonthBeginDate} AND #{curDayBeginDate}
|
||||
GROUP BY license_id) frd ON l.id = frd.license_id
|
||||
LEFT JOIN (SELECT license_id,sum(write_bytes) write_bytes,sum(read_bytes) read_bytes from flow_report_minute
|
||||
WHERE date >= #{curDayBeginDate} AND date <= #{curDate}
|
||||
|
||||
@@ -97,6 +97,7 @@ CREATE TABLE IF NOT EXISTS `port_mapping` (
|
||||
`id` INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||
`license_id` INTEGER(20) NOT NULL,
|
||||
`protocal` VARCHAR(10) NOT NULL DEFAULT 'TCP',
|
||||
`subdomain` VARCHAR(50) DEFAULT NULL,
|
||||
`server_port` INTEGER NOT NULL,
|
||||
`client_ip` VARCHAR(20) NOT NULL,
|
||||
`client_port` INTEGER NOT NULL,
|
||||
@@ -228,21 +229,3 @@ CREATE INDEX IF NOT EXISTS I_flow_report_month_create_time ON flow_report_month(
|
||||
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`);
|
||||
|
||||
# 域名 映射表 AUTO_INCREMENT 设置65550 避开端口号0-65535,减少域名解析代码修改
|
||||
CREATE TABLE IF NOT EXISTS `domain_mapping` (
|
||||
`id` INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||
`license_id` INTEGER(20) NOT NULL,
|
||||
`protocal` VARCHAR(10) NOT NULL DEFAULT 'HTTP',
|
||||
`domain` VARCHAR(50) DEFAULT NULL,
|
||||
`target_path` VARCHAR(50) NOT NULL,
|
||||
`up_limit_rate` VARCHAR(20) DEFAULT NULL,
|
||||
`down_limit_rate` VARCHAR(20) DEFAULT NULL,
|
||||
`description` VARCHAR(100) DEFAULT NULL,
|
||||
`request_header` INTEGER(20) NOT NULL DEFAULT 0,
|
||||
`enable` INTEGER(2) NOT NULL,
|
||||
`security_group_id` INTEGER(20) NOT NULL DEFAULT 0,
|
||||
`create_time` TIMESTAMP NOT NULL,
|
||||
`update_time` TIMESTAMP NOT NULL
|
||||
) AUTO_INCREMENT = 65550;
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS I_domain_mapping_domain ON domain_mapping (`domain` ASC);
|
||||
@@ -1,3 +1,3 @@
|
||||
#license
|
||||
INSERT INTO license(`id`, `name`, `key`, `user_id`, `is_online`, `enable`, `create_time`, `update_time`) VALUES
|
||||
(1, '测试客户端', 'b0a907332b474b25897c4dcb31fc7eb6', 1, 1, 1, now(), now());
|
||||
(1, '我的mac', 'b0a907332b474b25897c4dcb31fc7eb6', 1, 2, 1, now(), now());
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#port_mapping
|
||||
INSERT INTO port_mapping(`id`, `license_id`, `server_port`, `protocal`, `client_ip`, `client_port`, `is_online`, `enable`,`description`,`create_time`, `update_time`) VALUES
|
||||
(1, 1, 9101, 'HTTP', '127.0.0.1', 8080, 2, 1,'test1', now(), now());
|
||||
INSERT INTO port_mapping(`id`, `license_id`, `server_port`, `protocal`, `client_ip`, `client_port`, `is_online`, `enable`,`description`, `create_time`, `update_time`) VALUES
|
||||
(2, 1, 9102, 'TCP', '127.0.0.1', 3306, 2, 1,'test2', now(), now());
|
||||
INSERT INTO port_mapping(`id`, `license_id`, `server_port`, `protocal`, `client_ip`, `client_port`, `is_online`, `enable`,`description`, `create_time`, `update_time`) VALUES
|
||||
(3, 1, 9103, 'HTTP', '127.0.0.1', 8081, 2, 1,'test3', now(), now());
|
||||
INSERT INTO port_mapping(`id`, `license_id`, `server_port`, `protocal`, `subdomain`,`client_ip`, `client_port`, `is_online`, `enable`,`description`,`create_time`, `update_time`) VALUES
|
||||
(1, 1, 9101, 'HTTP', 'test1', '127.0.0.1', 8080, 2, 1,'test1', now(), now());
|
||||
INSERT INTO port_mapping(`id`, `license_id`, `server_port`, `protocal`, `subdomain`, `client_ip`, `client_port`, `is_online`, `enable`,`description`, `create_time`, `update_time`) VALUES
|
||||
(2, 1, 9102, 'TCP', '', '127.0.0.1', 3306, 2, 1,'test2', now(), now());
|
||||
INSERT INTO port_mapping(`id`, `license_id`, `server_port`, `protocal`, `subdomain`, `client_ip`, `client_port`, `is_online`, `enable`,`description`, `create_time`, `update_time`) VALUES
|
||||
(3, 1, 9103, 'HTTP', 'test2', '127.0.0.1', 8081, 2, 1,'test3', now(), now());
|
||||
@@ -9,3 +9,33 @@ INSERT INTO port_pool(`id`, `group_id`, `port`, `enable`, `create_time`, `update
|
||||
(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,12 @@
|
||||
ALTER TABLE port_pool ADD group_id INTEGER NOT NULL DEFAULT 1;
|
||||
|
||||
#端口分组
|
||||
CREATE TABLE IF NOT EXISTS `port_group` (
|
||||
`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
`name` VARCHAR(255) NOT NULL,
|
||||
`possessor_type` INTEGER NOT NULL DEFAULT '0',
|
||||
`possessor_id` INTEGER NOT NULL DEFAULT '-1',
|
||||
`enable` INTEGER NOT NULL,
|
||||
`create_time` datetime(3) NOT NULL,
|
||||
`update_time` datetime(3) NOT NULL
|
||||
);
|
||||
@@ -0,0 +1,3 @@
|
||||
ALTER TABLE port_mapping ADD `protocal` varchar(10) NOT NULL DEFAULT 'TCP';
|
||||
ALTER TABLE port_mapping ADD `subdomain` varchar(50) DEFAULT NULL;
|
||||
ALTER TABLE port_mapping ADD `description` varchar(100);
|
||||
@@ -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;
|
||||
@@ -0,0 +1,38 @@
|
||||
#安全组
|
||||
CREATE TABLE IF NOT EXISTS `security_group` (
|
||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||
`name` VARCHAR(20) NOT NULL,
|
||||
`description` VARCHAR(255),
|
||||
`user_id` INTEGER NOT NULL,
|
||||
`enable` INTEGER NOT NULL,
|
||||
`default_pass_type` INTEGER NOT NULL,
|
||||
`create_time` TIMESTAMP NOT NULL,
|
||||
`update_time` TIMESTAMP NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
);
|
||||
|
||||
#安全组规则
|
||||
CREATE TABLE IF NOT EXISTS `security_rule` (
|
||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||
`group_id` INTEGER NOT NULL,
|
||||
`name` VARCHAR(20) NOT NULL,
|
||||
`description` VARCHAR(255) NOT NULL,
|
||||
`rule` text NOT NULL,
|
||||
`pass_type` INTEGER NOT NULL,
|
||||
`priority` INTEGER NOT NULL,
|
||||
`user_id` INTEGER NOT NULL,
|
||||
`enable` INTEGER NOT NULL,
|
||||
`create_time` TIMESTAMP NOT NULL,
|
||||
`update_time` TIMESTAMP NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS I_security_rule_group_id ON security_rule(group_id);
|
||||
|
||||
# port_mapping表增加字段
|
||||
ALTER TABLE `port_mapping` ADD COLUMN `security_group_id` INTEGER DEFAULT 0;
|
||||
ALTER TABLE `port_mapping` ADD COLUMN `up_limit_rate` varchar(20) DEFAULT NULL;
|
||||
ALTER TABLE `port_mapping` ADD COLUMN `down_limit_rate` varchar(20) DEFAULT NULL;
|
||||
|
||||
# license表增加字段
|
||||
ALTER TABLE `license` ADD COLUMN `up_limit_rate` varchar(20) DEFAULT NULL;
|
||||
ALTER TABLE `license` ADD COLUMN `down_limit_rate` varchar(20) DEFAULT NULL;
|
||||
@@ -102,6 +102,7 @@ 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 '客户端端口',
|
||||
@@ -241,22 +242,3 @@ CREATE TABLE IF NOT EXISTS `flow_report_month` (
|
||||
KEY `I_flow_report_month_user_id` (`user_id`),
|
||||
KEY `I_flow_report_month_license_id` (`license_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
|
||||
# 域名 映射表 AUTO_INCREMENT 设置65550 避开端口号0-65535,减少域名解析代码修改
|
||||
CREATE TABLE IF NOT EXISTS `domain_mapping` (
|
||||
`id` INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||
`license_id` INTEGER(20) NOT NULL,
|
||||
`protocal` VARCHAR(10) NOT NULL DEFAULT 'HTTP',
|
||||
`domain` VARCHAR(50) DEFAULT NULL,
|
||||
`target_path` VARCHAR(50) NOT NULL,
|
||||
`up_limit_rate` VARCHAR(20) DEFAULT NULL,
|
||||
`down_limit_rate` VARCHAR(20) DEFAULT NULL,
|
||||
`description` VARCHAR(100) DEFAULT NULL,
|
||||
`request_header` INTEGER(20) NOT NULL DEFAULT 0,
|
||||
`enable` INTEGER(2) NOT NULL,
|
||||
`security_group_id` INTEGER(20) NOT NULL DEFAULT 0,
|
||||
`create_time` TIMESTAMP NOT NULL,
|
||||
`update_time` TIMESTAMP NOT NULL
|
||||
) AUTO_INCREMENT = 65550;
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS I_domain_mapping_domain ON domain_mapping (`domain` ASC);
|
||||
@@ -1,3 +1,3 @@
|
||||
#license
|
||||
INSERT INTO license(`id`, `name`, `key`, `user_id`, `is_online`, `enable`, `create_time`, `update_time`) VALUES
|
||||
(1, '服务端(不可编辑删除,可禁用)', 'b0a907332b474b25897c4dcb31fc7eb6', 1, 1, 1, now(), now());
|
||||
(1, '我的mac', 'b0a907332b474b25897c4dcb31fc7eb6', 1, 2, 1, now(), now());
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#port_mapping
|
||||
INSERT INTO port_mapping(`id`, `license_id`, `server_port`, `protocal`, `client_ip`, `client_port`, `is_online`, `enable`,`description`,`create_time`, `update_time`) VALUES
|
||||
(1, 1, 9101, 'HTTP', '127.0.0.1', 8080, 2, 1,'test1', now(), now());
|
||||
INSERT INTO port_mapping(`id`, `license_id`, `server_port`, `protocal`, `client_ip`, `client_port`, `is_online`, `enable`,`description`, `create_time`, `update_time`) VALUES
|
||||
(2, 1, 9102, 'TCP', '127.0.0.1', 3306, 2, 1,'test2', now(), now());
|
||||
INSERT INTO port_mapping(`id`, `license_id`, `server_port`, `protocal`, `client_ip`, `client_port`, `is_online`, `enable`,`description`, `create_time`, `update_time`) VALUES
|
||||
(3, 1, 9103, 'HTTP', '127.0.0.1', 8081, 2, 1,'test3', 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
|
||||
(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());
|
||||
|
||||
@@ -9,3 +9,33 @@ INSERT INTO port_pool(`id`, `group_id`, `port`, `enable`, `create_time`, `update
|
||||
(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());
|
||||
|
||||
@@ -102,6 +102,7 @@ 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 '客户端端口',
|
||||
@@ -242,20 +243,3 @@ CREATE TABLE IF NOT EXISTS `flow_report_month` (
|
||||
KEY `I_flow_report_month_license_id` (`license_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
# 域名 映射表 AUTO_INCREMENT 设置65550 避开端口号0-65535,减少域名解析代码修改
|
||||
CREATE TABLE IF NOT EXISTS `domain_mapping` (
|
||||
`id` INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||
`license_id` INTEGER(20) NOT NULL,
|
||||
`protocal` VARCHAR(10) NOT NULL DEFAULT 'HTTP',
|
||||
`domain` VARCHAR(50) DEFAULT NULL,
|
||||
`target_path` VARCHAR(50) NOT NULL,
|
||||
`up_limit_rate` VARCHAR(20) DEFAULT NULL,
|
||||
`down_limit_rate` VARCHAR(20) DEFAULT NULL,
|
||||
`description` VARCHAR(100) DEFAULT NULL,
|
||||
`request_header` INTEGER(20) NOT NULL DEFAULT 0,
|
||||
`enable` INTEGER(2) NOT NULL COMMENT '是否启用(1、启用 2、禁用)',
|
||||
`security_group_id` INTEGER(20) NOT NULL DEFAULT 0,
|
||||
`create_time` TIMESTAMP NOT NULL,
|
||||
`update_time` TIMESTAMP NOT NULL
|
||||
) AUTO_INCREMENT = 65550;
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS I_domain_mapping_domain ON domain_mapping (`domain` ASC);
|
||||
@@ -1,3 +1,3 @@
|
||||
#license
|
||||
INSERT INTO license(`id`, `name`, `key`, `user_id`, `is_online`, `enable`, `create_time`, `update_time`) VALUES
|
||||
(1, '服务端(不可编辑删除,可禁用)', 'b0a907332b474b25897c4dcb31fc7eb6', 1, 1, 1, now(), now());
|
||||
(1, '我的mac', 'b0a907332b474b25897c4dcb31fc7eb6', 1, 2, 1, now(), now());
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#port_mapping
|
||||
INSERT INTO port_mapping(`id`, `license_id`, `server_port`, `protocal`, `client_ip`, `client_port`, `is_online`, `enable`,`description`,`create_time`, `update_time`) VALUES
|
||||
(1, 1, 9101, 'HTTP', '127.0.0.1', 8080, 2, 1,'test1', now(), now());
|
||||
INSERT INTO port_mapping(`id`, `license_id`, `server_port`, `protocal`, `client_ip`, `client_port`, `is_online`, `enable`,`description`, `create_time`, `update_time`) VALUES
|
||||
(2, 1, 9102, 'TCP', '127.0.0.1', 3306, 2, 1,'test2', now(), now());
|
||||
INSERT INTO port_mapping(`id`, `license_id`, `server_port`, `protocal`, `client_ip`, `client_port`, `is_online`, `enable`,`description`, `create_time`, `update_time`) VALUES
|
||||
(3, 1, 9103, 'HTTP', '127.0.0.1', 8081, 2, 1,'test3', 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
|
||||
(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());
|
||||
|
||||
@@ -9,3 +9,33 @@ INSERT INTO port_pool(`id`, `group_id`, `port`, `enable`, `create_time`, `update
|
||||
(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,13 @@
|
||||
ALTER TABLE port_pool ADD group_id INT NOT NULL DEFAULT 1 COMMENT "分组ID";
|
||||
|
||||
#端口分组
|
||||
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 COMMENT='端口分组';
|
||||
@@ -0,0 +1,3 @@
|
||||
ALTER TABLE port_mapping ADD `protocal` varchar(10) NOT NULL DEFAULT 'TCP' COMMENT '协议';
|
||||
ALTER TABLE port_mapping ADD `subdomain` varchar(50) DEFAULT NULL COMMENT '子域名(仅HTTP时有效)';
|
||||
ALTER TABLE port_mapping ADD `description` varchar(100) DEFAULT NULL COMMENT '描述';
|
||||
@@ -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 '代理超时毫秒数';
|
||||
@@ -0,0 +1,8 @@
|
||||
ALTER TABLE `flow_report_minute` MODIFY COLUMN `read_bytes` BIGINT NOT NULL COMMENT '读取流量';
|
||||
ALTER TABLE `flow_report_minute` MODIFY COLUMN `write_bytes` BIGINT NOT NULL COMMENT '写入流量';
|
||||
ALTER TABLE `flow_report_hour` MODIFY COLUMN `read_bytes` BIGINT NOT NULL COMMENT '读取流量';
|
||||
ALTER TABLE `flow_report_hour` MODIFY COLUMN `write_bytes` BIGINT NOT NULL COMMENT '写入流量';
|
||||
ALTER TABLE `flow_report_day` MODIFY COLUMN `read_bytes` BIGINT NOT NULL COMMENT '读取流量';
|
||||
ALTER TABLE `flow_report_day` MODIFY COLUMN `write_bytes` BIGINT NOT NULL COMMENT '写入流量';
|
||||
ALTER TABLE `flow_report_month` MODIFY COLUMN `read_bytes` BIGINT NOT NULL COMMENT '读取流量';
|
||||
ALTER TABLE `flow_report_month` MODIFY COLUMN `write_bytes` BIGINT NOT NULL COMMENT '写入流量';
|
||||
@@ -0,0 +1,38 @@
|
||||
#安全组
|
||||
CREATE TABLE IF NOT EXISTS `security_group` (
|
||||
`id` int NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`name` varchar(20) NOT NULL COMMENT '安全组名称',
|
||||
`description` varchar(255) COMMENT '安全组描述',
|
||||
`user_id` int NOT NULL COMMENT '用户ID',
|
||||
`enable` int NOT NULL COMMENT '是否启用(1、启用 2、禁用)',
|
||||
`default_pass_type` int NOT NULL COMMENT '默认放行类型',
|
||||
`create_time` datetime(3) NOT NULL COMMENT '创建时间',
|
||||
`update_time` datetime(3) NOT NULL COMMENT '更新时间',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
#安全组规则
|
||||
CREATE TABLE IF NOT EXISTS `security_rule` (
|
||||
`id` int NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`group_id` int NOT NULL COMMENT '关联安全组',
|
||||
`name` varchar(20) NOT NULL COMMENT '规则名称',
|
||||
`description` varchar(255) NOT NULL COMMENT '规则描述',
|
||||
`rule` text NOT NULL COMMENT '规则内容',
|
||||
`pass_type`int NOT NULL COMMENT '放行类型',
|
||||
`priority` int(1) NOT NULL COMMENT '优先级',
|
||||
`user_id` int NOT NULL COMMENT '用户ID',
|
||||
`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_security_rule_group_id_priority` (`group_id`, `priority`) USING BTREE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
# port_mapping表增加字段
|
||||
ALTER TABLE `port_mapping` ADD COLUMN `security_group_id` int DEFAULT 0 COMMENT '安全组Id';
|
||||
ALTER TABLE `port_mapping` ADD COLUMN `up_limit_rate` varchar(20) DEFAULT NULL COMMENT '上传限速';
|
||||
ALTER TABLE `port_mapping` ADD COLUMN `down_limit_rate` varchar(20) DEFAULT NULL COMMENT '下载限速';
|
||||
|
||||
# license表增加字段
|
||||
ALTER TABLE `license` ADD COLUMN `up_limit_rate` varchar(20) DEFAULT NULL COMMENT '上传限速';
|
||||
ALTER TABLE `license` ADD COLUMN `down_limit_rate` varchar(20) DEFAULT NULL COMMENT '下载限速';
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 26 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 21 KiB |
@@ -1,20 +0,0 @@
|
||||
---
|
||||
title: 2024年
|
||||
date: 2024-04-16 19:22:05
|
||||
permalink: /pages/acdf0a/
|
||||
---
|
||||
|
||||
|
||||
| 日期 | 渠道 | 金额 |昵称| 备注 |
|
||||
|:-----------|:---|:-----|:-|:--------------------------------------|
|
||||
| 2024-04-16 |微信转账|100|暮光:城中城| |
|
||||
| 2024-04-03 |微信转账|100|仲秀| 大神,非常感谢 |
|
||||
| 2024-03-24 |Gitee捐助|10|include|
|
||||
| 2024-03-24 |微信赞赏码|9|宗| 麻烦了,最好能加一个返回公网IP。<br/>不知道有没有几乎通用的方案 |
|
||||
| 2024-03-22 |微信红包|20|不允| 请你吃外卖 |
|
||||
| 2024-03-12 |微信红包|50|喜鸽小宝|
|
||||
| 2024-02-12 |微信红包|50|喜鸽小宝|
|
||||
| 2024-02-02 |微信红包|38.88|不请自来君|
|
||||
| 2024-01-24 |Gitee捐助|30|唐吉诃德| 感谢您的开源项目!是一个不错的项目!<br/>希望继续完善界面UI的设计。 |
|
||||
| 2024-01-20 |微信红包|shiyongsway|8.88|
|
||||
| 2024-01-17 |微信红包|50|喜鸽小宝| |
|
||||
@@ -148,15 +148,11 @@ postList: none
|
||||
<div class="card-list">
|
||||
<a href="https://www.xigexb.com?from=neutrino-proxy" target="_blank" class="card-item row-3" style="background-color:#102863;--random-color:#102863;color:#FFFFFF;">
|
||||
<img src="img/sponsor/xigexiaobao.jpg" class="no-zoom">
|
||||
<div><p class="name">喜鸽小宝</p> <p class="desc">一个爱好写代码的同学。<br/> </p></div>
|
||||
<div><p class="name">喜鸽小宝</p> <p class="desc">一个爱好写代码的同学。</p></div>
|
||||
</a>
|
||||
<a href="https://7bu.top?from=neutrino-proxy" target="_blank" class="card-item row-3" style="background-color:#c6ddff;--random-color:#c6ddff;color:#000000;">
|
||||
<img src="img/sponsor/7bu.ico" class="no-zoom">
|
||||
<div><p class="name">去不图床</p> <p class="desc">杜老师说旗下付费图片外链平台。<br/> </p></div>
|
||||
</a>
|
||||
<a href="http://doc.zyplayer.com/#/integrate/zyplayer-doc?utm=neutrino-proxy" target="_blank" class="card-item row-3" style="background-color:#486898;--random-color:#c6ddff;color:#FFFFFF;">
|
||||
<img src="img/sponsor/zyplayer-doc.png" class="no-zoom">
|
||||
<div><p class="name">zyplayer-doc</p> <p class="desc">私有化部署的企业级文档管理与知识库AI问答平台。</p></div>
|
||||
<div><p class="name">去不图床</p> <p class="desc">杜老师说旗下付费图片外链平台。</p></div>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
"scripts": {
|
||||
"dev": "vuepress dev docs",
|
||||
"build": "vuepress build docs",
|
||||
"buildAndDeploy": "vuepress build docs && bash deploy/deploy2.sh",
|
||||
"deploy": "bash deploy/deploy2.sh",
|
||||
"buildAndDeploy": "vuepress build docs && bash deploy.sh",
|
||||
"deploy": "bash deploy.sh",
|
||||
"updateTheme": "yarn remove vuepress-theme-vdoing && rm -rf node_modules && yarn && yarn add vuepress-theme-vdoing -D",
|
||||
"editFm": "node utils/editFrontmatter.js"
|
||||
},
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>org.noear</groupId>
|
||||
<artifactId>solon-parent</artifactId>
|
||||
<version>2.7.6</version>
|
||||
<version>2.7.0-M2</version>
|
||||
<relativePath />
|
||||
</parent>
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
<module>neutrino-proxy-core</module>
|
||||
<module>neutrino-proxy-client</module>
|
||||
<module>neutrino-proxy-server</module>
|
||||
<module>neutrino-proxy-client-sdk</module>
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
|
||||
@@ -5,11 +5,9 @@ export JAVA_HOME=/Users/yangwen/my/service/graalvm/graalvm-community-openjdk-21.
|
||||
export MAVEN_HOME=/Users/yangwen/my/service/maven/apache-maven-3.8.1
|
||||
export PATH=:$PATH:$JAVA_HOME/bin:$MAVEN_HOME/bin
|
||||
|
||||
MODULE_NAME=neutrino-proxy-client
|
||||
deployDir="deploy"
|
||||
clientDeployDir=$deployDir"/client"
|
||||
machine=macos
|
||||
VER=2.0.1
|
||||
|
||||
#切到项目根目录
|
||||
cd ../..
|
||||
@@ -17,38 +15,38 @@ cd ../..
|
||||
mkdir -p $clientDeployDir
|
||||
|
||||
# 删除原来的编译文件
|
||||
rm -rf $clientDeployDir/$MODULE_NAME.jar
|
||||
rm -rf $clientDeployDir/$MODULE_NAME
|
||||
rm -rf $clientDeployDir/$MODULE_NAME-jdk21-$VER-jar
|
||||
rm -rf $clientDeployDir/$MODULE_NAME-jdk21-$VER-jar.zip
|
||||
rm -rf $clientDeployDir/$MODULE_NAME-$machine-$VER-native
|
||||
rm -rf $clientDeployDir/$MODULE_NAME-$machine-$VER-native.zip
|
||||
rm -rf $clientDeployDir/neutrino-proxy-client.jar
|
||||
rm -rf $clientDeployDir/neutrino-proxy-client
|
||||
rm -rf $clientDeployDir/neutrino-proxy-client-jar
|
||||
rm -rf $clientDeployDir/neutrino-proxy-client-jar.zip
|
||||
rm -rf $clientDeployDir/neutrino-proxy-client-${machine}-native
|
||||
rm -rf $clientDeployDir/neutrino-proxy-client-${machine}-native.zip
|
||||
|
||||
#客户端打包
|
||||
mvn clean install -U -pl $MODULE_NAME -am -Dmaven.test.skip=true
|
||||
cd $MODULE_NAME
|
||||
mvn clean install -U -pl neutrino-proxy-client -am -Dmaven.test.skip=true
|
||||
cd neutrino-proxy-client
|
||||
mvn clean native:compile -P native -DskipTests
|
||||
cd ..
|
||||
|
||||
# 给执行权限
|
||||
chmod +x ./$MODULE_NAME/target/$MODULE_NAME
|
||||
chmod +x ./neutrino-proxy-client/target/neutrino-proxy-client
|
||||
|
||||
# 拷贝到deploy目录下
|
||||
cp ./$MODULE_NAME/target/$MODULE_NAME.jar $clientDeployDir/$MODULE_NAME.jar
|
||||
cp ./$MODULE_NAME/target/$MODULE_NAME $clientDeployDir/$MODULE_NAME
|
||||
cp ./neutrino-proxy-client/target/neutrino-proxy-client.jar $clientDeployDir/neutrino-proxy-client.jar
|
||||
cp ./neutrino-proxy-client/target/neutrino-proxy-client $clientDeployDir/neutrino-proxy-client
|
||||
|
||||
#打zip包,用于发版
|
||||
cd $clientDeployDir
|
||||
## jar
|
||||
mkdir $MODULE_NAME-jdk21-$VER-jar
|
||||
cp ../../$MODULE_NAME/target/$MODULE_NAME.jar ./$MODULE_NAME-jdk21-$VER-jar/$MODULE_NAME.jar
|
||||
cp ../../$MODULE_NAME/src/main/resources/app-copy.yml ./$MODULE_NAME-jdk21-$VER-jar/app.yml
|
||||
zip -r $MODULE_NAME-jdk21-$VER-jar.zip ./$MODULE_NAME-jdk21-$VER-jar
|
||||
rm -rf ./$MODULE_NAME-jdk21-$VER-jar
|
||||
mkdir neutrino-proxy-client-jar
|
||||
cp ../../neutrino-proxy-client/target/neutrino-proxy-client.jar ./neutrino-proxy-client-jar/neutrino-proxy-client.jar
|
||||
cp ../../neutrino-proxy-client/src/main/resources/app-copy.yml ./neutrino-proxy-client-jar/app.yml
|
||||
zip -r neutrino-proxy-client-jar.zip ./neutrino-proxy-client-jar
|
||||
rm -rf ./neutrino-proxy-client-jar
|
||||
|
||||
## native
|
||||
mkdir $MODULE_NAME-$machine-$VER-native
|
||||
cp ../../$MODULE_NAME/target/$MODULE_NAME ./$MODULE_NAME-$machine-$VER-native/$MODULE_NAME
|
||||
cp ../../$MODULE_NAME/src/main/resources/app-copy.yml ./$MODULE_NAME-$machine-$VER-native/app.yml
|
||||
zip -r $MODULE_NAME-$machine-$VER-native.zip ./$MODULE_NAME-$machine-$VER-native
|
||||
rm -rf ./$MODULE_NAME-$machine-$VER-native
|
||||
mkdir neutrino-proxy-client-${machine}-native
|
||||
cp ../../neutrino-proxy-client/target/neutrino-proxy-client ./neutrino-proxy-client-${machine}-native/neutrino-proxy-client
|
||||
cp ../../neutrino-proxy-client/src/main/resources/app-copy.yml ./neutrino-proxy-client-${machine}-native/app.yml
|
||||
zip -r neutrino-proxy-client-${machine}-native.zip ./neutrino-proxy-client-${machine}-native
|
||||
rm -rf ./neutrino-proxy-client-${machine}-native
|
||||
|
||||
@@ -5,11 +5,9 @@ export JAVA_HOME=/Users/yangwen/my/service/graalvm/graalvm-community-openjdk-21.
|
||||
export MAVEN_HOME=/Users/yangwen/my/service/maven/apache-maven-3.8.1
|
||||
export PATH=:$PATH:$JAVA_HOME/bin:$MAVEN_HOME/bin
|
||||
|
||||
MODULE_NAME=neutrino-proxy-server
|
||||
deployDir="deploy"
|
||||
serverDeployDir=$deployDir"/server"
|
||||
machine=macos
|
||||
VER=2.0.1
|
||||
|
||||
#切到项目根目录
|
||||
cd ../..
|
||||
@@ -17,12 +15,12 @@ cd ../..
|
||||
mkdir -p $serverDeployDir
|
||||
|
||||
# 删除原来的编译文件
|
||||
rm -rf $serverDeployDir/$MODULE_NAME.jar
|
||||
rm -rf $serverDeployDir/$MODULE_NAME
|
||||
rm -rf $serverDeployDir/$MODULE_NAME-jdk21-$VER-jar
|
||||
rm -rf $serverDeployDir/$MODULE_NAME-jdk21-$VER-jar.zip
|
||||
rm -rf $serverDeployDir/$MODULE_NAME-$machine-$VER-native
|
||||
rm -rf $serverDeployDir/$MODULE_NAME-$machine-$VER-native.zip
|
||||
rm -rf $serverDeployDir/neutrino-proxy-server.jar
|
||||
rm -rf $serverDeployDir/neutrino-proxy-server
|
||||
rm -rf $serverDeployDir/neutrino-proxy-server-jar
|
||||
rm -rf $serverDeployDir/neutrino-proxy-server-jar.zip
|
||||
rm -rf $serverDeployDir/neutrino-proxy-server-${machine}-native
|
||||
rm -rf $serverDeployDir/neutrino-proxy-server-${machine}-native.zip
|
||||
|
||||
# 不需要每次都重新编译一次前端代码,如果前端代码有变更,编译前需要手动执行`admin_build_docker.sh`
|
||||
##前端页面打包
|
||||
@@ -34,30 +32,30 @@ rm -rf $serverDeployDir/$MODULE_NAME-$machine-$VER-native.zip
|
||||
#cp -rf ./neutrino-proxy-admin/dist/ ./neutrino-proxy-server/src/main/resources/static
|
||||
|
||||
#服务端打包
|
||||
mvn clean install -U -pl $MODULE_NAME -am -Dmaven.test.skip=true
|
||||
cd $MODULE_NAME
|
||||
mvn clean install -U -pl neutrino-proxy-server -am -Dmaven.test.skip=true
|
||||
cd neutrino-proxy-server
|
||||
mvn clean native:compile -P native -DskipTests
|
||||
cd ..
|
||||
|
||||
# 给执行权限
|
||||
chmod +x ./$MODULE_NAME/target/$MODULE_NAME
|
||||
chmod +x ./neutrino-proxy-server/target/neutrino-proxy-server
|
||||
|
||||
# 拷贝到deploy目录下
|
||||
cp ./$MODULE_NAME/target/$MODULE_NAME.jar $serverDeployDir/$MODULE_NAME.jar
|
||||
cp ./$MODULE_NAME/target/$MODULE_NAME $serverDeployDir/$MODULE_NAME
|
||||
cp ./neutrino-proxy-server/target/neutrino-proxy-server.jar $serverDeployDir/neutrino-proxy-server.jar
|
||||
cp ./neutrino-proxy-server/target/neutrino-proxy-server $serverDeployDir/neutrino-proxy-server
|
||||
|
||||
#打zip包,用于发版
|
||||
cd $serverDeployDir
|
||||
## jar
|
||||
mkdir $MODULE_NAME-jdk21-$VER-jar
|
||||
cp ../../$MODULE_NAME/target/$MODULE_NAME.jar ./$MODULE_NAME-jdk21-$VER-jar/$MODULE_NAME.jar
|
||||
cp ../../$MODULE_NAME/src/main/resources/app-copy.yml ./$MODULE_NAME-jdk21-$VER-jar/app.yml
|
||||
zip -r $MODULE_NAME-jdk21-$VER-jar.zip ./$MODULE_NAME-jdk21-$VER-jar
|
||||
rm -rf ./$MODULE_NAME-jdk21-$VER-jar
|
||||
mkdir neutrino-proxy-server-jar
|
||||
cp ../../neutrino-proxy-server/target/neutrino-proxy-server.jar ./neutrino-proxy-server-jar/neutrino-proxy-server.jar
|
||||
cp ../../neutrino-proxy-server/src/main/resources/app-copy.yml ./neutrino-proxy-server-jar/app.yml
|
||||
zip -r neutrino-proxy-server-jar.zip ./neutrino-proxy-server-jar
|
||||
rm -rf ./neutrino-proxy-server-jar
|
||||
|
||||
## native
|
||||
mkdir $MODULE_NAME-$machine-$VER-native
|
||||
cp ../../$MODULE_NAME/target/$MODULE_NAME ./$MODULE_NAME-$machine-$VER-native/$MODULE_NAME
|
||||
cp ../../$MODULE_NAME/src/main/resources/app-copy.yml ./$MODULE_NAME-$machine-$VER-native/app.yml
|
||||
zip -r $MODULE_NAME-$machine-$VER-native.zip ./$MODULE_NAME-$machine-$VER-native
|
||||
rm -rf ./$MODULE_NAME-$machine-$VER-native
|
||||
mkdir neutrino-proxy-server-${machine}-native
|
||||
cp ../../neutrino-proxy-server/target/neutrino-proxy-server ./neutrino-proxy-server-${machine}-native/neutrino-proxy-server
|
||||
cp ../../neutrino-proxy-server/src/main/resources/app-copy.yml ./neutrino-proxy-server-${machine}-native/app.yml
|
||||
zip -r neutrino-proxy-server-${machine}-native.zip ./neutrino-proxy-server-${machine}-native
|
||||
rm -rf ./neutrino-proxy-server-${machine}-native
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
@echo off
|
||||
@rem basic params
|
||||
set ENV=dev
|
||||
set NODE_VERSION=v13.12.0
|
||||
set MODULE_NAME=neutrino-proxy-admin
|
||||
@rem 判断当前node版本是否符合,如果不符合切换node版本
|
||||
for /f "tokens=1" %%v in ('node -v') do set v=%%v
|
||||
if not "%v%" == "%NODE_VERSION%" (
|
||||
echo Node.js version is not %NODE_VERSION%.
|
||||
@rem 判断是否安装nvm
|
||||
set "nvm_home=%NVM_HOME%"
|
||||
set "nvm_symlink=%NVM_SYMLINK%"
|
||||
if not defined nvm_home (
|
||||
echo nvm is not installed,then use nvm to install node %NODE_VERSION%.
|
||||
) else if not defined nvm_symlink (
|
||||
echo nvm is not installed,then use nvm to install node %NODE_VERSION%.
|
||||
) else (
|
||||
echo nvm is installed.
|
||||
nvm use %NODE_VERSION%
|
||||
)
|
||||
)
|
||||
cd %~dp0 && cd ../../%MODULE_NAME%
|
||||
@rem 检查dist文件夹是否存在,存在就删除,/s选项表示将目录及其所有子目录一起删除,/q选项表示不需要确认操作
|
||||
if exist dist (
|
||||
rmdir /s /q dist
|
||||
)
|
||||
@rem 等待npm执行完毕
|
||||
call npm install
|
||||
npm run build:%ENV% && pause
|
||||
@@ -24,17 +24,6 @@ cd %~dp0 && cd ../../%MODULE_NAME%
|
||||
if exist dist (
|
||||
rmdir /s /q dist
|
||||
)
|
||||
@rem 编译
|
||||
@rem 等待npm执行完毕
|
||||
call npm install
|
||||
call npm run build:%ENV%
|
||||
|
||||
echo 开始拷贝
|
||||
@rem 拷贝
|
||||
cd ..
|
||||
del /Q /F .\neutrino-proxy-server\src\main\resources\static
|
||||
rd /S /Q .\neutrino-proxy-server\src\main\resources\static
|
||||
mkdir .\neutrino-proxy-server\src\main\resources\static
|
||||
xcopy /S /E neutrino-proxy-admin\dist neutrino-proxy-server\src\main\resources\static
|
||||
|
||||
@rem 回到脚本目录
|
||||
cd scripts\win
|
||||
npm run build:%ENV% && pause
|
||||
@@ -1,63 +0,0 @@
|
||||
@echo off
|
||||
@rem console output code changed to UTF-8
|
||||
chcp 65001
|
||||
@rem basic params
|
||||
set MODULE_NAME=neutrino-proxy-client
|
||||
@rem step
|
||||
cd %~dp0 && cd ../../
|
||||
|
||||
SET VS_HOME=C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519
|
||||
SET JAVA_HOME=C:\my\package\jdk\graalvm-community-openjdk-21.0.2
|
||||
SET MAVEN_HOME=C:\my\package\maven\apache-maven-3.9.6
|
||||
SET WIN_RAR_HOME=C:\Program Files\WinRAR
|
||||
SET PATH=%PATH%;%JAVA_HOME%\bin;%MAVEN_HOME%\bin;%VS_HOME%\bin;%WIN_RAR_HOME%
|
||||
SET INCLUDE=%INCLUDE%;%VS_HOME%\include;
|
||||
SET LIB=%LIB%;%VS_HOME%\lib;
|
||||
|
||||
SET deployDir=deploy
|
||||
SET clientDeployDir=%deployDir%\client
|
||||
SET machine=windows
|
||||
SET VER=2.0.1
|
||||
|
||||
@rem 初始化文件夹
|
||||
mkdir -p %clientDeployDir%
|
||||
|
||||
@rem 删除原来的编译文件
|
||||
del /S /Q /F %clientDeployDir%\%MODULE_NAME%.jar
|
||||
del /S /Q /F %clientDeployDir%\%MODULE_NAME%.exe
|
||||
del /S /Q /F %clientDeployDir%\%MODULE_NAME%-jdk21-%VER%-jar
|
||||
del /S /Q /F %clientDeployDir%\%MODULE_NAME%-jdk21-%VER%-jar.zip
|
||||
del /S /Q /F %clientDeployDir%\%MODULE_NAME%-%machine%-%VER%-native
|
||||
del /S /Q /F %clientDeployDir%\%MODULE_NAME%-%machine%-%VER%-native.zip
|
||||
rd /S /Q %clientDeployDir%\%MODULE_NAME%-jdk21-%VER%-jar
|
||||
rd /S /Q %clientDeployDir%\%MODULE_NAME%-%machine%-%VER%-native
|
||||
|
||||
@rem 客户端打包
|
||||
call mvn clean install -U -pl %MODULE_NAME% -am -Dmaven.test.skip=true
|
||||
cd %MODULE_NAME%
|
||||
call mvn clean native:compile -P native -DskipTests
|
||||
cd ..
|
||||
|
||||
@rem 拷贝到deploy目录下
|
||||
copy .\%MODULE_NAME%\target\%MODULE_NAME%.jar .\%clientDeployDir%\%MODULE_NAME%.jar
|
||||
copy .\%MODULE_NAME%\target\%MODULE_NAME%.exe .\%clientDeployDir%\%MODULE_NAME%.exe
|
||||
|
||||
@rem 打zip包,用于发版
|
||||
cd %clientDeployDir%
|
||||
@rem jar
|
||||
mkdir %MODULE_NAME%-jdk21-%VER%-jar
|
||||
copy %MODULE_NAME%.jar %MODULE_NAME%-jdk21-%VER%-jar
|
||||
copy ..\..\%MODULE_NAME%\src\main\resources\app-copy.yml %MODULE_NAME%-jdk21-%VER%-jar\app.yml
|
||||
Rar a %MODULE_NAME%-jdk21-%VER%-jar.zip %MODULE_NAME%-jdk21-%VER%-jar
|
||||
|
||||
@rem native
|
||||
mkdir %MODULE_NAME%-%machine%-%VER%-native
|
||||
copy %MODULE_NAME%.exe %MODULE_NAME%-%machine%-%VER%-native
|
||||
copy ..\..\%MODULE_NAME%\src\main\resources\app-copy.yml %MODULE_NAME%-%machine%-%VER%-native\app.yml
|
||||
Rar a %MODULE_NAME%-%machine%-%VER%-native.zip %MODULE_NAME%-%machine%-%VER%-native
|
||||
|
||||
@rem 删除临时文件
|
||||
|
||||
|
||||
@rem 回到脚本目录
|
||||
cd ..\..\scripts\win
|
||||
@@ -1,63 +0,0 @@
|
||||
@echo off
|
||||
@rem console output code changed to UTF-8
|
||||
chcp 65001
|
||||
@rem basic params
|
||||
set MODULE_NAME=neutrino-proxy-server
|
||||
@rem step
|
||||
cd %~dp0 && cd ../../
|
||||
|
||||
SET VS_HOME=C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519
|
||||
SET JAVA_HOME=C:\my\package\jdk\graalvm-community-openjdk-21.0.2
|
||||
SET MAVEN_HOME=C:\my\package\maven\apache-maven-3.9.6
|
||||
SET WIN_RAR_HOME=C:\Program Files\WinRAR
|
||||
SET PATH=%PATH%;%JAVA_HOME%\bin;%MAVEN_HOME%\bin;%VS_HOME%\bin;%WIN_RAR_HOME%
|
||||
SET INCLUDE=%INCLUDE%;%VS_HOME%\include;
|
||||
SET LIB=%LIB%;%VS_HOME%\lib;
|
||||
|
||||
SET deployDir=deploy
|
||||
SET serverDeployDir=%deployDir%\server
|
||||
SET machine=windows
|
||||
SET VER=2.0.1
|
||||
|
||||
@rem 初始化文件夹
|
||||
mkdir -p %serverDeployDir%
|
||||
|
||||
@rem 删除原来的编译文件
|
||||
del /S /Q /F %serverDeployDir%\%MODULE_NAME%.jar
|
||||
del /S /Q /F %serverDeployDir%\%MODULE_NAME%.exe
|
||||
del /S /Q /F %serverDeployDir%\%MODULE_NAME%-jdk21-%VER%-jar
|
||||
del /S /Q /F %serverDeployDir%\%MODULE_NAME%-jdk21-%VER%-jar.zip
|
||||
del /S /Q /F %serverDeployDir%\%MODULE_NAME%-%machine%-%VER%-native
|
||||
del /S /Q /F %serverDeployDir%\%MODULE_NAME%-%machine%-%VER%-native.zip
|
||||
rd /S /Q %serverDeployDir%\%MODULE_NAME%-jdk21-%VER%-jar
|
||||
rd /S /Q %serverDeployDir%\%MODULE_NAME%-%machine%-%VER%-native
|
||||
|
||||
@rem 服务端打包
|
||||
call mvn clean install -U -pl %MODULE_NAME% -am -Dmaven.test.skip=true
|
||||
cd %MODULE_NAME%
|
||||
call mvn clean native:compile -P native -DskipTests
|
||||
cd ..
|
||||
|
||||
@rem 拷贝到deploy目录下
|
||||
copy .\%MODULE_NAME%\target\%MODULE_NAME%.jar .\%serverDeployDir%\%MODULE_NAME%.jar
|
||||
copy .\%MODULE_NAME%\target\%MODULE_NAME%.exe .\%serverDeployDir%\%MODULE_NAME%.exe
|
||||
|
||||
@rem 打zip包,用于发版
|
||||
cd %serverDeployDir%
|
||||
@rem jar
|
||||
mkdir %MODULE_NAME%-jdk21-%VER%-jar
|
||||
copy %MODULE_NAME%.jar %MODULE_NAME%-jdk21-%VER%-jar
|
||||
copy ..\..\%MODULE_NAME%\src\main\resources\app-copy.yml %MODULE_NAME%-jdk21-%VER%-jar\app.yml
|
||||
Rar a %MODULE_NAME%-jdk21-%VER%-jar.zip %MODULE_NAME%-jdk21-%VER%-jar
|
||||
|
||||
@rem native
|
||||
mkdir %MODULE_NAME%-%machine%-%VER%-native
|
||||
copy %MODULE_NAME%.exe %MODULE_NAME%-%machine%-%VER%-native
|
||||
copy ..\..\%MODULE_NAME%\src\main\resources\app-copy.yml %MODULE_NAME%-%machine%-%VER%-native\app.yml
|
||||
Rar a %MODULE_NAME%-%machine%-%VER%-native.zip %MODULE_NAME%-%machine%-%VER%-native
|
||||
|
||||
@rem 删除临时文件
|
||||
|
||||
|
||||
@rem 回到脚本目录
|
||||
cd ..\..\scripts\win
|
||||
Reference in New Issue
Block a user