Amend to last commit: account for the existence of proxies.
parent
2970a18e54
commit
ac64fe03d8
|
@ -78,7 +78,8 @@ namespace OpenSim.Server.Handlers.MapImage
|
||||||
else
|
else
|
||||||
m_log.InfoFormat("[MAP IMAGE HANDLER]: GridService check is OFF");
|
m_log.InfoFormat("[MAP IMAGE HANDLER]: GridService check is OFF");
|
||||||
|
|
||||||
server.AddStreamHandler(new MapServerPostHandler(m_MapService, m_GridService));
|
bool proxy = serverConfig.GetBoolean("HasProxy", false);
|
||||||
|
server.AddStreamHandler(new MapServerPostHandler(m_MapService, m_GridService, proxy));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -88,12 +89,14 @@ namespace OpenSim.Server.Handlers.MapImage
|
||||||
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
private IMapImageService m_MapService;
|
private IMapImageService m_MapService;
|
||||||
private IGridService m_GridService;
|
private IGridService m_GridService;
|
||||||
|
bool m_Proxy;
|
||||||
|
|
||||||
public MapServerPostHandler(IMapImageService service, IGridService grid) :
|
public MapServerPostHandler(IMapImageService service, IGridService grid, bool proxy) :
|
||||||
base("POST", "/map")
|
base("POST", "/map")
|
||||||
{
|
{
|
||||||
m_MapService = service;
|
m_MapService = service;
|
||||||
m_GridService = grid;
|
m_GridService = grid;
|
||||||
|
m_Proxy = proxy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override byte[] Handle(string path, Stream requestData, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
|
public override byte[] Handle(string path, Stream requestData, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
|
||||||
|
@ -129,7 +132,7 @@ namespace OpenSim.Server.Handlers.MapImage
|
||||||
GridRegion r = m_GridService.GetRegionByPosition(UUID.Zero, x * (int)Constants.RegionSize, y * (int)Constants.RegionSize);
|
GridRegion r = m_GridService.GetRegionByPosition(UUID.Zero, x * (int)Constants.RegionSize, y * (int)Constants.RegionSize);
|
||||||
if (r != null)
|
if (r != null)
|
||||||
{
|
{
|
||||||
if (r.ExternalEndPoint.Address != httpRequest.RemoteIPEndPoint.Address)
|
if (r.ExternalEndPoint.Address != GetCallerIP(httpRequest))
|
||||||
{
|
{
|
||||||
m_log.WarnFormat("[MAP IMAGE HANDLER]: IP address {0} may be rogue", httpRequest.RemoteIPEndPoint.Address);
|
m_log.WarnFormat("[MAP IMAGE HANDLER]: IP address {0} may be rogue", httpRequest.RemoteIPEndPoint.Address);
|
||||||
return FailureResult("IP address of caller does not match IP address of registered region");
|
return FailureResult("IP address of caller does not match IP address of registered region");
|
||||||
|
@ -221,5 +224,31 @@ namespace OpenSim.Server.Handlers.MapImage
|
||||||
|
|
||||||
return ms.ToArray();
|
return ms.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private System.Net.IPAddress GetCallerIP(IOSHttpRequest request)
|
||||||
|
{
|
||||||
|
if (!m_Proxy)
|
||||||
|
return request.RemoteIPEndPoint.Address;
|
||||||
|
|
||||||
|
// We're behind a proxy
|
||||||
|
string xff = "X-Forwarded-For";
|
||||||
|
string xffValue = request.Headers[xff.ToLower()];
|
||||||
|
if (xffValue == null || (xffValue != null && xffValue == string.Empty))
|
||||||
|
xffValue = request.Headers[xff];
|
||||||
|
|
||||||
|
if (xffValue == null || (xffValue != null && xffValue == string.Empty))
|
||||||
|
{
|
||||||
|
m_log.WarnFormat("[MAP IMAGE HANDLER]: No XFF header");
|
||||||
|
return request.RemoteIPEndPoint.Address;
|
||||||
|
}
|
||||||
|
|
||||||
|
System.Net.IPEndPoint ep = Util.GetClientIPFromXFF(xffValue);
|
||||||
|
if (ep != null)
|
||||||
|
return ep.Address;
|
||||||
|
|
||||||
|
// Oops
|
||||||
|
return request.RemoteIPEndPoint.Address;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -283,6 +283,9 @@ ServiceConnectors = "8003/OpenSim.Server.Handlers.dll:AssetServiceConnector,8003
|
||||||
; If for some reason you have the AddMapTile service outside the firewall (e.g. 8002),
|
; If for some reason you have the AddMapTile service outside the firewall (e.g. 8002),
|
||||||
; you may want to set this. Otherwise, don't set it, because it's already protected.
|
; you may want to set this. Otherwise, don't set it, because it's already protected.
|
||||||
; GridService = "OpenSim.Services.GridService.dll:GridService"
|
; GridService = "OpenSim.Services.GridService.dll:GridService"
|
||||||
|
;
|
||||||
|
; Additionally, if you run this server behind a proxy, set this to true
|
||||||
|
; HasProxy = false
|
||||||
|
|
||||||
[GridInfoService]
|
[GridInfoService]
|
||||||
; These settings are used to return information on a get_grid_info call.
|
; These settings are used to return information on a get_grid_info call.
|
||||||
|
|
|
@ -258,6 +258,10 @@ ServiceConnectors = "8003/OpenSim.Server.Handlers.dll:AssetServiceConnector,8003
|
||||||
; If for some reason you have the AddMapTile service outside the firewall (e.g. 8002),
|
; If for some reason you have the AddMapTile service outside the firewall (e.g. 8002),
|
||||||
; you may want to set this. Otherwise, don't set it, because it's already protected.
|
; you may want to set this. Otherwise, don't set it, because it's already protected.
|
||||||
; GridService = "OpenSim.Services.GridService.dll:GridService"
|
; GridService = "OpenSim.Services.GridService.dll:GridService"
|
||||||
|
;
|
||||||
|
; Additionally, if you run this server behind a proxy, set this to true
|
||||||
|
; HasProxy = false
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[GridInfoService]
|
[GridInfoService]
|
||||||
|
|
Loading…
Reference in New Issue