add a /index.php fake handler, for map. only does ?method=.. but can be extended)

This commit is contained in:
UbitUmarov
2020-04-25 23:24:00 +01:00
parent 70d2878d0a
commit dcc2f764f2
4 changed files with 73 additions and 0 deletions

View File

@@ -221,6 +221,7 @@ namespace OpenSim
if (userStatsURI != String.Empty)
MainServer.Instance.AddSimpleStreamHandler(new UXSimStatusHandler(this));
MainServer.Instance.AddSimpleStreamHandler(new SimRobotsHandler());
MainServer.Instance.AddSimpleStreamHandler(new IndexPHPHandler(MainServer.Instance));
if (managedStatsURI != String.Empty)
{

View File

@@ -870,6 +870,56 @@ namespace OpenSim
}
}
public class IndexPHPHandler : SimpleStreamHandler
{
BaseHttpServer m_server;
public IndexPHPHandler(BaseHttpServer server)
: base("/index.php")
{
m_server = server;
}
protected override void ProcessRequest(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
{
httpResponse.KeepAlive = false;
if(m_server == null || !m_server.HTTPDRunning)
{
httpResponse.StatusCode = (int)HttpStatusCode.NotFound;
return;
}
if (!httpRequest.QueryAsDictionary.TryGetValue("method", out string methods) || string.IsNullOrWhiteSpace(methods))
{
httpResponse.StatusCode = (int)HttpStatusCode.NotFound;
return;
}
string[] splited = methods.Split(new char[]{','});
string method = splited[0];
if (string.IsNullOrWhiteSpace(method))
{
httpResponse.StatusCode = (int)HttpStatusCode.NotFound;
return;
}
SimpleStreamMethod sh = m_server.TryGetIndexPHPMethodHandler(method);
if (sh == null)
{
httpResponse.StatusCode = (int)HttpStatusCode.NotFound;
return;
}
try
{
sh?.Invoke(httpRequest, httpResponse);
}
catch
{
httpResponse.StatusCode = (int)HttpStatusCode.InternalServerError;
}
}
}
/// <summary>
/// Handler to supply the current extended status of this sim to a user configured URI
/// Sends the statistical data in a json serialization