diff options
Diffstat (limited to 'OpenSim/Server/Handlers')
-rw-r--r-- | OpenSim/Server/Handlers/Map/MapAddServerConnector.cs | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/OpenSim/Server/Handlers/Map/MapAddServerConnector.cs b/OpenSim/Server/Handlers/Map/MapAddServerConnector.cs index c87de92..cc7ef9d 100644 --- a/OpenSim/Server/Handlers/Map/MapAddServerConnector.cs +++ b/OpenSim/Server/Handlers/Map/MapAddServerConnector.cs | |||
@@ -78,7 +78,8 @@ namespace OpenSim.Server.Handlers.MapImage | |||
78 | else | 78 | else |
79 | m_log.InfoFormat("[MAP IMAGE HANDLER]: GridService check is OFF"); | 79 | m_log.InfoFormat("[MAP IMAGE HANDLER]: GridService check is OFF"); |
80 | 80 | ||
81 | server.AddStreamHandler(new MapServerPostHandler(m_MapService, m_GridService)); | 81 | bool proxy = serverConfig.GetBoolean("HasProxy", false); |
82 | server.AddStreamHandler(new MapServerPostHandler(m_MapService, m_GridService, proxy)); | ||
82 | 83 | ||
83 | } | 84 | } |
84 | } | 85 | } |
@@ -88,12 +89,14 @@ namespace OpenSim.Server.Handlers.MapImage | |||
88 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 89 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
89 | private IMapImageService m_MapService; | 90 | private IMapImageService m_MapService; |
90 | private IGridService m_GridService; | 91 | private IGridService m_GridService; |
92 | bool m_Proxy; | ||
91 | 93 | ||
92 | public MapServerPostHandler(IMapImageService service, IGridService grid) : | 94 | public MapServerPostHandler(IMapImageService service, IGridService grid, bool proxy) : |
93 | base("POST", "/map") | 95 | base("POST", "/map") |
94 | { | 96 | { |
95 | m_MapService = service; | 97 | m_MapService = service; |
96 | m_GridService = grid; | 98 | m_GridService = grid; |
99 | m_Proxy = proxy; | ||
97 | } | 100 | } |
98 | 101 | ||
99 | public override byte[] Handle(string path, Stream requestData, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | 102 | public override byte[] Handle(string path, Stream requestData, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) |
@@ -129,7 +132,7 @@ namespace OpenSim.Server.Handlers.MapImage | |||
129 | GridRegion r = m_GridService.GetRegionByPosition(UUID.Zero, x * (int)Constants.RegionSize, y * (int)Constants.RegionSize); | 132 | GridRegion r = m_GridService.GetRegionByPosition(UUID.Zero, x * (int)Constants.RegionSize, y * (int)Constants.RegionSize); |
130 | if (r != null) | 133 | if (r != null) |
131 | { | 134 | { |
132 | if (r.ExternalEndPoint.Address != httpRequest.RemoteIPEndPoint.Address) | 135 | if (r.ExternalEndPoint.Address != GetCallerIP(httpRequest)) |
133 | { | 136 | { |
134 | m_log.WarnFormat("[MAP IMAGE HANDLER]: IP address {0} may be rogue", httpRequest.RemoteIPEndPoint.Address); | 137 | m_log.WarnFormat("[MAP IMAGE HANDLER]: IP address {0} may be rogue", httpRequest.RemoteIPEndPoint.Address); |
135 | return FailureResult("IP address of caller does not match IP address of registered region"); | 138 | return FailureResult("IP address of caller does not match IP address of registered region"); |
@@ -221,5 +224,31 @@ namespace OpenSim.Server.Handlers.MapImage | |||
221 | 224 | ||
222 | return ms.ToArray(); | 225 | return ms.ToArray(); |
223 | } | 226 | } |
227 | |||
228 | private System.Net.IPAddress GetCallerIP(IOSHttpRequest request) | ||
229 | { | ||
230 | if (!m_Proxy) | ||
231 | return request.RemoteIPEndPoint.Address; | ||
232 | |||
233 | // We're behind a proxy | ||
234 | string xff = "X-Forwarded-For"; | ||
235 | string xffValue = request.Headers[xff.ToLower()]; | ||
236 | if (xffValue == null || (xffValue != null && xffValue == string.Empty)) | ||
237 | xffValue = request.Headers[xff]; | ||
238 | |||
239 | if (xffValue == null || (xffValue != null && xffValue == string.Empty)) | ||
240 | { | ||
241 | m_log.WarnFormat("[MAP IMAGE HANDLER]: No XFF header"); | ||
242 | return request.RemoteIPEndPoint.Address; | ||
243 | } | ||
244 | |||
245 | System.Net.IPEndPoint ep = Util.GetClientIPFromXFF(xffValue); | ||
246 | if (ep != null) | ||
247 | return ep.Address; | ||
248 | |||
249 | // Oops | ||
250 | return request.RemoteIPEndPoint.Address; | ||
251 | } | ||
252 | |||
224 | } | 253 | } |
225 | } | 254 | } |