mirror of
https://github.com/Sagit-chu/flvx.git
synced 2026-09-29 16:06:36 +08:00
修复ui 添加gost静默http服务
This commit is contained in:
@@ -29,9 +29,13 @@ public class TunnelDto {
|
||||
private Long outNodeId;
|
||||
|
||||
// 出口端口开始,当type=1时可以为空,会自动设置为入口端口
|
||||
@Min(value = 0, message = "出口端口开始必须大于等于1")
|
||||
@Max(value = 65535, message = "出口端口开始不能超过65535")
|
||||
private Integer outIpSta;
|
||||
|
||||
// 出口端口结束,当type=1时可以为空,会自动设置为入口端口
|
||||
@Min(value = 0, message = "出口端口结束必须大于等于1")
|
||||
@Max(value = 65535, message = "出口端口结束不能超过65535")
|
||||
private Integer outIpEnd;
|
||||
|
||||
@NotNull(message = "隧道类型不能为空")
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.admin.common.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Min;
|
||||
import javax.validation.constraints.Max;
|
||||
|
||||
@Data
|
||||
public class TunnelUpdateDto {
|
||||
|
||||
@NotNull(message = "隧道ID不能为空")
|
||||
private Long id;
|
||||
|
||||
@NotBlank(message = "隧道名称不能为空")
|
||||
private String name;
|
||||
|
||||
@NotNull(message = "流量计算类型不能为空")
|
||||
private Integer flow;
|
||||
|
||||
@NotNull(message = "入口端口开始不能为空")
|
||||
@Min(value = 1, message = "入口端口开始必须大于0")
|
||||
@Max(value = 65535, message = "入口端口开始不能超过65535")
|
||||
private Integer inPortSta;
|
||||
|
||||
@NotNull(message = "入口端口结束不能为空")
|
||||
@Min(value = 1, message = "入口端口结束必须大于0")
|
||||
@Max(value = 65535, message = "入口端口结束不能超过65535")
|
||||
private Integer inPortEnd;
|
||||
|
||||
// 出口端口开始(对于隧道转发类型的隧道)
|
||||
@Min(value = 1, message = "出口端口开始必须大于等于0")
|
||||
@Max(value = 65535, message = "出口端口开始不能超过65535")
|
||||
private Integer outIpSta;
|
||||
|
||||
// 出口端口结束(对于隧道转发类型的隧道)
|
||||
@Min(value = 1, message = "出口端口结束必须大于等于0")
|
||||
@Max(value = 65535, message = "出口端口结束不能超过65535")
|
||||
private Integer outIpEnd;
|
||||
}
|
||||
@@ -9,8 +9,7 @@ import javax.validation.constraints.Min;
|
||||
@Data
|
||||
public class UserDto {
|
||||
|
||||
@NotBlank(message = "姓名不能为空")
|
||||
private String name;
|
||||
private String name = "user";
|
||||
|
||||
@NotBlank(message = "用户名不能为空")
|
||||
private String user;
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.admin.common.aop.LogAnnotation;
|
||||
import com.admin.common.annotation.RequireRole;
|
||||
import com.admin.common.dto.PageDto;
|
||||
import com.admin.common.dto.TunnelDto;
|
||||
import com.admin.common.dto.TunnelUpdateDto;
|
||||
|
||||
import com.admin.common.dto.UserTunnelDto;
|
||||
import com.admin.common.dto.UserTunnelQueryDto;
|
||||
@@ -50,7 +51,12 @@ public class TunnelController extends BaseController {
|
||||
return tunnelService.getAllTunnels();
|
||||
}
|
||||
|
||||
|
||||
@LogAnnotation
|
||||
@RequireRole
|
||||
@PostMapping("/update")
|
||||
public R update(@Validated @RequestBody TunnelUpdateDto tunnelUpdateDto) {
|
||||
return tunnelService.updateTunnel(tunnelUpdateDto);
|
||||
}
|
||||
|
||||
@LogAnnotation
|
||||
@RequireRole
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.admin.service;
|
||||
|
||||
import com.admin.common.dto.PageDto;
|
||||
import com.admin.common.dto.TunnelDto;
|
||||
import com.admin.common.dto.TunnelUpdateDto;
|
||||
|
||||
import com.admin.common.lang.R;
|
||||
import com.admin.entity.Tunnel;
|
||||
@@ -30,7 +31,12 @@ public interface TunnelService extends IService<Tunnel> {
|
||||
*/
|
||||
R getAllTunnels();
|
||||
|
||||
|
||||
/**
|
||||
* 更新隧道(只允许修改名称、流量计费、端口范围)
|
||||
* @param tunnelUpdateDto 更新数据
|
||||
* @return 结果
|
||||
*/
|
||||
R updateTunnel(TunnelUpdateDto tunnelUpdateDto);
|
||||
|
||||
/**
|
||||
* 删除隧道
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.admin.service.impl;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.admin.common.dto.TunnelDto;
|
||||
import com.admin.common.dto.TunnelListDto;
|
||||
import com.admin.common.dto.TunnelUpdateDto;
|
||||
|
||||
import com.admin.common.lang.R;
|
||||
import com.admin.common.utils.JwtUtil;
|
||||
@@ -110,22 +111,30 @@ public class TunnelServiceImpl extends ServiceImpl<TunnelMapper, Tunnel> impleme
|
||||
return nameValidationResult;
|
||||
}
|
||||
|
||||
// 2. 验证入口节点和端口
|
||||
// 2. 验证隧道转发类型的必要参数
|
||||
if (tunnelDto.getType() == TUNNEL_TYPE_TUNNEL_FORWARD) {
|
||||
R tunnelForwardValidationResult = validateTunnelForwardCreate(tunnelDto);
|
||||
if (tunnelForwardValidationResult.getCode() != 0) {
|
||||
return tunnelForwardValidationResult;
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 验证入口节点和端口
|
||||
NodeValidationResult inNodeValidation = validateInNode(tunnelDto);
|
||||
if (inNodeValidation.isHasError()) {
|
||||
return R.err(inNodeValidation.getErrorMessage());
|
||||
}
|
||||
|
||||
// 3. 构建隧道实体
|
||||
// 4. 构建隧道实体
|
||||
Tunnel tunnel = buildTunnelEntity(tunnelDto, inNodeValidation.getNode());
|
||||
|
||||
// 4. 根据隧道类型设置出口参数
|
||||
// 5. 根据隧道类型设置出口参数
|
||||
R outNodeSetupResult = setupOutNodeParameters(tunnel, tunnelDto);
|
||||
if (outNodeSetupResult.getCode() != 0) {
|
||||
return outNodeSetupResult;
|
||||
}
|
||||
|
||||
// 5. 设置默认属性并保存
|
||||
// 6. 设置默认属性并保存
|
||||
setDefaultTunnelProperties(tunnel);
|
||||
boolean result = this.save(tunnel);
|
||||
|
||||
@@ -143,6 +152,60 @@ public class TunnelServiceImpl extends ServiceImpl<TunnelMapper, Tunnel> impleme
|
||||
return R.ok(tunnelList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新隧道(只允许修改名称、流量计费、端口范围)
|
||||
*
|
||||
* @param tunnelUpdateDto 更新数据传输对象
|
||||
* @return 更新结果响应
|
||||
*/
|
||||
@Override
|
||||
public R updateTunnel(TunnelUpdateDto tunnelUpdateDto) {
|
||||
// 1. 验证隧道是否存在
|
||||
Tunnel existingTunnel = this.getById(tunnelUpdateDto.getId());
|
||||
if (existingTunnel == null) {
|
||||
return R.err(ERROR_TUNNEL_NOT_FOUND);
|
||||
}
|
||||
|
||||
// 2. 验证隧道名称唯一性(排除自身)
|
||||
R nameValidationResult = validateTunnelNameUniquenessForUpdate(
|
||||
tunnelUpdateDto.getName(), tunnelUpdateDto.getId());
|
||||
if (nameValidationResult.getCode() != 0) {
|
||||
return nameValidationResult;
|
||||
}
|
||||
|
||||
// 3. 验证端口范围
|
||||
R portValidationResult = validatePortRanges(tunnelUpdateDto);
|
||||
if (portValidationResult.getCode() != 0) {
|
||||
return portValidationResult;
|
||||
}
|
||||
|
||||
// 4. 验证隧道转发类型的出口端口
|
||||
if (existingTunnel.getType() == TUNNEL_TYPE_TUNNEL_FORWARD) {
|
||||
R tunnelTypeValidationResult = validateTunnelForwardUpdate(tunnelUpdateDto);
|
||||
if (tunnelTypeValidationResult.getCode() != 0) {
|
||||
return tunnelTypeValidationResult;
|
||||
}
|
||||
}
|
||||
|
||||
// 5. 更新允许修改的字段
|
||||
existingTunnel.setName(tunnelUpdateDto.getName());
|
||||
existingTunnel.setFlow(tunnelUpdateDto.getFlow());
|
||||
existingTunnel.setInPortSta(tunnelUpdateDto.getInPortSta());
|
||||
existingTunnel.setInPortEnd(tunnelUpdateDto.getInPortEnd());
|
||||
|
||||
if (existingTunnel.getType() == TUNNEL_TYPE_TUNNEL_FORWARD) {
|
||||
existingTunnel.setOutIpSta(tunnelUpdateDto.getOutIpSta());
|
||||
existingTunnel.setOutIpEnd(tunnelUpdateDto.getOutIpEnd());
|
||||
}else{
|
||||
existingTunnel.setOutIpSta(tunnelUpdateDto.getInPortSta());
|
||||
existingTunnel.setOutIpEnd(tunnelUpdateDto.getInPortEnd());
|
||||
}
|
||||
|
||||
// 6. 保存更新
|
||||
boolean result = this.updateById(existingTunnel);
|
||||
return result ? R.ok("隧道更新成功") : R.err("隧道更新失败");
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除隧道
|
||||
* 删除前会检查是否有转发或用户权限在使用该隧道
|
||||
@@ -213,6 +276,91 @@ public class TunnelServiceImpl extends ServiceImpl<TunnelMapper, Tunnel> impleme
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证隧道名称唯一性(更新时使用,排除自身)
|
||||
*
|
||||
* @param tunnelName 隧道名称
|
||||
* @param tunnelId 隧道ID(要排除的隧道)
|
||||
* @return 验证结果响应
|
||||
*/
|
||||
private R validateTunnelNameUniquenessForUpdate(String tunnelName, Long tunnelId) {
|
||||
QueryWrapper<Tunnel> query = new QueryWrapper<>();
|
||||
query.eq("name", tunnelName);
|
||||
query.ne("id", tunnelId); // 排除自身
|
||||
Tunnel existTunnel = this.getOne(query);
|
||||
if (existTunnel != null) {
|
||||
return R.err(ERROR_TUNNEL_NAME_EXISTS);
|
||||
}
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证端口范围
|
||||
*
|
||||
* @param tunnelUpdateDto 更新数据传输对象
|
||||
* @return 验证结果响应
|
||||
*/
|
||||
private R validatePortRanges(TunnelUpdateDto tunnelUpdateDto) {
|
||||
// 验证入口端口范围
|
||||
if (tunnelUpdateDto.getInPortSta() > tunnelUpdateDto.getInPortEnd()) {
|
||||
return R.err(ERROR_IN_PORT_RANGE_INVALID);
|
||||
}
|
||||
|
||||
// 验证出口端口范围(如果有的话)
|
||||
if (tunnelUpdateDto.getOutIpSta() != null && tunnelUpdateDto.getOutIpEnd() != null) {
|
||||
if (tunnelUpdateDto.getOutIpSta() > tunnelUpdateDto.getOutIpEnd()) {
|
||||
return R.err(ERROR_OUT_PORT_RANGE_INVALID);
|
||||
}
|
||||
}
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证隧道转发更新时的出口端口
|
||||
*
|
||||
* @param tunnelUpdateDto 更新数据传输对象
|
||||
* @return 验证结果响应
|
||||
*/
|
||||
private R validateTunnelForwardUpdate(TunnelUpdateDto tunnelUpdateDto) {
|
||||
// 验证出口端口参数不能为空
|
||||
if (tunnelUpdateDto.getOutIpSta() == null || tunnelUpdateDto.getOutIpEnd() == null) {
|
||||
return R.err(ERROR_OUT_PORT_REQUIRED);
|
||||
}
|
||||
|
||||
// 验证出口端口范围
|
||||
if (tunnelUpdateDto.getOutIpSta() > tunnelUpdateDto.getOutIpEnd()) {
|
||||
return R.err(ERROR_OUT_PORT_RANGE_INVALID);
|
||||
}
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证隧道转发创建时的必要参数
|
||||
*
|
||||
* @param tunnelDto 隧道创建数据传输对象
|
||||
* @return 验证结果响应
|
||||
*/
|
||||
private R validateTunnelForwardCreate(TunnelDto tunnelDto) {
|
||||
// 验证出口节点不能为空
|
||||
if (tunnelDto.getOutNodeId() == null) {
|
||||
return R.err(ERROR_OUT_NODE_REQUIRED);
|
||||
}
|
||||
|
||||
// 验证出口端口参数不能为空
|
||||
if (tunnelDto.getOutIpSta() == null || tunnelDto.getOutIpEnd() == null) {
|
||||
return R.err(ERROR_OUT_PORT_REQUIRED);
|
||||
}
|
||||
|
||||
// 验证出口端口范围
|
||||
if (tunnelDto.getOutIpSta() > tunnelDto.getOutIpEnd()) {
|
||||
return R.err(ERROR_OUT_PORT_RANGE_INVALID);
|
||||
}
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证入口节点和端口
|
||||
*
|
||||
|
||||
@@ -151,7 +151,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
||||
|
||||
return R.ok(MapUtil.builder()
|
||||
.put(LOGIN_TOKEN_FIELD, token)
|
||||
.put(LOGIN_NAME_FIELD, user.getName())
|
||||
.put(LOGIN_NAME_FIELD, user.getUser())
|
||||
.put(LOGIN_ROLE_ID_FIELD, user.getRoleId())
|
||||
.put(LOGIN_REQUIRE_PASSWORD_CHANGE_FIELD, requirePasswordChange)
|
||||
.build());
|
||||
|
||||
Reference in New Issue
Block a user