From aca5fb847bb8648df2e90ebcf727e11d9e31936b Mon Sep 17 00:00:00 2001
From: xj <550345579@qq.com>
Date: Mon, 4 Mar 2024 21:35:03 +0800
Subject: [PATCH] =?UTF-8?q?=E5=9F=9F=E5=90=8D=E8=A7=A3=E6=9E=90?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../src/views/proxy/domainMapping.vue | 265 +++---------------
.../src/views/proxy/portMapping.vue | 63 +----
.../server/controller/DomainController.java | 51 +---
.../PortMappingUpdateEnableStatusReq.java | 3 +
.../server/dal/DomainMappingMapper.java | 34 +--
.../server/service/DomainMappingService.java | 119 ++++----
.../resources/mapper/DomainMappingMapper.xml | 8 +-
.../resources/mapper/PortMappingMapper.xml | 2 +-
8 files changed, 121 insertions(+), 424 deletions(-)
diff --git a/neutrino-proxy-admin/src/views/proxy/domainMapping.vue b/neutrino-proxy-admin/src/views/proxy/domainMapping.vue
index bd8a6c7c..8d49f298 100644
--- a/neutrino-proxy-admin/src/views/proxy/domainMapping.vue
+++ b/neutrino-proxy-admin/src/views/proxy/domainMapping.vue
@@ -10,12 +10,12 @@
-
+
-
+
-
+
{{
@@ -54,7 +54,6 @@
-
{{ scope.row.serverPort }}
@@ -92,19 +91,19 @@
- {{ scope.row.enable | statusName }}
+ {{ statusOptions[scope.row.enable] }}
- {{ scope.row.isOnline | isOnlineName }}
+ {{ onlineOptions[scope.row.isOnline] }}
- {{ $t('table.openWebPage') }}
+ {{ $t('table.openWebPage') }}
@@ -113,8 +112,7 @@
{{ $t('table.edit') }}
{{ $t('table.disable') }}
{{ $t('table.enable') }}
-
-
+
@@ -128,58 +126,21 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+ http(s):
+
-
-
-
-
-
+
+
-
-
-
- .{{ domainName }}
-
-
-
-
-
-
-
-
- 毫秒
-
-
@@ -223,38 +184,20 @@ import { fetchList, createUserPortMapping, updateUserPortMapping, updateEnableSt
import { fetchGroupList } from '@/api/securityGroup'
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',
+ name: 'DmainMaping',
directives: {
waves
},
components: {
DropdownTable,
- ButtonPopover,
- loadSelect
+ ButtonPopover
},
data() {
const isPortAvailable = (rule, value, callback) => {
@@ -278,7 +221,6 @@ export default {
current: 1,
size: 10,
domain: null,
- importance: undefined,
title: undefined,
type: undefined,
userId: undefined,
@@ -287,33 +229,32 @@ export default {
isOnline: undefined,
enable: undefined,
description: undefined
-
},
- importanceOptions: [1, 2, 3],
- calendarTypeOptions,
- sortOptions: [{ label: 'ID Ascending', key: '+id' }, { label: 'ID Descending', key: '-id' }],
- statusOptions: ['published', 'draft', 'deleted'],
userList: [],
licenseList: [],
- protocalList: [],
licenseAuthList: [],
- serverPortList: [],
domainName: '',
showReviewer: false,
temp: {
id: undefined,
licenseId: undefined,
licenseName: undefined,
- serverPort: undefined,
clientIp: undefined,
clientPort: undefined,
- protocal: undefined,
proxyResponses: undefined,
proxyTimeoutMs: undefined
},
- selectObj: {
- statusOptions: [{ label: '启用', value: 1 }, { label: '禁用', value: 2 }],
- onlineOptions: [{ label: '在线', value: 1 }, { label: '离线', value: 2 }]
+ statusOptions: {
+ 1: '启用',
+ 2: '禁用',
+ },
+ onlineOptions: {
+ 1: '在线',
+ 2: '离线'
+ },
+ colorOption: {
+ 1: 'success',
+ 2: 'danger'
},
dialogFormVisible: false,
dialogStatus: '',
@@ -330,54 +271,18 @@ export default {
],
clientIp: [{ required: true, message: '请输入客户端IP', trigger: 'blur' }],
clientPort: [{ required: true, message: '请输入客户端端口', trigger: 'blur' }],
- protocal: [{ required: true, message: '请选择协议', trigger: 'blur' }]
- },
- downloadLoading: false,
- countryColumns: [
- { prop: 'userName', label: '用户名', align: 'center' },
- { prop: 'name', label: 'License', align: 'center' }
- ],
- loadServerPortQuery: { //下拉框加载数据请求参数
- page: 1,
- size: 50,
- licenseId: null,
},
more: true,
securityGroupList: []
}
},
- filters: {
- statusName(status) {
- const statusMap = {
- 1: '启用',
- 2: '禁用'
- }
- return statusMap[status]
- },
- isOnlineName(isOnline) {
- const isOnlineMap = {
- 1: '在线',
- 2: '离线'
- }
- return isOnlineMap[isOnline]
- },
- statusFilter(status) {
- const statusMap = {
- 1: 'success',
- 2: 'danger'
- }
- return statusMap[status]
- },
- typeFilter(type) {
- return calendarTypeKeyValue[type]
- }
- },
+ // filters: {
+ // },
created() {
this.getDomainNameBindInfo()
this.getDataList()
this.getLicenseList()
this.getLicenseAuthList()
- this.getProtocalList()
this.fetchSecurityGroupList()
},
methods: {
@@ -412,10 +317,6 @@ export default {
this.domainName = response.data.data
})
},
- getAvailablePortList(licenseId) {
- this.loadServerPortQuery.licenseId = licenseId;
- this.serverPortList = []; //清掉数据
- },
getAllUserList() {
userList().then(response => {
this.userList = response.data.data
@@ -426,11 +327,6 @@ export default {
this.licenseList = response.data.data
})
},
- getProtocalList() {
- protocalList().then(response => {
- this.protocalList = response.data.data
- })
- },
getLicenseAuthList() {
licenseAuthList().then(response => {
this.licenseAuthList = response.data.data
@@ -465,15 +361,12 @@ export default {
id: undefined,
licenseId: undefined,
licenseName: undefined,
- serverPort: undefined,
clientIp: '127.0.0.1',
clientPort: undefined,
userId: undefined,
proxyResponses: undefined,
proxyTimeoutMs: undefined
}
- this.serverPortList = []
- this.loadServerPortQuery.licenseId = null;
this.more = true;
},
handleCreate() {
@@ -502,36 +395,12 @@ export default {
}
})
},
- handleOpenWebPage(row) {
- let url = location.protocol + '//' + location.hostname + ':' + row.serverPort
- if (row.domain) {
- url = location.protocol + '//' + row.domain
- }
- open(url)
- },
- handleUpdate(row) {
- this.temp = Object.assign({}, row) // copy obj
- 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()
- })
- this.getAvailablePortList(row.licenseId)
- },
updateData() {
this.$refs['dataForm'].validate((valid) => {
if (valid) {
const tempData = Object.assign({}, this.temp)
updateUserPortMapping(tempData).then(response => {
if (response.data.code === 0) {
- // this.$message({
- // message: '操作成功',
- // type: 'success'
- // })
this.$notify({
title: '成功',
message: '更新成功',
@@ -545,11 +414,25 @@ export default {
}
})
},
+ handleOpenWebPage(row) {
+ open(location.protocol + '//' + row.domain)
+ },
+ handleUpdate(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.getAvailablePortList(row.id)
this.temp.serverPort = null
}
},
@@ -572,68 +455,6 @@ 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') {
- return parseTime(v[j])
- } else {
- return v[j]
- }
- }))
- },
- // 传入给load-select组件的函数
- loadServerPort({ page = 1, more = false, keyword = "" } = {}) {
- if (this.loadServerPortQuery.licenseId == null || this.loadServerPortQuery.licenseId == '') {
- this.more = false;
- this.$message({
- message: '请先选择License',
- type: 'warning'
- })
- return;
- }
- return new Promise(resolve => {
- this.loadServerPortQuery.page = page;
- this.loadServerPortQuery.keyword = keyword;
- // 访问后端接口API
- availablePortList(this.loadServerPortQuery).then(res => {
- let result = res.data;
- if (more) {
- this.serverPortList = [...this.serverPortList, ...result.data.records];
- } else {
- this.serverPortList = result.data.records;
- }
-
- // this.loadServerPortQuery.page = result.data.current;
- let { total, current, size } = result.data;
- this.more = page * size < total;
- this.loadServerPortQuery.page = current;
- resolve();
- });
- });
- }
}
}
diff --git a/neutrino-proxy-admin/src/views/proxy/portMapping.vue b/neutrino-proxy-admin/src/views/proxy/portMapping.vue
index 597edaf6..29864686 100644
--- a/neutrino-proxy-admin/src/views/proxy/portMapping.vue
+++ b/neutrino-proxy-admin/src/views/proxy/portMapping.vue
@@ -105,9 +105,7 @@
{{ $t('table.edit') }}
{{$t('table.disable')}}
{{ $t('table.enable') }}
-
-
-
+
@@ -122,26 +120,9 @@
-
-
-
-
-
-
-
-
@@ -232,20 +213,6 @@ 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: {
@@ -277,7 +244,6 @@ export default {
listQuery: {
current: 1,
size: 10,
- importance: undefined,
title: undefined,
type: undefined,
userId: undefined,
@@ -288,7 +254,6 @@ export default {
description: undefined
},
- importanceOptions: [1, 2, 3],
calendarTypeOptions,
sortOptions: [{ label: 'ID Ascending', key: '+id' }, { label: 'ID Descending', key: '-id' }],
statusOptions: ['published', 'draft', 'deleted'],
@@ -367,9 +332,6 @@ export default {
}
return statusMap[status]
},
- typeFilter(type) {
- return calendarTypeKeyValue[type]
- }
},
created() {
this.getDomainNameBindInfo()
@@ -571,29 +533,6 @@ 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') {
diff --git a/neutrino-proxy-server/src/main/java/org/dromara/neutrinoproxy/server/controller/DomainController.java b/neutrino-proxy-server/src/main/java/org/dromara/neutrinoproxy/server/controller/DomainController.java
index 4e94c5ea..abf62019 100644
--- a/neutrino-proxy-server/src/main/java/org/dromara/neutrinoproxy/server/controller/DomainController.java
+++ b/neutrino-proxy-server/src/main/java/org/dromara/neutrinoproxy/server/controller/DomainController.java
@@ -37,44 +37,22 @@ public class DomainController {
@Get
@Mapping("/page")
- public PageInfo page(PageQuery pageQuery, PortMappingListReq req) {
+ public PageInfo page(PageQuery pageQuery, DomainMappingDto req) {
ParamCheckUtil.checkNotNull(pageQuery, "pageQuery");
return domainMappingService.page(pageQuery, req);
}
@Post
@Mapping("/modify")
- public PortMappingCreateRes create(PortMappingCreateReq req) {
- ParamCheckUtil.checkNotNull(req, "req");
- ParamCheckUtil.checkNotNull(req.getLicenseId(), "licenseId");
- ParamCheckUtil.checkNotNull(req.getServerPort(), "serverPort");
- ParamCheckUtil.checkNotNull(req.getClientPort(), "clientPort");
- ParamCheckUtil.checkNotEmpty(req.getProtocal(), "protocal");
- ParamCheckUtil.checkMaxLength(req.getDescription(), 50, "描述", "50");
- ParamCheckUtil.checkBytesDesc(req.getUpLimitRate(), "upLimitRate");
- ParamCheckUtil.checkBytesDesc(req.getDownLimitRate(), "downLimitRate");
- if (StringUtils.isBlank(req.getClientIp())) {
- // 没传客户端ip,默认为127.0.0.1
- req.setClientIp("127.0.0.1");
- }
- 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);
- }
- if (null == req.getProxyTimeoutMs()) {
- req.setProxyTimeoutMs(0L);
+ public PortMappingCreateRes modify(DomainMappingDto 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.create(req);
+ return domainMappingService.modify(req);
}
@Get
@@ -86,20 +64,13 @@ public class DomainController {
@Post
@Mapping("/update/enable-status")
public PortMappingUpdateEnableStatusRes updateEnableStatus(PortMappingUpdateEnableStatusReq req) {
- ParamCheckUtil.checkNotNull(req, "req");
- ParamCheckUtil.checkNotNull(req.getId(), "id");
- ParamCheckUtil.checkNotNull(req.getEnable(), "enable");
-
return domainMappingService.updateEnableStatus(req);
}
@Post
- @Mapping("/delete")
- public void delete(PortMappingDeleteReq req) {
- ParamCheckUtil.checkNotNull(req, "req");
- ParamCheckUtil.checkNotNull(req.getId(), "id");
-
- domainMappingService.delete(req.getId());
+ @Mapping("/delete/{id}")
+ public void delete(Integer id) {
+ domainMappingService.delete(id);
}
/**
@@ -109,7 +80,7 @@ public class DomainController {
@Post
@Mapping("/bind/security-group")
public void bindSecurityGroup(PortMappingBindSecurityGroupReq req) {
- domainMappingService.portBindSecurityGroup(req.getId(), req.getSecurityGroupId());
+ domainMappingService.domainBindSecurityGroup(req.getId(), req.getSecurityGroupId());
}
/**
@@ -119,7 +90,7 @@ public class DomainController {
@Post
@Mapping("/unbind/security-group")
public void unbindSecurityGroup(Integer id) {
- domainMappingService.portUnbindSecurityGroup(id);
+ domainMappingService.domainUnbindSecurityGroup(id);
}
diff --git a/neutrino-proxy-server/src/main/java/org/dromara/neutrinoproxy/server/controller/req/proxy/PortMappingUpdateEnableStatusReq.java b/neutrino-proxy-server/src/main/java/org/dromara/neutrinoproxy/server/controller/req/proxy/PortMappingUpdateEnableStatusReq.java
index 0c832fb1..d89b3986 100644
--- a/neutrino-proxy-server/src/main/java/org/dromara/neutrinoproxy/server/controller/req/proxy/PortMappingUpdateEnableStatusReq.java
+++ b/neutrino-proxy-server/src/main/java/org/dromara/neutrinoproxy/server/controller/req/proxy/PortMappingUpdateEnableStatusReq.java
@@ -22,6 +22,7 @@
package org.dromara.neutrinoproxy.server.controller.req.proxy;
import lombok.Data;
+import lombok.NonNull;
/**
* 端口映射更新启用状态请求
@@ -34,10 +35,12 @@ public class PortMappingUpdateEnableStatusReq {
/**
* id
*/
+ @NonNull
private Integer id;
/**
* 启用状态
*/
+ @NonNull
private Integer enable;
}
diff --git a/neutrino-proxy-server/src/main/java/org/dromara/neutrinoproxy/server/dal/DomainMappingMapper.java b/neutrino-proxy-server/src/main/java/org/dromara/neutrinoproxy/server/dal/DomainMappingMapper.java
index bf2c44a3..fff1a211 100644
--- a/neutrino-proxy-server/src/main/java/org/dromara/neutrinoproxy/server/dal/DomainMappingMapper.java
+++ b/neutrino-proxy-server/src/main/java/org/dromara/neutrinoproxy/server/dal/DomainMappingMapper.java
@@ -10,6 +10,7 @@ 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;
@@ -64,9 +65,9 @@ public interface DomainMappingMapper extends BaseMapper {
);
}
- default List findListByServerPort(Integer serverPort) {
+ default List findListByServerPort(String domain) {
return this.selectList(new LambdaQueryWrapper()
- .eq(DomainMappingDO::getServerPort, serverPort)
+ .eq(DomainMappingDO::getDomain, domain)
);
}
@@ -76,37 +77,14 @@ public interface DomainMappingMapper extends BaseMapper {
);
}
- default DomainMappingDO findByLicenseIdAndServerPort(Integer licenseId, Integer serverPort) {
+ default DomainMappingDO findByLicenseIdAndServerPort(Integer licenseId, String domain) {
return this.selectOne(new LambdaQueryWrapper()
.eq(DomainMappingDO::getLicenseId, licenseId)
- .eq(DomainMappingDO::getServerPort, serverPort)
+ .eq(DomainMappingDO::getDomain, domain)
.last("limit 1")
);
}
- default void updateOnlineStatus(Integer licenseId,Integer serverPort, Integer isOnline, Date updateTime) {
- this.update(null, new LambdaUpdateWrapper()
- .eq(DomainMappingDO::getLicenseId, licenseId)
- .eq(DomainMappingDO::getServerPort, serverPort)
- .set(DomainMappingDO::getIsOnline, isOnline)
- .set(DomainMappingDO::getUpdateTime, updateTime)
- );
- }
- default void updateOnlineStatus(Integer licenseId, Integer isOnline, Date updateTime) {
- this.update(null, new LambdaUpdateWrapper()
- .eq(DomainMappingDO::getLicenseId, licenseId)
- .set(DomainMappingDO::getIsOnline, isOnline)
- .set(DomainMappingDO::getUpdateTime, updateTime)
- );
- }
-
- default void updateOnlineStatus(Integer isOnline, Date updateTime) {
- this.update(null, new LambdaUpdateWrapper()
- .set(DomainMappingDO::getIsOnline, isOnline)
- .set(DomainMappingDO::getUpdateTime, updateTime)
- );
- }
-
- List selectDomainMappingByCondition(IPage page, @Param("req") PortMappingListReq req);
+ List selectDomainMappingByCondition(IPage page, @Param("req") DomainMappingDto req);
}
diff --git a/neutrino-proxy-server/src/main/java/org/dromara/neutrinoproxy/server/service/DomainMappingService.java b/neutrino-proxy-server/src/main/java/org/dromara/neutrinoproxy/server/service/DomainMappingService.java
index 9d92a1cb..a791e278 100644
--- a/neutrino-proxy-server/src/main/java/org/dromara/neutrinoproxy/server/service/DomainMappingService.java
+++ b/neutrino-proxy-server/src/main/java/org/dromara/neutrinoproxy/server/service/DomainMappingService.java
@@ -77,13 +77,13 @@ public class DomainMappingService implements LifecycleBean {
/**
* 域名 到 域名解析id的映射
*/
- private final Cache domainToDomainMappingIdCache = CacheUtil.newLRUCache(500, 1000 * 60 * 10);
+ private final Cache domainToDomainMappingIdCache = CacheUtil.newLRUCache(500, 1000 * 60 * 10);
// 域名解析id到licenseId
private final Cache idToLicenseIdCache = CacheUtil.newLRUCache(500, 1000 * 60 * 10);
// 流量限制缓存
private final Cache flowLimitCache = CacheUtil.newLRUCache(500, 1000 * 60 * 5);
- public PageInfo page(PageQuery pageQuery, PortMappingListReq req) {
+ public PageInfo page(PageQuery pageQuery, DomainMappingDto req) {
if (StringUtils.isNotEmpty(req.getDescription())) {
//描述字段为模糊查询,在应用层处理,否则sqlite不支持
req.setDescription("%" + req.getDescription() + "%");
@@ -145,55 +145,42 @@ public class DomainMappingService implements LifecycleBean {
// 临时处理,如果当前用户不是管理员,则操作userId不能为1
ParamCheckUtil.checkExpression(!licenseDO.getUserId().equals(1), ExceptionConstant.NO_PERMISSION_VISIT);
}
- PortPoolDO portPoolDO = portPoolMapper.findByPort(req.getDomain());
- ParamCheckUtil.checkNotNull(portPoolDO, ExceptionConstant.PORT_NOT_EXIST);
+// PortPoolDO portPoolDO = portPoolMapper.findByPort(req.getDomain());
+// ParamCheckUtil.checkNotNull(portPoolDO, ExceptionConstant.PORT_NOT_EXIST);
ParamCheckUtil.checkExpression(null == domainMappingMapper.findByDomain(req.getDomain(), null), ExceptionConstant.PORT_CANNOT_REPEAT_MAPPING, req.getDomain());
ParamCheckUtil.checkExpression(!domainMappingMapper.checkRepeatByDomain(req.getDomain(), null), ExceptionConstant.PORT_MAPPING_SUBDONAME_CONNOT_REPEAT);
Date now = new Date();
- PortMappingDO 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());
- portMappingDO.setUpLimitRate(req.getUpLimitRate());
- portMappingDO.setDownLimitRate(req.getDownLimitRate());
- portMappingDO.setProxyResponses(req.getProxyResponses());
- portMappingDO.setProxyTimeoutMs(req.getProxyTimeoutMs());
- portMappingDO.setDescription(req.getDescription());
- portMappingDO.setIsOnline(OnlineStatusEnum.OFFLINE.getStatus());
- portMappingDO.setEnable(EnableStatusEnum.ENABLE.getStatus());
- portMappingDO.setCreateTime(now);
- portMappingDO.setUpdateTime(now);
- domainMappingMapper.insert(portMappingDO);
+ DomainMappingDO domainMappingDO = (DomainMappingDO) req;
+ domainMappingDO.setIsOnline(OnlineStatusEnum.OFFLINE.getStatus());
+ domainMappingDO.setEnable(EnableStatusEnum.ENABLE.getStatus());
+ domainMappingDO.setCreateTime(now);
+ domainMappingDO.setUpdateTime(now);
+ domainMappingMapper.insert(domainMappingDO);
// 更新VisitorChannel
- visitorChannelService.addVisitorChannelByPortMapping(portMappingDO);
+// visitorChannelService.addVisitorChannelByPortMapping(domainMappingDO);
// 更新域名映射
- if (NetworkProtocolEnum.isHttp(portMappingDO.getProtocal()) && StrUtil.isNotBlank(proxyConfig.getServer().getTcp().getDomainName()) && StrUtil.isNotBlank(portMappingDO.getSubdomain())) {
- ProxyUtil.setSubdomainToServerPort(portMappingDO.getSubdomain(), portMappingDO.getServerPort());
+ if (NetworkProtocolEnum.isHttp(domainMappingDO.getProtocal()) && StrUtil.isNotBlank(proxyConfig.getServer().getTcp().getDomainName()) && StrUtil.isNotBlank(domainMappingDO.getDomain())) {
+// ProxyUtil.setSubdomainToServerPort(domainMappingDO.getDomain(), domainMappingDO.getServerPort());
}
- updateMappingDomainToSecurityGroupMap(portMappingDO.getServerPort(), req.getSecurityGroupId());
+ updateMappingDomainToSecurityGroupMap(domainMappingDO.getDomain(), req.getSecurityGroupId());
// 更新端口到映射的缓存
- domainToDomainMappingIdCache.put(req.getServerPort(), portMappingDO.getId());
+ domainToDomainMappingIdCache.put(req.getDomain(), domainMappingDO.getId());
// 更新端口映射到licenseId的缓存
- idToLicenseIdCache.put(portMappingDO.getId(), portMappingDO.getLicenseId());
+ idToLicenseIdCache.put(domainMappingDO.getId(), domainMappingDO.getLicenseId());
// 刷新流量限制缓存
- refreshFlowLimitCache(portMappingDO.getId(), portMappingDO.getUpLimitRate(), portMappingDO.getDownLimitRate());
+ refreshFlowLimitCache(domainMappingDO.getId(), domainMappingDO.getUpLimitRate(), domainMappingDO.getDownLimitRate());
return new PortMappingCreateRes();
}
-
-
public PortMappingUpdateEnableStatusRes updateEnableStatus(PortMappingUpdateEnableStatusReq req) {
- PortMappingDO portMappingDO = domainMappingMapper.findById(req.getId());
- ParamCheckUtil.checkNotNull(portMappingDO, ExceptionConstant.PORT_MAPPING_NOT_EXIST);
+ DomainMappingDO domainMappingDO = domainMappingMapper.findById(req.getId());
+ ParamCheckUtil.checkNotNull(domainMappingDO, ExceptionConstant.PORT_MAPPING_NOT_EXIST);
- LicenseDO licenseDO = licenseMapper.findById(portMappingDO.getLicenseId());
+ 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);
@@ -202,21 +189,21 @@ public class DomainMappingService implements LifecycleBean {
domainMappingMapper.updateEnableStatus(req.getId(), req.getEnable(), new Date());
// 更新VisitorChannel
- portMappingDO.setEnable(req.getEnable());
+ domainMappingDO.setEnable(req.getEnable());
if (EnableStatusEnum.ENABLE == EnableStatusEnum.of(req.getEnable())) {
- visitorChannelService.addVisitorChannelByPortMapping(portMappingDO);
+// visitorChannelService.addVisitorChannelByPortMapping(domainMappingDO);
} else {
- visitorChannelService.removeVisitorChannelByPortMapping(portMappingDO);
+// visitorChannelService.removeVisitorChannelByPortMapping(domainMappingDO);
}
return new PortMappingUpdateEnableStatusRes();
}
public void delete(Integer id) {
- PortMappingDO portMappingDO = domainMappingMapper.findById(id);
- ParamCheckUtil.checkNotNull(portMappingDO, ExceptionConstant.PORT_MAPPING_NOT_EXIST);
+ DomainMappingDO domainMappingDO = domainMappingMapper.findById(id);
+ ParamCheckUtil.checkNotNull(domainMappingDO, ExceptionConstant.PORT_MAPPING_NOT_EXIST);
- LicenseDO licenseDO = licenseMapper.findById(portMappingDO.getLicenseId());
+ LicenseDO licenseDO = licenseMapper.findById(domainMappingDO.getLicenseId());
if (null != licenseDO && !SystemContextHolder.isAdmin()) {
// 临时处理,如果当前用户不是管理员,则操作userId不能为1
ParamCheckUtil.checkExpression(!licenseDO.getUserId().equals(1), ExceptionConstant.NO_PERMISSION_VISIT);
@@ -225,13 +212,14 @@ public class DomainMappingService implements LifecycleBean {
domainMappingMapper.deleteById(id);
// 更新VisitorChannel
- visitorChannelService.removeVisitorChannelByPortMapping(portMappingDO);
+// visitorChannelService.removeVisitorChannelByPortMapping(domainMappingDO);
+
// 更新域名映射
- if (NetworkProtocolEnum.isHttp(portMappingDO.getProtocal()) && StrUtil.isNotBlank(portMappingDO.getSubdomain())) {
- ProxyUtil.removeSubdomainToServerPort(portMappingDO.getSubdomain());
+ if (NetworkProtocolEnum.isHttp(domainMappingDO.getProtocal()) && StrUtil.isNotBlank(domainMappingDO.getDomain())) {
+ ProxyUtil.removeSubdomainToServerPort(domainMappingDO.getDomain());
}
- updateMappingDomainToSecurityGroupMap(portMappingDO.getServerPort(), null);
+ updateMappingDomainToSecurityGroupMap(domainMappingDO.getDomain(), null);
// 删除id到licenseId的映射
idToLicenseIdCache.remove(id);
@@ -239,26 +227,26 @@ public class DomainMappingService implements LifecycleBean {
flowLimitCache.remove(id);
}
- public void portBindSecurityGroup(Integer portMappingId, Integer groupId) {
- PortMappingDO mappingDO = domainMappingMapper.findById(portMappingId);
+ 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);
- updateMappingDomainToSecurityGroupMap(mappingDO.getServerPort(), groupId);
+ updateMappingDomainToSecurityGroupMap(mappingDO.getDomain(), groupId);
}
- public void portUnbindSecurityGroup(Integer portMappingId) {
- PortMappingDO mappingDO = domainMappingMapper.findById(portMappingId);
+ 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);
- updateMappingDomainToSecurityGroupMap(mappingDO.getServerPort(), null);
+ updateMappingDomainToSecurityGroupMap(mappingDO.getDomain(), null);
}
/**
@@ -267,7 +255,7 @@ public class DomainMappingService implements LifecycleBean {
* @param licenseId
* @return
*/
- public List findEnableListByLicenseId(Integer licenseId) {
+ public List findEnableListByLicenseId(Integer licenseId) {
return domainMappingMapper.findEnableListByLicenseId(licenseId);
}
@@ -286,7 +274,7 @@ public class DomainMappingService implements LifecycleBean {
return;
}
// 服务刚启动,所以默认所有license都是离线状态。解决服务突然关闭,在线状态来不及更新的问题
- domainMappingMapper.updateOnlineStatus(OnlineStatusEnum.OFFLINE.getStatus(), new Date());
+// domainMappingMapper.updateOnlineStatus(OnlineStatusEnum.OFFLINE.getStatus(), new Date());
List allMappingDOList = domainMappingMapper.selectList(Wrappers.lambdaQuery(DomainMappingDO.class));
allMappingDOList.forEach(item -> {
@@ -306,17 +294,17 @@ public class DomainMappingService implements LifecycleBean {
if (StrUtil.isBlank(proxyConfig.getServer().getTcp().getDomainName())) {
return;
}
- List portMappingDOList = allMappingDOList.stream()
+ List portMappingDOList = allMappingDOList.stream()
.filter(item -> NetworkProtocolEnum.HTTP.getDesc().equals(item.getProtocal()) && item.getDomain() != null)
.collect(Collectors.toList());
if (CollectionUtil.isEmpty(portMappingDOList)) {
return;
}
portMappingDOList.forEach(item -> {
- if (StrUtil.isBlank(item.getSubdomain())) {
+ if (StrUtil.isBlank(item.getDomain())) {
return;
}
- ProxyUtil.setSubdomainToServerPort(item.getSubdomain(), item.getServerPort());
+// ProxyUtil.setSubdomainToServerPort(item.getDomain(), item.getServerPort());
});
}
@@ -354,21 +342,18 @@ public class DomainMappingService implements LifecycleBean {
return res;
}
- public Integer getDomainMappingIdByServerPort(Integer serverPort) {
- if (null == serverPort) {
- return null;
- }
- Integer id = domainToDomainMappingIdCache.get(serverPort);
+ public Integer getDomainMappingIdByDomain(String domain) {
+ Integer id = domainToDomainMappingIdCache.get(domain);
if (null != id) {
return id;
}
- List domainMappingDOList = domainMappingMapper.findListByServerPort(serverPort);
+ List domainMappingDOList = domainMappingMapper.findListByServerPort(domain);
// 不存在 或者 有多条记录,都不处理
if (CollectionUtils.isEmpty(domainMappingDOList) || domainMappingDOList.size() > 1) {
return null;
}
id = domainMappingDOList.get(0).getId();
- domainToDomainMappingIdCache.put(serverPort, id);
+ domainToDomainMappingIdCache.put(domain, id);
return id;
}
@@ -384,8 +369,8 @@ public class DomainMappingService implements LifecycleBean {
return licenseId;
}
- public FlowLimitBO getFlowLimitByServerPort(Integer serverPort) {
- Integer id = getPortMappingIdByServerPort(serverPort);
+ public FlowLimitBO getFlowLimitByServerPort(String domain) {
+ Integer id = getDomainMappingIdByDomain(domain);
if (null == id) {
return null;
}
@@ -399,12 +384,12 @@ public class DomainMappingService implements LifecycleBean {
return res;
}
- private void updateMappingDomainToSecurityGroupMap(Integer serverPort, Integer securityGroupId) {
+ private void updateMappingDomainToSecurityGroupMap(String domain, Integer securityGroupId) {
if (securityGroupId == null || securityGroupId == 0) {
- mappingDomainToSecurityGroupMap.remove(serverPort);
+ mappingDomainToSecurityGroupMap.remove(domain);
return;
}
- mappingDomainToSecurityGroupMap.put(serverPort, securityGroupId);
+ mappingDomainToSecurityGroupMap.put(domain, securityGroupId);
}
@Override
@@ -417,7 +402,7 @@ public class DomainMappingService implements LifecycleBean {
*/
@Override
public void stop() throws Throwable {
- domainMappingMapper.updateOnlineStatus(OnlineStatusEnum.OFFLINE.getStatus(), new Date());
+// domainMappingMapper.updateOnlineStatus(OnlineStatusEnum.OFFLINE.getStatus(), new Date());
}
public DomainMappingDto one(Integer id) {
diff --git a/neutrino-proxy-server/src/main/resources/mapper/DomainMappingMapper.xml b/neutrino-proxy-server/src/main/resources/mapper/DomainMappingMapper.xml
index 8d169bdd..912fb5cb 100644
--- a/neutrino-proxy-server/src/main/resources/mapper/DomainMappingMapper.xml
+++ b/neutrino-proxy-server/src/main/resources/mapper/DomainMappingMapper.xml
@@ -1,10 +1,10 @@
-
+
-