fix DataSnapShot
parent
4679ede2f2
commit
b598573f41
|
@ -107,6 +107,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||||
protected ConcurrentDictionary<string, ISimpleStreamHandler> m_simpleStreamHandlers = new ConcurrentDictionary<string, ISimpleStreamHandler>();
|
protected ConcurrentDictionary<string, ISimpleStreamHandler> m_simpleStreamHandlers = new ConcurrentDictionary<string, ISimpleStreamHandler>();
|
||||||
protected ConcurrentDictionary<string, ISimpleStreamHandler> m_simpleStreamVarPath = new ConcurrentDictionary<string, ISimpleStreamHandler>();
|
protected ConcurrentDictionary<string, ISimpleStreamHandler> m_simpleStreamVarPath = new ConcurrentDictionary<string, ISimpleStreamHandler>();
|
||||||
protected ConcurrentDictionary<string, SimpleStreamMethod> m_indexPHPmethods = new ConcurrentDictionary<string, SimpleStreamMethod>();
|
protected ConcurrentDictionary<string, SimpleStreamMethod> m_indexPHPmethods = new ConcurrentDictionary<string, SimpleStreamMethod>();
|
||||||
|
protected ConcurrentDictionary<string, SimpleStreamMethod> m_globalMethods = new ConcurrentDictionary<string, SimpleStreamMethod>();
|
||||||
|
|
||||||
protected IRequestHandler m_RootDefaultGET = null; // default method for root path. does override rpc xml and json, and old llsd login
|
protected IRequestHandler m_RootDefaultGET = null; // default method for root path. does override rpc xml and json, and old llsd login
|
||||||
|
|
||||||
|
@ -389,6 +390,11 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||||
return new List<string>(m_indexPHPmethods.Keys);
|
return new List<string>(m_indexPHPmethods.Keys);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<string> GetGLobalMethodsKeys()
|
||||||
|
{
|
||||||
|
return new List<string>(m_globalMethods.Keys);
|
||||||
|
}
|
||||||
|
|
||||||
private static string GetHandlerKey(string httpMethod, string path)
|
private static string GetHandlerKey(string httpMethod, string path)
|
||||||
{
|
{
|
||||||
return httpMethod + ":" + path;
|
return httpMethod + ":" + path;
|
||||||
|
@ -547,11 +553,31 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||||
|
|
||||||
public SimpleStreamMethod TryGetIndexPHPMethodHandler(string key)
|
public SimpleStreamMethod TryGetIndexPHPMethodHandler(string key)
|
||||||
{
|
{
|
||||||
if(m_indexPHPmethods.TryGetValue(key, out SimpleStreamMethod sh))
|
if (!string.IsNullOrWhiteSpace(key) && m_indexPHPmethods.TryGetValue(key, out SimpleStreamMethod sh))
|
||||||
return sh;
|
return sh;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void AddGloblaMethodHandler(string key, SimpleStreamMethod sh)
|
||||||
|
{
|
||||||
|
m_globalMethods.TryAdd(key, sh);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RemoveGlobalPMethodHandler(string key)
|
||||||
|
{
|
||||||
|
m_globalMethods.TryRemove(key, out SimpleStreamMethod sh);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool TryGetGlobalMethodHandler(string key, out SimpleStreamMethod sh)
|
||||||
|
{
|
||||||
|
if(string.IsNullOrWhiteSpace(key))
|
||||||
|
{
|
||||||
|
sh = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return m_globalMethods.TryGetValue(key, out sh);
|
||||||
|
}
|
||||||
|
|
||||||
public void OnRequest(object source, RequestEventArgs args)
|
public void OnRequest(object source, RequestEventArgs args)
|
||||||
{
|
{
|
||||||
RequestNumber++;
|
RequestNumber++;
|
||||||
|
@ -665,6 +691,16 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||||
}
|
}
|
||||||
default: // not sure about xmlrpc content type coerence at this point
|
default: // not sure about xmlrpc content type coerence at this point
|
||||||
{
|
{
|
||||||
|
// let legacy datasnapshot work
|
||||||
|
if(request.QueryString.Count > 0 && request.QueryAsDictionary.TryGetValue("method", out string method))
|
||||||
|
{
|
||||||
|
if(TryGetGlobalMethodHandler(method, out SimpleStreamMethod sm))
|
||||||
|
{
|
||||||
|
sm?.Invoke(request, response);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (DebugLevel >= 3)
|
if (DebugLevel >= 3)
|
||||||
LogIncomingToXmlRpcHandler(request);
|
LogIncomingToXmlRpcHandler(request);
|
||||||
|
|
||||||
|
|
|
@ -27,16 +27,15 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
using System.Net;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
using log4net;
|
using log4net;
|
||||||
using OpenMetaverse;
|
using OpenMetaverse;
|
||||||
using OpenSim.Framework;
|
using OpenSim.Framework;
|
||||||
using OpenSim.Framework.Capabilities;
|
|
||||||
using OpenSim.Framework.Servers;
|
using OpenSim.Framework.Servers;
|
||||||
using OpenSim.Framework.Servers.HttpServer;
|
using OpenSim.Framework.Servers.HttpServer;
|
||||||
using OpenSim.Region.Framework.Scenes;
|
using OpenSim.Region.Framework.Scenes;
|
||||||
using Caps = OpenSim.Framework.Capabilities.Caps;
|
|
||||||
|
|
||||||
namespace OpenSim.Region.DataSnapshot
|
namespace OpenSim.Region.DataSnapshot
|
||||||
{
|
{
|
||||||
|
@ -53,68 +52,31 @@ namespace OpenSim.Region.DataSnapshot
|
||||||
m_externalData = externalData;
|
m_externalData = externalData;
|
||||||
|
|
||||||
//Register HTTP handler
|
//Register HTTP handler
|
||||||
if (MainServer.UnSecureInstance.AddHTTPHandler("collector", OnGetSnapshot))
|
MainServer.UnSecureInstance.AddGloblaMethodHandler("collector", OnGetSnapshot);
|
||||||
{
|
// Register validation callback handler
|
||||||
|
MainServer.UnSecureInstance.AddGloblaMethodHandler("validate", OnValidate);
|
||||||
|
|
||||||
m_log.Info("[DATASNAPSHOT]: Set up snapshot service");
|
m_log.Info("[DATASNAPSHOT]: Set up snapshot service");
|
||||||
}
|
}
|
||||||
// Register validation callback handler
|
|
||||||
MainServer.UnSecureInstance.AddHTTPHandler("validate", OnValidate);
|
|
||||||
|
|
||||||
}
|
public void OnGetSnapshot(IOSHttpRequest req, IOSHttpResponse resp)
|
||||||
|
|
||||||
private string GetClientString(Hashtable request)
|
|
||||||
{
|
|
||||||
string clientstring = "";
|
|
||||||
if (!request.ContainsKey("headers"))
|
|
||||||
return clientstring;
|
|
||||||
|
|
||||||
Hashtable requestinfo = (Hashtable)request["headers"];
|
|
||||||
if (requestinfo.ContainsKey("x-forwarded-for"))
|
|
||||||
{
|
|
||||||
object str = requestinfo["x-forwarded-for"];
|
|
||||||
if (str != null)
|
|
||||||
{
|
|
||||||
if (!string.IsNullOrEmpty(str.ToString()))
|
|
||||||
{
|
|
||||||
return str.ToString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!requestinfo.ContainsKey("remote_addr"))
|
|
||||||
return clientstring;
|
|
||||||
|
|
||||||
object remote_addrobj = requestinfo["remote_addr"];
|
|
||||||
if (remote_addrobj != null)
|
|
||||||
{
|
|
||||||
if (!string.IsNullOrEmpty(remote_addrobj.ToString()))
|
|
||||||
{
|
|
||||||
clientstring = remote_addrobj.ToString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return clientstring;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Hashtable OnGetSnapshot(Hashtable keysvals)
|
|
||||||
{
|
{
|
||||||
Hashtable reply = new Hashtable();
|
Hashtable reply = new Hashtable();
|
||||||
string reqtag;
|
string reqtag;
|
||||||
string snapObj = (string)keysvals["region"];
|
if(req.QueryAsDictionary.TryGetValue("region", out string snapObj) && !string.IsNullOrWhiteSpace(snapObj))
|
||||||
if(string.IsNullOrWhiteSpace(snapObj))
|
reqtag = snapObj + req.RemoteIPEndPoint.Address.ToString();
|
||||||
reqtag = GetClientString(keysvals);
|
|
||||||
else
|
else
|
||||||
reqtag = snapObj + GetClientString(keysvals);
|
reqtag = req.RemoteIPEndPoint.Address.ToString();
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(reqtag))
|
||||||
if(!string.IsNullOrWhiteSpace(reqtag))
|
|
||||||
{
|
{
|
||||||
if(throotleGen.Contains(reqtag))
|
if(throotleGen.Contains(reqtag))
|
||||||
{
|
{
|
||||||
reply["str_response_string"] = "Please try your request again later";
|
resp.StatusCode = (int)HttpStatusCode.ServiceUnavailable;
|
||||||
reply["int_response_code"] = 503;
|
resp.StatusDescription = "Please try again later";
|
||||||
reply["content_type"] = "text/plain";
|
resp.ContentType = "text/plain";
|
||||||
m_log.Debug("[DATASNAPSHOT] Collection request spam. reply try later");
|
m_log.Debug("[DATASNAPSHOT] Collection request spam. reply try later");
|
||||||
return reply;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
throotleGen.AddOrUpdate(reqtag, 0, 60);
|
throotleGen.AddOrUpdate(reqtag, 0, 60);
|
||||||
|
@ -128,35 +90,28 @@ namespace OpenSim.Region.DataSnapshot
|
||||||
XmlDocument response = m_externalData.GetSnapshot(snapObj);
|
XmlDocument response = m_externalData.GetSnapshot(snapObj);
|
||||||
if(response == null)
|
if(response == null)
|
||||||
{
|
{
|
||||||
reply["str_response_string"] = "Please try your request again later";
|
resp.StatusCode = (int)HttpStatusCode.ServiceUnavailable;
|
||||||
reply["int_response_code"] = 503;
|
resp.ContentType = "text/plain";
|
||||||
reply["content_type"] = "text/plain";
|
|
||||||
m_log.Debug("[DATASNAPSHOT] Collection request spam. reply try later");
|
m_log.Debug("[DATASNAPSHOT] Collection request spam. reply try later");
|
||||||
return reply;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
reply["str_response_string"] = response.OuterXml;
|
resp.RawBuffer = Util.UTF8NBGetbytes(response.OuterXml);
|
||||||
reply["int_response_code"] = 200;
|
resp.ContentType = "text/xml";
|
||||||
reply["content_type"] = "text/xml";
|
resp.StatusCode = (int)HttpStatusCode.OK;
|
||||||
return reply;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Hashtable OnValidate(Hashtable keysvals)
|
public void OnValidate(IOSHttpRequest req, IOSHttpResponse resp)
|
||||||
{
|
{
|
||||||
m_log.Debug("[DATASNAPSHOT] Received validation request");
|
m_log.Debug("[DATASNAPSHOT] Received validation request");
|
||||||
Hashtable reply = new Hashtable();
|
resp.ContentType = "text/xml";
|
||||||
int statuscode = 200;
|
resp.StatusCode = (int)HttpStatusCode.Forbidden;
|
||||||
|
|
||||||
string secret = (string)keysvals["secret"];
|
if(req.QueryAsDictionary.TryGetValue("secret", out string secret))
|
||||||
|
{
|
||||||
if (secret == m_externalData.Secret.ToString())
|
if (secret == m_externalData.Secret.ToString())
|
||||||
statuscode = 403;
|
resp.StatusCode = (int)HttpStatusCode.OK;
|
||||||
|
}
|
||||||
reply["str_response_string"] = string.Empty;
|
|
||||||
reply["int_response_code"] = statuscode;
|
|
||||||
reply["content_type"] = "text/plain";
|
|
||||||
|
|
||||||
return reply;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue