mirror of
https://github.com/GravitLauncher/Launcher
synced 2025-01-09 00:59:44 +03:00
[FEATURE} IP Forwarding
This commit is contained in:
parent
bb04ed849c
commit
a66d7a7164
6 changed files with 57 additions and 2 deletions
|
@ -275,6 +275,7 @@ public class LauncherConf
|
|||
public class NettyConfig {
|
||||
public boolean fileServerEnabled;
|
||||
public boolean sendExceptionEnabled;
|
||||
public boolean ipForwarding;
|
||||
public String launcherURL;
|
||||
public String downloadURL;
|
||||
public String launcherEXEURL;
|
||||
|
|
|
@ -40,13 +40,15 @@ public LauncherNettyServer() {
|
|||
@Override
|
||||
public void initChannel(NioSocketChannel ch) {
|
||||
ChannelPipeline pipeline = ch.pipeline();
|
||||
NettyConnectContext context = new NettyConnectContext();
|
||||
//p.addLast(new LoggingHandler(LogLevel.INFO));
|
||||
pipeline.addLast(new HttpServerCodec());
|
||||
pipeline.addLast(new HttpObjectAggregator(65536));
|
||||
pipeline.addLast(new WebSocketServerCompressionHandler());
|
||||
pipeline.addLast(new WebSocketServerProtocolHandler(WEBSOCKET_PATH, null, true));
|
||||
if (LaunchServer.server.config.netty.fileServerEnabled) pipeline.addLast(new FileServerHandler(LaunchServer.server.updatesDir, true));
|
||||
pipeline.addLast(new WebSocketFrameHandler());
|
||||
if (LaunchServer.server.config.netty.ipForwarding) pipeline.addLast(new NettyIpForwardHandler(context));
|
||||
pipeline.addLast(new WebSocketFrameHandler(context));
|
||||
}
|
||||
});
|
||||
if(config.proxy != null && config.proxy.enabled)
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
package ru.gravit.launchserver.websocket;
|
||||
|
||||
public class NettyConnectContext {
|
||||
public String ip = null;
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package ru.gravit.launchserver.websocket;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelInboundHandler;
|
||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||
import io.netty.handler.codec.http.DefaultHttpRequest;
|
||||
import io.netty.handler.codec.http.HttpHeaders;
|
||||
import ru.gravit.utils.helper.LogHelper;
|
||||
|
||||
public class NettyIpForwardHandler extends ChannelInboundHandlerAdapter {
|
||||
private NettyConnectContext context;
|
||||
|
||||
public NettyIpForwardHandler(NettyConnectContext context) {
|
||||
super();
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
|
||||
super.channelRead(ctx, msg);
|
||||
if(context.ip != null) return;
|
||||
if(msg instanceof DefaultHttpRequest)
|
||||
{
|
||||
DefaultHttpRequest http = (DefaultHttpRequest) msg;
|
||||
HttpHeaders headers = http.headers();
|
||||
String realIP = null;
|
||||
if(headers.contains("X-Forwarded-For"))
|
||||
{
|
||||
realIP = headers.get("X-Forwarded-For");
|
||||
}
|
||||
if(headers.contains("X-Real-IP"))
|
||||
{
|
||||
realIP = headers.get("X-Real-IP");
|
||||
}
|
||||
if(realIP != null) {
|
||||
LogHelper.dev("Real IP address %s", realIP);
|
||||
context.ip = realIP;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -100,7 +100,7 @@ public void run() {
|
|||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}*/
|
||||
LogHelper.info("Starting server socket thread");
|
||||
LogHelper.info("Starting netty server socket thread");
|
||||
//SSLEngine engine = sc.createSSLEngine();
|
||||
//engine.setUseClientMode(false);
|
||||
WebSocketFrameHandler.server = LaunchServer.server;
|
||||
|
|
|
@ -17,6 +17,12 @@ public class WebSocketFrameHandler extends SimpleChannelInboundHandler<WebSocket
|
|||
public static LaunchServer server;
|
||||
public static GsonBuilder builder = new GsonBuilder();
|
||||
public static WebSocketService service = new WebSocketService(new DefaultChannelGroup(GlobalEventExecutor.INSTANCE), LaunchServer.server, builder);
|
||||
public NettyConnectContext context;
|
||||
|
||||
public WebSocketFrameHandler(NettyConnectContext context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
private Client client;
|
||||
|
||||
static {
|
||||
|
|
Loading…
Reference in a new issue