aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Console/RemoteConsole.cs
diff options
context:
space:
mode:
authorMarck2010-11-01 13:52:39 +0100
committerDiva Canto2010-11-02 14:12:25 -0700
commit4fdab71c8d05249778a567349fc3340be3841c43 (patch)
tree8e08ed51ba41c576dd3349e3d2a04d8202bdac44 /OpenSim/Framework/Console/RemoteConsole.cs
parentSupport for CORS with simple requests in BaseHttpServer (diff)
downloadopensim-SC-4fdab71c8d05249778a567349fc3340be3841c43.zip
opensim-SC-4fdab71c8d05249778a567349fc3340be3841c43.tar.gz
opensim-SC-4fdab71c8d05249778a567349fc3340be3841c43.tar.bz2
opensim-SC-4fdab71c8d05249778a567349fc3340be3841c43.tar.xz
Add support for cross-domain AJAX requests to REST console.
Enables RemoteConsole to add the appropriate HTTP header when responding to requests that use Cross-Origin Resource Sharing (CORS with simple requests). The allowed origin is set with configuration option "ConsoleAllowedOrigin" in section [Network]. For a suggestion to make this configuration option more flexible, see the TODO comment in the source code. The WifiConsole uses this functionality with grid mode.
Diffstat (limited to '')
-rw-r--r--OpenSim/Framework/Console/RemoteConsole.cs31
1 files changed, 31 insertions, 0 deletions
diff --git a/OpenSim/Framework/Console/RemoteConsole.cs b/OpenSim/Framework/Console/RemoteConsole.cs
index 7eb289b..07de27a 100644
--- a/OpenSim/Framework/Console/RemoteConsole.cs
+++ b/OpenSim/Framework/Console/RemoteConsole.cs
@@ -32,6 +32,7 @@ using System.Collections.Generic;
32using System.Diagnostics; 32using System.Diagnostics;
33using System.Reflection; 33using System.Reflection;
34using System.Text; 34using System.Text;
35using System.Text.RegularExpressions;
35using System.Threading; 36using System.Threading;
36using OpenMetaverse; 37using OpenMetaverse;
37using Nini.Config; 38using Nini.Config;
@@ -62,6 +63,7 @@ namespace OpenSim.Framework.Console
62 new Dictionary<UUID, ConsoleConnection>(); 63 new Dictionary<UUID, ConsoleConnection>();
63 private string m_UserName = String.Empty; 64 private string m_UserName = String.Empty;
64 private string m_Password = String.Empty; 65 private string m_Password = String.Empty;
66 private string m_AllowedOrigin = String.Empty;
65 67
66 public RemoteConsole(string defaultPrompt) : base(defaultPrompt) 68 public RemoteConsole(string defaultPrompt) : base(defaultPrompt)
67 { 69 {
@@ -77,6 +79,7 @@ namespace OpenSim.Framework.Console
77 79
78 m_UserName = netConfig.GetString("ConsoleUser", String.Empty); 80 m_UserName = netConfig.GetString("ConsoleUser", String.Empty);
79 m_Password = netConfig.GetString("ConsolePass", String.Empty); 81 m_Password = netConfig.GetString("ConsolePass", String.Empty);
82 m_AllowedOrigin = netConfig.GetString("ConsoleAllowedOrigin", String.Empty);
80 } 83 }
81 84
82 public void SetServer(IHttpServer server) 85 public void SetServer(IHttpServer server)
@@ -150,6 +153,29 @@ namespace OpenSim.Framework.Console
150 return cmdinput; 153 return cmdinput;
151 } 154 }
152 155
156 private Hashtable CheckOrigin(Hashtable result)
157 {
158 if (!string.IsNullOrEmpty(m_AllowedOrigin))
159 result["access_control_allow_origin"] = m_AllowedOrigin;
160 return result;
161 }
162 /* TODO: Figure out how PollServiceHTTPHandler can access the request headers
163 * in order to use m_AllowedOrigin as a regular expression
164 private Hashtable CheckOrigin(Hashtable headers, Hashtable result)
165 {
166 if (!string.IsNullOrEmpty(m_AllowedOrigin))
167 {
168 if (headers.ContainsKey("origin"))
169 {
170 string origin = headers["origin"].ToString();
171 if (Regex.IsMatch(origin, m_AllowedOrigin))
172 result["access_control_allow_origin"] = origin;
173 }
174 }
175 return result;
176 }
177 */
178
153 private void DoExpire() 179 private void DoExpire()
154 { 180 {
155 List<UUID> expired = new List<UUID>(); 181 List<UUID> expired = new List<UUID>();
@@ -235,6 +261,7 @@ namespace OpenSim.Framework.Console
235 reply["str_response_string"] = xmldoc.InnerXml; 261 reply["str_response_string"] = xmldoc.InnerXml;
236 reply["int_response_code"] = 200; 262 reply["int_response_code"] = 200;
237 reply["content_type"] = "text/xml"; 263 reply["content_type"] = "text/xml";
264 reply = CheckOrigin(reply);
238 265
239 return reply; 266 return reply;
240 } 267 }
@@ -289,6 +316,7 @@ namespace OpenSim.Framework.Console
289 reply["str_response_string"] = xmldoc.InnerXml; 316 reply["str_response_string"] = xmldoc.InnerXml;
290 reply["int_response_code"] = 200; 317 reply["int_response_code"] = 200;
291 reply["content_type"] = "text/xml"; 318 reply["content_type"] = "text/xml";
319 reply = CheckOrigin(reply);
292 320
293 return reply; 321 return reply;
294 } 322 }
@@ -344,6 +372,7 @@ namespace OpenSim.Framework.Console
344 reply["str_response_string"] = xmldoc.InnerXml; 372 reply["str_response_string"] = xmldoc.InnerXml;
345 reply["int_response_code"] = 200; 373 reply["int_response_code"] = 200;
346 reply["content_type"] = "text/xml"; 374 reply["content_type"] = "text/xml";
375 reply = CheckOrigin(reply);
347 376
348 return reply; 377 return reply;
349 } 378 }
@@ -457,6 +486,7 @@ namespace OpenSim.Framework.Console
457 result["content_type"] = "application/xml"; 486 result["content_type"] = "application/xml";
458 result["keepalive"] = false; 487 result["keepalive"] = false;
459 result["reusecontext"] = false; 488 result["reusecontext"] = false;
489 result = CheckOrigin(result);
460 490
461 return result; 491 return result;
462 } 492 }
@@ -480,6 +510,7 @@ namespace OpenSim.Framework.Console
480 result["content_type"] = "text/xml"; 510 result["content_type"] = "text/xml";
481 result["keepalive"] = false; 511 result["keepalive"] = false;
482 result["reusecontext"] = false; 512 result["reusecontext"] = false;
513 result = CheckOrigin(result);
483 514
484 return result; 515 return result;
485 } 516 }