From b6e76ecc7479156c9564e4056c144adbfe2d8ced Mon Sep 17 00:00:00 2001 From: aoshiguchen <1052045476@qq.com> Date: Mon, 3 Apr 2023 12:09:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9F=9F=E5=90=8D=E6=98=A0=E5=B0=84=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E6=B5=8B=E8=AF=95=E3=80=81bug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- neutrino-proxy-server/pom.xml | 18 +++++++++--------- .../server/dal/LicenseMapper.java | 2 +- .../server/proxy/core/HttpProxy.java | 1 - .../server/service/LicenseService.java | 12 +++++++++++- .../server/service/PortMappingService.java | 13 +++++++++++-- .../src/main/resources/app.yml | 2 ++ .../resources/sql/mysql/port_mapping.data.sql | 4 ++-- .../resources/sql/sqlite/port_mapping.data.sql | 4 ++-- 8 files changed, 38 insertions(+), 18 deletions(-) diff --git a/neutrino-proxy-server/pom.xml b/neutrino-proxy-server/pom.xml index a3591f21..79084093 100644 --- a/neutrino-proxy-server/pom.xml +++ b/neutrino-proxy-server/pom.xml @@ -83,16 +83,16 @@ - - - ${project.basedir}/src/main/resources - false + + + + - - app-*.yml - - - + + + + + maven-assembly-plugin diff --git a/neutrino-proxy-server/src/main/java/org/dromara/neutrinoproxy/server/dal/LicenseMapper.java b/neutrino-proxy-server/src/main/java/org/dromara/neutrinoproxy/server/dal/LicenseMapper.java index 0ceb8a46..4f0a95a5 100644 --- a/neutrino-proxy-server/src/main/java/org/dromara/neutrinoproxy/server/dal/LicenseMapper.java +++ b/neutrino-proxy-server/src/main/java/org/dromara/neutrinoproxy/server/dal/LicenseMapper.java @@ -72,7 +72,7 @@ public interface LicenseMapper extends BaseMapper { default void updateOnlineStatus(Integer isOnline, Date updateTime) { this.update(null, new LambdaUpdateWrapper() - .set(LicenseDO::getIsOnline, updateTime) + .set(LicenseDO::getIsOnline, isOnline) .set(LicenseDO::getUpdateTime, updateTime) ); } diff --git a/neutrino-proxy-server/src/main/java/org/dromara/neutrinoproxy/server/proxy/core/HttpProxy.java b/neutrino-proxy-server/src/main/java/org/dromara/neutrinoproxy/server/proxy/core/HttpProxy.java index ff680fb2..618148fb 100644 --- a/neutrino-proxy-server/src/main/java/org/dromara/neutrinoproxy/server/proxy/core/HttpProxy.java +++ b/neutrino-proxy-server/src/main/java/org/dromara/neutrinoproxy/server/proxy/core/HttpProxy.java @@ -1,7 +1,6 @@ package org.dromara.neutrinoproxy.server.proxy.core; import cn.hutool.core.util.StrUtil; -import com.sun.deploy.net.proxy.ProxyType; import io.netty.bootstrap.ServerBootstrap; import io.netty.buffer.ByteBuf; import io.netty.channel.*; diff --git a/neutrino-proxy-server/src/main/java/org/dromara/neutrinoproxy/server/service/LicenseService.java b/neutrino-proxy-server/src/main/java/org/dromara/neutrinoproxy/server/service/LicenseService.java index e818c6db..e1a66a03 100644 --- a/neutrino-proxy-server/src/main/java/org/dromara/neutrinoproxy/server/service/LicenseService.java +++ b/neutrino-proxy-server/src/main/java/org/dromara/neutrinoproxy/server/service/LicenseService.java @@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; import com.google.common.collect.Sets; +import org.dromara.neutrinoproxy.server.base.db.DBInitialize; import org.dromara.neutrinoproxy.server.base.page.PageInfo; import org.dromara.neutrinoproxy.server.base.page.PageQuery; import org.dromara.neutrinoproxy.server.base.rest.SystemContextHolder; @@ -27,6 +28,7 @@ import org.apache.ibatis.solon.annotation.Db; import org.dromara.neutrinoproxy.server.controller.res.proxy.*; import org.jetbrains.annotations.Nullable; import org.noear.solon.annotation.Component; +import org.noear.solon.annotation.Init; import org.noear.solon.annotation.Inject; import org.noear.solon.core.Lifecycle; import org.noear.solon.core.bean.LifecycleBean; @@ -50,6 +52,8 @@ public class LicenseService implements LifecycleBean { private UserMapper userMapper; @Inject private VisitorChannelService visitorChannelService; + @Inject + private DBInitialize dbInitialize; public PageInfo page(PageQuery pageQuery, LicenseListReq req) { Page result = PageHelper.startPage(pageQuery.getCurrent(), pageQuery.getSize()); @@ -217,9 +221,15 @@ public class LicenseService implements LifecycleBean { /** * 服务端项目停止、启动时,更新在线状态为离线 */ + @Init + public void init() { + licenseMapper.updateOnlineStatus(OnlineStatusEnum.OFFLINE.getStatus(), new Date()); + } + + @Override public void start() throws Throwable { - licenseMapper.updateOnlineStatus(OnlineStatusEnum.OFFLINE.getStatus(), new Date()); + } /** diff --git a/neutrino-proxy-server/src/main/java/org/dromara/neutrinoproxy/server/service/PortMappingService.java b/neutrino-proxy-server/src/main/java/org/dromara/neutrinoproxy/server/service/PortMappingService.java index 7e89c5b5..e1069ca1 100644 --- a/neutrino-proxy-server/src/main/java/org/dromara/neutrinoproxy/server/service/PortMappingService.java +++ b/neutrino-proxy-server/src/main/java/org/dromara/neutrinoproxy/server/service/PortMappingService.java @@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; import com.google.common.collect.Sets; +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; @@ -34,6 +35,7 @@ import org.apache.ibatis.solon.annotation.Db; import org.dromara.neutrinoproxy.server.controller.res.proxy.*; import org.dromara.neutrinoproxy.server.util.ProxyUtil; import org.noear.solon.annotation.Component; +import org.noear.solon.annotation.Init; import org.noear.solon.annotation.Inject; import org.noear.solon.core.Lifecycle; import org.noear.solon.core.bean.LifecycleBean; @@ -66,6 +68,8 @@ public class PortMappingService implements LifecycleBean { private PortPoolService portPoolService; @Inject private ProxyConfig proxyConfig; + @Inject + private DBInitialize dbInitialize; public PageInfo page(PageQuery pageQuery, PortMappingListReq req) { Page result = PageHelper.startPage(pageQuery.getCurrent(), pageQuery.getSize()); @@ -274,8 +278,8 @@ public class PortMappingService implements LifecycleBean { /** * 服务端项目停止、启动时,更新在线状态为离线 */ - @Override - public void start() throws Throwable { + @Init + public void init() { portMappingMapper.updateOnlineStatus(OnlineStatusEnum.OFFLINE.getStatus(), new Date()); // 未配置域名,则不需要处理域名映射逻辑 @@ -297,6 +301,11 @@ public class PortMappingService implements LifecycleBean { }); } + @Override + public void start() throws Throwable { + + } + /** * 服务端项目停止、启动时,更新在线状态为离线 */ diff --git a/neutrino-proxy-server/src/main/resources/app.yml b/neutrino-proxy-server/src/main/resources/app.yml index 3bca9b98..4bd07246 100644 --- a/neutrino-proxy-server/src/main/resources/app.yml +++ b/neutrino-proxy-server/src/main/resources/app.yml @@ -20,6 +20,8 @@ neutrino: key-store-password: 123456 key-manager-password: 123456 jks-path: classpath:/test.jks + # 如果不配置,则不支持代理http + domain-name: data: db: type: sqlite diff --git a/neutrino-proxy-server/src/main/resources/sql/mysql/port_mapping.data.sql b/neutrino-proxy-server/src/main/resources/sql/mysql/port_mapping.data.sql index e7858bef..9063ecea 100644 --- a/neutrino-proxy-server/src/main/resources/sql/mysql/port_mapping.data.sql +++ b/neutrino-proxy-server/src/main/resources/sql/mysql/port_mapping.data.sql @@ -1,7 +1,7 @@ #port_mapping INSERT INTO port_mapping(`id`, `license_id`, `server_port`, `protocal`, `subdomain`, `client_ip`, `client_port`, `is_online`, `enable`, `create_time`, `update_time`) VALUES (1, 1, 9101, 'HTTP', 'test1', '127.0.0.1', 8080, 2, 1, now(), now()); -INSERT INTO port_mapping(`id`, `license_id`, `server_port`, `client_ip`, `client_port`, `is_online`, `enable`, `create_time`, `update_time`) VALUES +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`, `client_ip`, `client_port`, `is_online`, `enable`, `create_time`, `update_time`) VALUES +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()); diff --git a/neutrino-proxy-server/src/main/resources/sql/sqlite/port_mapping.data.sql b/neutrino-proxy-server/src/main/resources/sql/sqlite/port_mapping.data.sql index 81798272..2b2847cb 100644 --- a/neutrino-proxy-server/src/main/resources/sql/sqlite/port_mapping.data.sql +++ b/neutrino-proxy-server/src/main/resources/sql/sqlite/port_mapping.data.sql @@ -1,7 +1,7 @@ #port_mapping INSERT INTO port_mapping(`id`, `license_id`, `server_port`, `protocal`, `subdomain`, `client_ip`, `client_port`, `is_online`, `enable`, `create_time`, `update_time`) VALUES (1, 1, 9101, 'HTTP', 'test1', '127.0.0.1', 8080, 2, 1, STRFTIME('%s000', 'NOW'), STRFTIME('%s000', 'NOW')); -INSERT INTO port_mapping(`id`, `license_id`, `server_port`, `client_ip`, `client_port`, `is_online`, `enable`, `create_time`, `update_time`) VALUES +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, STRFTIME('%s000', 'NOW'), STRFTIME('%s000', 'NOW')); -INSERT INTO port_mapping(`id`, `license_id`, `server_port`, `client_ip`, `client_port`, `is_online`, `enable`, `create_time`, `update_time`) VALUES +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, STRFTIME('%s000', 'NOW'), STRFTIME('%s000', 'NOW')); \ No newline at end of file