added config to set name of the IP forward header

This commit is contained in:
LAX1DUDE 2022-08-27 01:12:22 -07:00
parent d42e64cd75
commit 42f9dcc250
3 changed files with 14 additions and 4 deletions

View File

@ -160,8 +160,8 @@ public class EaglerSPRelay extends WebSocketServer {
public void onOpen(WebSocket arg0, ClientHandshake arg1) {
String addr;
long millis = System.currentTimeMillis();
if(config.isEnableRealIpHeader() && arg1.hasFieldValue("X-Real-IP")) {
addr = arg1.getFieldValue("X-Real-IP").toLowerCase();
if(config.isEnableRealIpHeader() && arg1.hasFieldValue(config.getRealIPHeaderName())) {
addr = arg1.getFieldValue(config.getRealIPHeaderName()).toLowerCase();
}else {
addr = arg0.getRemoteSocketAddress().getAddress().getHostAddress().toLowerCase();
}

View File

@ -36,6 +36,7 @@ public class EaglerSPRelayConfig {
private String originWhitelist = "";
private String[] originWhitelistArray = new String[0];
private boolean enableRealIpHeader = false;
private String realIpHeaderName = "CF-Connecting-IP";
private boolean enableShowLocals = true;
private String serverComment = "Eags. Public LAN Relay";
@ -55,7 +56,8 @@ public class EaglerSPRelayConfig {
gotPingRateLimitLimit = false, gotPingRateLimitLockoutLimit = false,
gotPingRateLimitLockoutDuration = false;
boolean gotOriginWhitelist = false, gotEnableRealIpHeader = false,
gotAddress = false, gotComment = false, gotShowLocals = false;
gotRealIpHeaderName = false, gotAddress = false, gotComment = false,
gotShowLocals = false;
Throwable t2 = null;
try(BufferedReader reader = new BufferedReader(new FileReader(conf))) {
@ -238,6 +240,9 @@ public class EaglerSPRelayConfig {
t2 = t;
break;
}
}else if(ss[0].equalsIgnoreCase("real-ip-header-name")) {
realIpHeaderName = ss[1];
gotRealIpHeaderName = true;
}else if(ss[0].equalsIgnoreCase("show-local-worlds")) {
try {
enableShowLocals = getBooleanValue(ss[1]);
@ -270,7 +275,7 @@ public class EaglerSPRelayConfig {
!gotPingRateLimitPeriod || !gotPingRateLimitLimit ||
!gotPingRateLimitLockoutLimit || !gotPingRateLimitLockoutDuration ||
!gotOriginWhitelist || !gotEnableRealIpHeader || !gotAddress ||
!gotComment || !gotShowLocals) {
!gotComment || !gotShowLocals || !gotRealIpHeaderName) {
EaglerSPRelay.logger.warn("Updating config file: {}", conf.getAbsoluteFile());
save(conf);
}
@ -310,6 +315,7 @@ public class EaglerSPRelayConfig {
w.println("world-ratelimit-lockout-limit: " + openRateLimitLockoutLimit);
w.println("world-ratelimit-lockout-duration: " + openRateLimitLockoutDuration);
w.println("origin-whitelist: " + originWhitelist);
w.println("real-ip-header-name: " + realIpHeaderName);
w.println("enable-real-ip-header: " + enableRealIpHeader);
w.println("show-local-worlds: " + isEnableShowLocals());
w.print("server-comment: " + serverComment);
@ -422,6 +428,10 @@ public class EaglerSPRelayConfig {
return false;
}
public String getRealIPHeaderName() {
return realIpHeaderName;
}
public boolean isEnableRealIpHeader() {
return enableRealIpHeader;
}

Binary file not shown.