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