mirror of
https://github.com/Sagit-chu/flvx.git
synced 2026-09-29 07:56:37 +08:00
添加屏蔽协议到面板,免去手动操作
This commit is contained in:
@@ -31,4 +31,8 @@ public class NodeUpdateDto {
|
||||
@Min(value = 1, message = "结束端口必须大于0")
|
||||
@Max(value = 65535, message = "结束端口不能超过65535")
|
||||
private Integer portEnd;
|
||||
|
||||
private Integer http;
|
||||
private Integer tls;
|
||||
private Integer socks;
|
||||
}
|
||||
@@ -224,6 +224,9 @@ public class WebSocketServer extends TextWebSocketHandler {
|
||||
// 客户端节点连接
|
||||
Long nodeId = Long.valueOf(id);
|
||||
String version = (String) session.getAttributes().get("nodeVersion");
|
||||
String http = (String) session.getAttributes().get("http");
|
||||
String tls = (String) session.getAttributes().get("tls");
|
||||
String socks = (String) session.getAttributes().get("socks");
|
||||
|
||||
log.info("节点 {} 尝试连接,开始处理连接逻辑", nodeId);
|
||||
|
||||
@@ -256,6 +259,16 @@ public class WebSocketServer extends TextWebSocketHandler {
|
||||
if (version != null) {
|
||||
node.setVersion(version);
|
||||
}
|
||||
if (http != null) {
|
||||
node.setHttp(Integer.parseInt(http));
|
||||
}
|
||||
if (tls != null) {
|
||||
node.setTls(Integer.parseInt(tls));
|
||||
}
|
||||
if (socks != null) {
|
||||
node.setSocks(Integer.parseInt(socks));
|
||||
}
|
||||
|
||||
boolean updateResult = nodeService.updateById(node);
|
||||
|
||||
if (updateResult) {
|
||||
|
||||
@@ -38,6 +38,9 @@ public class WebSocketInterceptor extends HttpSessionHandshakeInterceptor {
|
||||
String secret = serverHttpRequest.getServletRequest().getParameter("secret");
|
||||
String type = serverHttpRequest.getServletRequest().getParameter("type");
|
||||
String version = serverHttpRequest.getServletRequest().getParameter("version");
|
||||
String http = serverHttpRequest.getServletRequest().getParameter("http");
|
||||
String tls = serverHttpRequest.getServletRequest().getParameter("tls");
|
||||
String socks = serverHttpRequest.getServletRequest().getParameter("socks");
|
||||
if (Objects.equals(type, "1")) {
|
||||
System.out.println("type: " + type + " - version: " + version + " - secret: " + secret + " - IP: " + getClientIp(request));
|
||||
Node node = nodeService.getOne(new QueryWrapper<Node>().eq("secret", secret));
|
||||
@@ -48,6 +51,9 @@ public class WebSocketInterceptor extends HttpSessionHandshakeInterceptor {
|
||||
attributes.put("id", node.getId());
|
||||
attributes.put("nodeSecret", secret);
|
||||
attributes.put("nodeVersion", version);
|
||||
attributes.put("http",http);
|
||||
attributes.put("tls",tls);
|
||||
attributes.put("socks",socks);
|
||||
log.info("节点 {} 通过验证,版本: {}", node.getId(), version);
|
||||
// 不在这里更新状态,等到连接建立后再统一更新
|
||||
}else {
|
||||
|
||||
@@ -32,4 +32,10 @@ public class Node extends BaseEntity {
|
||||
|
||||
private Integer portEnd;
|
||||
|
||||
private Integer http;
|
||||
|
||||
private Integer tls;
|
||||
|
||||
private Integer socks;
|
||||
|
||||
}
|
||||
|
||||
@@ -2,9 +2,11 @@ package com.admin.service.impl;
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.admin.common.dto.GostDto;
|
||||
import com.admin.common.dto.NodeDto;
|
||||
import com.admin.common.dto.NodeUpdateDto;
|
||||
import com.admin.common.lang.R;
|
||||
import com.admin.common.utils.WebSocketServer;
|
||||
import com.admin.entity.Node;
|
||||
import com.admin.entity.Tunnel;
|
||||
import com.admin.entity.ViteConfig;
|
||||
@@ -13,6 +15,7 @@ import com.admin.mapper.TunnelMapper;
|
||||
import com.admin.service.NodeService;
|
||||
import com.admin.service.TunnelService;
|
||||
import com.admin.service.ViteConfigService;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
@@ -22,6 +25,8 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
|
||||
/**
|
||||
@@ -114,10 +119,34 @@ public class NodeServiceImpl extends ServiceImpl<NodeMapper, Node> implements No
|
||||
@Override
|
||||
public R updateNode(NodeUpdateDto nodeUpdateDto) {
|
||||
// 1. 验证节点是否存在
|
||||
if (!isNodeExists(nodeUpdateDto.getId())) {
|
||||
Node node = this.getById(nodeUpdateDto.getId());
|
||||
if (node == null) {
|
||||
return R.err(ERROR_NODE_NOT_FOUND);
|
||||
}
|
||||
|
||||
//1.1 如果节点在线 且传入更新的 http/tls/socks 任意一项与数据库不一致,则通过 WS 通知节点更新设置
|
||||
boolean online = node.getStatus() != null && node.getStatus() == 1;
|
||||
Integer newHttp = nodeUpdateDto.getHttp();
|
||||
Integer newTls = nodeUpdateDto.getTls();
|
||||
Integer newSocks = nodeUpdateDto.getSocks();
|
||||
|
||||
boolean httpChanged = newHttp != null && !newHttp.equals(node.getHttp());
|
||||
boolean tlsChanged = newTls != null && !newTls.equals(node.getTls());
|
||||
boolean socksChanged = newSocks != null && !newSocks.equals(node.getSocks());
|
||||
|
||||
if (online && (httpChanged || tlsChanged || socksChanged)) {
|
||||
JSONObject req = new JSONObject();
|
||||
req.put("http", newHttp);
|
||||
req.put("tls", newTls);
|
||||
req.put("socks", newSocks);
|
||||
|
||||
GostDto gostResult = WebSocketServer.send_msg(node.getId(), req, "SetProtocol");
|
||||
if (!Objects.equals(gostResult.getMsg(), "OK")){
|
||||
return R.err(gostResult.getMsg());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 2. 构建更新对象并执行更新
|
||||
Node updateNode = buildUpdateNode(nodeUpdateDto);
|
||||
boolean result = this.updateById(updateNode);
|
||||
@@ -153,7 +182,8 @@ public class NodeServiceImpl extends ServiceImpl<NodeMapper, Node> implements No
|
||||
@Override
|
||||
public R deleteNode(Long id) {
|
||||
// 1. 验证节点是否存在
|
||||
if (!isNodeExists(id)) {
|
||||
Node node = this.getById(id);
|
||||
if (node == null) {
|
||||
return R.err(ERROR_NODE_NOT_FOUND);
|
||||
}
|
||||
|
||||
@@ -225,7 +255,9 @@ public class NodeServiceImpl extends ServiceImpl<NodeMapper, Node> implements No
|
||||
node.setServerIp(nodeUpdateDto.getServerIp());
|
||||
node.setPortSta(nodeUpdateDto.getPortSta());
|
||||
node.setPortEnd(nodeUpdateDto.getPortEnd());
|
||||
|
||||
node.setHttp(nodeUpdateDto.getHttp());
|
||||
node.setTls(nodeUpdateDto.getTls());
|
||||
node.setSocks(nodeUpdateDto.getSocks());
|
||||
// 验证端口范围
|
||||
validatePortRange(node.getPortSta(), node.getPortEnd());
|
||||
|
||||
@@ -242,15 +274,6 @@ public class NodeServiceImpl extends ServiceImpl<NodeMapper, Node> implements No
|
||||
nodeList.forEach(node -> node.setSecret(null));
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查节点是否存在
|
||||
*
|
||||
* @param nodeId 节点ID
|
||||
* @return 节点是否存在
|
||||
*/
|
||||
private boolean isNodeExists(Long nodeId) {
|
||||
return this.getById(nodeId) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查节点使用情况
|
||||
|
||||
Reference in New Issue
Block a user