diff options
Diffstat (limited to 'OpenSim/Server')
-rw-r--r-- | OpenSim/Server/Handlers/Map/MapAddServerConnector.cs | 79 |
1 files changed, 74 insertions, 5 deletions
diff --git a/OpenSim/Server/Handlers/Map/MapAddServerConnector.cs b/OpenSim/Server/Handlers/Map/MapAddServerConnector.cs index 75dd711..4a61969 100644 --- a/OpenSim/Server/Handlers/Map/MapAddServerConnector.cs +++ b/OpenSim/Server/Handlers/Map/MapAddServerConnector.cs | |||
@@ -33,17 +33,24 @@ using System.Xml; | |||
33 | 33 | ||
34 | using Nini.Config; | 34 | using Nini.Config; |
35 | using log4net; | 35 | using log4net; |
36 | using OpenMetaverse; | ||
36 | 37 | ||
38 | using OpenSim.Framework; | ||
37 | using OpenSim.Server.Base; | 39 | using OpenSim.Server.Base; |
38 | using OpenSim.Services.Interfaces; | 40 | using OpenSim.Services.Interfaces; |
39 | using OpenSim.Framework.Servers.HttpServer; | 41 | using OpenSim.Framework.Servers.HttpServer; |
40 | using OpenSim.Server.Handlers.Base; | 42 | using OpenSim.Server.Handlers.Base; |
41 | 43 | ||
44 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
45 | |||
42 | namespace OpenSim.Server.Handlers.MapImage | 46 | namespace OpenSim.Server.Handlers.MapImage |
43 | { | 47 | { |
44 | public class MapAddServiceConnector : ServiceConnector | 48 | public class MapAddServiceConnector : ServiceConnector |
45 | { | 49 | { |
50 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
51 | |||
46 | private IMapImageService m_MapService; | 52 | private IMapImageService m_MapService; |
53 | private IGridService m_GridService; | ||
47 | private string m_ConfigName = "MapImageService"; | 54 | private string m_ConfigName = "MapImageService"; |
48 | 55 | ||
49 | public MapAddServiceConnector(IConfigSource config, IHttpServer server, string configName) : | 56 | public MapAddServiceConnector(IConfigSource config, IHttpServer server, string configName) : |
@@ -53,16 +60,27 @@ namespace OpenSim.Server.Handlers.MapImage | |||
53 | if (serverConfig == null) | 60 | if (serverConfig == null) |
54 | throw new Exception(String.Format("No section {0} in config file", m_ConfigName)); | 61 | throw new Exception(String.Format("No section {0} in config file", m_ConfigName)); |
55 | 62 | ||
56 | string gridService = serverConfig.GetString("LocalServiceModule", | 63 | string mapService = serverConfig.GetString("LocalServiceModule", |
57 | String.Empty); | 64 | String.Empty); |
58 | 65 | ||
59 | if (gridService == String.Empty) | 66 | if (mapService == String.Empty) |
60 | throw new Exception("No LocalServiceModule in config file"); | 67 | throw new Exception("No LocalServiceModule in config file"); |
61 | 68 | ||
62 | Object[] args = new Object[] { config }; | 69 | Object[] args = new Object[] { config }; |
63 | m_MapService = ServerUtils.LoadPlugin<IMapImageService>(gridService, args); | 70 | m_MapService = ServerUtils.LoadPlugin<IMapImageService>(mapService, args); |
71 | |||
72 | string gridService = serverConfig.GetString("GridService", String.Empty); | ||
73 | if (gridService != string.Empty) | ||
74 | m_GridService = ServerUtils.LoadPlugin<IGridService>(gridService, args); | ||
75 | |||
76 | if (m_GridService != null) | ||
77 | m_log.InfoFormat("[MAP IMAGE HANDLER]: GridService check is ON"); | ||
78 | else | ||
79 | m_log.InfoFormat("[MAP IMAGE HANDLER]: GridService check is OFF"); | ||
80 | |||
81 | bool proxy = serverConfig.GetBoolean("HasProxy", false); | ||
82 | server.AddStreamHandler(new MapServerPostHandler(m_MapService, m_GridService, proxy)); | ||
64 | 83 | ||
65 | server.AddStreamHandler(new MapServerPostHandler(m_MapService)); | ||
66 | } | 84 | } |
67 | } | 85 | } |
68 | 86 | ||
@@ -70,11 +88,15 @@ namespace OpenSim.Server.Handlers.MapImage | |||
70 | { | 88 | { |
71 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 89 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
72 | private IMapImageService m_MapService; | 90 | private IMapImageService m_MapService; |
91 | private IGridService m_GridService; | ||
92 | bool m_Proxy; | ||
73 | 93 | ||
74 | public MapServerPostHandler(IMapImageService service) : | 94 | public MapServerPostHandler(IMapImageService service, IGridService grid, bool proxy) : |
75 | base("POST", "/map") | 95 | base("POST", "/map") |
76 | { | 96 | { |
77 | m_MapService = service; | 97 | m_MapService = service; |
98 | m_GridService = grid; | ||
99 | m_Proxy = proxy; | ||
78 | } | 100 | } |
79 | 101 | ||
80 | 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) |
@@ -105,6 +127,27 @@ namespace OpenSim.Server.Handlers.MapImage | |||
105 | // if (request.ContainsKey("TYPE")) | 127 | // if (request.ContainsKey("TYPE")) |
106 | // type = request["TYPE"].ToString(); | 128 | // type = request["TYPE"].ToString(); |
107 | 129 | ||
130 | if (m_GridService != null) | ||
131 | { | ||
132 | System.Net.IPAddress ipAddr = GetCallerIP(httpRequest); | ||
133 | GridRegion r = m_GridService.GetRegionByPosition(UUID.Zero, x * (int)Constants.RegionSize, y * (int)Constants.RegionSize); | ||
134 | if (r != null) | ||
135 | { | ||
136 | if (r.ExternalEndPoint.Address.ToString() != ipAddr.ToString()) | ||
137 | { | ||
138 | m_log.WarnFormat("[MAP IMAGE HANDLER]: IP address {0} may be trying to impersonate region in IP {1}", ipAddr, r.ExternalEndPoint.Address); | ||
139 | return FailureResult("IP address of caller does not match IP address of registered region"); | ||
140 | } | ||
141 | |||
142 | } | ||
143 | else | ||
144 | { | ||
145 | m_log.WarnFormat("[MAP IMAGE HANDLER]: IP address {0} may be rogue. Region not found at coordinates {1}-{2}", | ||
146 | ipAddr, x, y); | ||
147 | return FailureResult("Region not found at given coordinates"); | ||
148 | } | ||
149 | } | ||
150 | |||
108 | byte[] data = Convert.FromBase64String(request["DATA"].ToString()); | 151 | byte[] data = Convert.FromBase64String(request["DATA"].ToString()); |
109 | 152 | ||
110 | string reason = string.Empty; | 153 | string reason = string.Empty; |
@@ -183,5 +226,31 @@ namespace OpenSim.Server.Handlers.MapImage | |||
183 | 226 | ||
184 | return ms.ToArray(); | 227 | return ms.ToArray(); |
185 | } | 228 | } |
229 | |||
230 | private System.Net.IPAddress GetCallerIP(IOSHttpRequest request) | ||
231 | { | ||
232 | if (!m_Proxy) | ||
233 | return request.RemoteIPEndPoint.Address; | ||
234 | |||
235 | // We're behind a proxy | ||
236 | string xff = "X-Forwarded-For"; | ||
237 | string xffValue = request.Headers[xff.ToLower()]; | ||
238 | if (xffValue == null || (xffValue != null && xffValue == string.Empty)) | ||
239 | xffValue = request.Headers[xff]; | ||
240 | |||
241 | if (xffValue == null || (xffValue != null && xffValue == string.Empty)) | ||
242 | { | ||
243 | m_log.WarnFormat("[MAP IMAGE HANDLER]: No XFF header"); | ||
244 | return request.RemoteIPEndPoint.Address; | ||
245 | } | ||
246 | |||
247 | System.Net.IPEndPoint ep = Util.GetClientIPFromXFF(xffValue); | ||
248 | if (ep != null) | ||
249 | return ep.Address; | ||
250 | |||
251 | // Oops | ||
252 | return request.RemoteIPEndPoint.Address; | ||
253 | } | ||
254 | |||
186 | } | 255 | } |
187 | } | 256 | } |