mirror of
https://github.com/opensim/opensim.git
synced 2026-08-05 17:05:55 +08:00
fix DataSnapShot
This commit is contained in:
@@ -27,16 +27,15 @@
|
||||
*/
|
||||
|
||||
using System.Collections;
|
||||
using System.Net;
|
||||
using System.Reflection;
|
||||
using System.Xml;
|
||||
using log4net;
|
||||
using OpenMetaverse;
|
||||
using OpenSim.Framework;
|
||||
using OpenSim.Framework.Capabilities;
|
||||
using OpenSim.Framework.Servers;
|
||||
using OpenSim.Framework.Servers.HttpServer;
|
||||
using OpenSim.Region.Framework.Scenes;
|
||||
using Caps = OpenSim.Framework.Capabilities.Caps;
|
||||
|
||||
namespace OpenSim.Region.DataSnapshot
|
||||
{
|
||||
@@ -53,68 +52,31 @@ namespace OpenSim.Region.DataSnapshot
|
||||
m_externalData = externalData;
|
||||
|
||||
//Register HTTP handler
|
||||
if (MainServer.UnSecureInstance.AddHTTPHandler("collector", OnGetSnapshot))
|
||||
{
|
||||
m_log.Info("[DATASNAPSHOT]: Set up snapshot service");
|
||||
}
|
||||
MainServer.UnSecureInstance.AddGloblaMethodHandler("collector", OnGetSnapshot);
|
||||
// Register validation callback handler
|
||||
MainServer.UnSecureInstance.AddHTTPHandler("validate", OnValidate);
|
||||
MainServer.UnSecureInstance.AddGloblaMethodHandler("validate", OnValidate);
|
||||
|
||||
m_log.Info("[DATASNAPSHOT]: Set up snapshot service");
|
||||
}
|
||||
|
||||
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)
|
||||
public void OnGetSnapshot(IOSHttpRequest req, IOSHttpResponse resp)
|
||||
{
|
||||
Hashtable reply = new Hashtable();
|
||||
string reqtag;
|
||||
string snapObj = (string)keysvals["region"];
|
||||
if(string.IsNullOrWhiteSpace(snapObj))
|
||||
reqtag = GetClientString(keysvals);
|
||||
if(req.QueryAsDictionary.TryGetValue("region", out string snapObj) && !string.IsNullOrWhiteSpace(snapObj))
|
||||
reqtag = snapObj + req.RemoteIPEndPoint.Address.ToString();
|
||||
else
|
||||
reqtag = snapObj + GetClientString(keysvals);
|
||||
reqtag = req.RemoteIPEndPoint.Address.ToString();
|
||||
|
||||
|
||||
if(!string.IsNullOrWhiteSpace(reqtag))
|
||||
if (!string.IsNullOrWhiteSpace(reqtag))
|
||||
{
|
||||
if(throotleGen.Contains(reqtag))
|
||||
{
|
||||
reply["str_response_string"] = "Please try your request again later";
|
||||
reply["int_response_code"] = 503;
|
||||
reply["content_type"] = "text/plain";
|
||||
resp.StatusCode = (int)HttpStatusCode.ServiceUnavailable;
|
||||
resp.StatusDescription = "Please try again later";
|
||||
resp.ContentType = "text/plain";
|
||||
m_log.Debug("[DATASNAPSHOT] Collection request spam. reply try later");
|
||||
return reply;
|
||||
return;
|
||||
}
|
||||
|
||||
throotleGen.AddOrUpdate(reqtag, 0, 60);
|
||||
@@ -128,35 +90,28 @@ namespace OpenSim.Region.DataSnapshot
|
||||
XmlDocument response = m_externalData.GetSnapshot(snapObj);
|
||||
if(response == null)
|
||||
{
|
||||
reply["str_response_string"] = "Please try your request again later";
|
||||
reply["int_response_code"] = 503;
|
||||
reply["content_type"] = "text/plain";
|
||||
resp.StatusCode = (int)HttpStatusCode.ServiceUnavailable;
|
||||
resp.ContentType = "text/plain";
|
||||
m_log.Debug("[DATASNAPSHOT] Collection request spam. reply try later");
|
||||
return reply;
|
||||
return;
|
||||
}
|
||||
|
||||
reply["str_response_string"] = response.OuterXml;
|
||||
reply["int_response_code"] = 200;
|
||||
reply["content_type"] = "text/xml";
|
||||
return reply;
|
||||
resp.RawBuffer = Util.UTF8NBGetbytes(response.OuterXml);
|
||||
resp.ContentType = "text/xml";
|
||||
resp.StatusCode = (int)HttpStatusCode.OK;
|
||||
}
|
||||
|
||||
public Hashtable OnValidate(Hashtable keysvals)
|
||||
public void OnValidate(IOSHttpRequest req, IOSHttpResponse resp)
|
||||
{
|
||||
m_log.Debug("[DATASNAPSHOT] Received validation request");
|
||||
Hashtable reply = new Hashtable();
|
||||
int statuscode = 200;
|
||||
resp.ContentType = "text/xml";
|
||||
resp.StatusCode = (int)HttpStatusCode.Forbidden;
|
||||
|
||||
string secret = (string)keysvals["secret"];
|
||||
if (secret == m_externalData.Secret.ToString())
|
||||
statuscode = 403;
|
||||
|
||||
reply["str_response_string"] = string.Empty;
|
||||
reply["int_response_code"] = statuscode;
|
||||
reply["content_type"] = "text/plain";
|
||||
|
||||
return reply;
|
||||
if(req.QueryAsDictionary.TryGetValue("secret", out string secret))
|
||||
{
|
||||
if (secret == m_externalData.Secret.ToString())
|
||||
resp.StatusCode = (int)HttpStatusCode.OK;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user