|
|
@ -45,12 +45,12 @@ public class RouteConfig { |
|
|
|
/** 管理员不能同时在多个地方登录 */ |
|
|
|
/** 管理员不能同时在多个地方登录 */ |
|
|
|
private static String token; |
|
|
|
private static String token; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 初始化 |
|
|
|
|
|
|
|
*/ |
|
|
|
public static void init() { |
|
|
|
public static void init() { |
|
|
|
|
|
|
|
|
|
|
|
ApiRoute.addMiddleware(new RequestMiddleware() { |
|
|
|
ApiRoute.addMiddleware((request)->{ |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void preRequest(FullHttpRequest request) { |
|
|
|
|
|
|
|
String cookieHeader = request.headers().get(HttpHeaderNames.COOKIE); |
|
|
|
String cookieHeader = request.headers().get(HttpHeaderNames.COOKIE); |
|
|
|
boolean authenticated = false; |
|
|
|
boolean authenticated = false; |
|
|
|
if (cookieHeader != null) { |
|
|
|
if (cookieHeader != null) { |
|
|
@ -72,38 +72,29 @@ public class RouteConfig { |
|
|
|
authenticated = true; |
|
|
|
authenticated = true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!LOGIN_URL.equals(request.uri()) && !authenticated) { |
|
|
|
if (!LOGIN_URL.equals(request.uri()) && !authenticated) { |
|
|
|
throw new ContextException(ResponseInfo.CODE_UNAUTHORIZED); |
|
|
|
throw new ContextException(ResponseInfo.CODE_UNAUTHORIZED); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
logger.info("handle request for api {}", request.uri()); |
|
|
|
logger.info("handle request for api {}", request.uri()); |
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// 获取配置详细信息
|
|
|
|
// 获取配置详细信息
|
|
|
|
ApiRoute.addRoute("/config/detail", new RequestHandler() { |
|
|
|
ApiRoute.addRoute("/config/detail",(request)->{ |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public ResponseInfo request(FullHttpRequest request) { |
|
|
|
|
|
|
|
List<Client> clients = ProxyConfig.getInstance().getClients(); |
|
|
|
List<Client> clients = ProxyConfig.getInstance().getClients(); |
|
|
|
for (Client client : clients) { |
|
|
|
clients.forEach(client -> { |
|
|
|
Channel channel = ProxyChannelManager.getCmdChannel(client.getClientKey()); |
|
|
|
Channel channel = ProxyChannelManager.getCmdChannel(client.getClientKey()); |
|
|
|
if (channel != null) { |
|
|
|
if (channel != null) { |
|
|
|
client.setStatus(1);// online
|
|
|
|
client.setStatus(1);// online
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
client.setStatus(0);// offline
|
|
|
|
client.setStatus(0);// offline
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
return ResponseInfo.build(ProxyConfig.getInstance().getClients()); |
|
|
|
return ResponseInfo.build(ProxyConfig.getInstance().getClients()); |
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// 更新配置
|
|
|
|
// 更新配置
|
|
|
|
ApiRoute.addRoute("/config/update", new RequestHandler() { |
|
|
|
ApiRoute.addRoute("/config/update",(request)->{ |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public ResponseInfo request(FullHttpRequest request) { |
|
|
|
|
|
|
|
byte[] buf = new byte[request.content().readableBytes()]; |
|
|
|
byte[] buf = new byte[request.content().readableBytes()]; |
|
|
|
request.content().readBytes(buf); |
|
|
|
request.content().readBytes(buf); |
|
|
|
String config = new String(buf, Charset.forName("UTF-8")); |
|
|
|
String config = new String(buf, Charset.forName("UTF-8")); |
|
|
@ -121,13 +112,9 @@ public class RouteConfig { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return ResponseInfo.build(ResponseInfo.CODE_OK, "success"); |
|
|
|
return ResponseInfo.build(ResponseInfo.CODE_OK, "success"); |
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
ApiRoute.addRoute("/login", new RequestHandler() { |
|
|
|
ApiRoute.addRoute("/login",(request)->{ |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public ResponseInfo request(FullHttpRequest request) { |
|
|
|
|
|
|
|
byte[] buf = new byte[request.content().readableBytes()]; |
|
|
|
byte[] buf = new byte[request.content().readableBytes()]; |
|
|
|
request.content().readBytes(buf); |
|
|
|
request.content().readBytes(buf); |
|
|
|
String config = new String(buf); |
|
|
|
String config = new String(buf); |
|
|
@ -149,33 +136,23 @@ public class RouteConfig { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return ResponseInfo.build(ResponseInfo.CODE_INVILID_PARAMS, "Error username or password"); |
|
|
|
return ResponseInfo.build(ResponseInfo.CODE_INVILID_PARAMS, "Error username or password"); |
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ApiRoute.addRoute("/logout", new RequestHandler() { |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
//退出登陆
|
|
|
|
public ResponseInfo request(FullHttpRequest request) { |
|
|
|
ApiRoute.addRoute("/logout",(request)->{ |
|
|
|
token = null; |
|
|
|
token = null; |
|
|
|
return ResponseInfo.build(ResponseInfo.CODE_OK, "success"); |
|
|
|
return ResponseInfo.build(ResponseInfo.CODE_OK, "success"); |
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
ApiRoute.addRoute("/metrics/get", new RequestHandler() { |
|
|
|
ApiRoute.addRoute("/metrics/get",(request)->{ |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public ResponseInfo request(FullHttpRequest request) { |
|
|
|
|
|
|
|
return ResponseInfo.build(MetricsCollector.getAllMetrics()); |
|
|
|
return ResponseInfo.build(MetricsCollector.getAllMetrics()); |
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
ApiRoute.addRoute("/metrics/getandreset", new RequestHandler() { |
|
|
|
ApiRoute.addRoute("/metrics/getandreset",(request)->{ |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public ResponseInfo request(FullHttpRequest request) { |
|
|
|
|
|
|
|
return ResponseInfo.build(MetricsCollector.getAndResetAllMetrics()); |
|
|
|
return ResponseInfo.build(MetricsCollector.getAndResetAllMetrics()); |
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|