diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs index c0e715d20f..12afb76e6d 100644 --- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs @@ -105,6 +105,7 @@ namespace OpenSim.Framework.Servers.HttpServer protected ConcurrentDictionary m_pollHandlers = new ConcurrentDictionary(); + protected ConcurrentDictionary m_indexPHPmethods = new ConcurrentDictionary(); protected Dictionary m_WebSocketHandlers = new Dictionary(); @@ -535,6 +536,24 @@ namespace OpenSim.Framework.Servers.HttpServer return true; } + public void AddIndexPHPMethodHandler(string key, SimpleStreamMethod sh) + { + m_indexPHPmethods.TryAdd(key, sh); + } + + public void RemoveIndexPHPMethodHandler(string key) + { + m_indexPHPmethods.TryRemove(key, out SimpleStreamMethod sh); + } + + public SimpleStreamMethod TryGetIndexPHPMethodHandler(string key) + { + if(m_indexPHPmethods.TryGetValue(key, out SimpleStreamMethod sh)) + return sh; + return null; + } + + public void OnRequest(object source, RequestEventArgs args) { RequestNumber++; diff --git a/OpenSim/Framework/Servers/HttpServer/Interfaces/IHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/Interfaces/IHttpServer.cs index 6f1379e843..6c89b40150 100644 --- a/OpenSim/Framework/Servers/HttpServer/Interfaces/IHttpServer.cs +++ b/OpenSim/Framework/Servers/HttpServer/Interfaces/IHttpServer.cs @@ -149,5 +149,8 @@ namespace OpenSim.Framework.Servers.HttpServer void RemoveJsonRPCHandler(string method); string GetHTTP404(); + void AddIndexPHPMethodHandler(string key, SimpleStreamMethod sh); + void RemoveIndexPHPMethodHandler(string key); + SimpleStreamMethod TryGetIndexPHPMethodHandler(string key); } } diff --git a/OpenSim/Region/Application/OpenSim.cs b/OpenSim/Region/Application/OpenSim.cs index 76a8604b55..d27f8b2db1 100755 --- a/OpenSim/Region/Application/OpenSim.cs +++ b/OpenSim/Region/Application/OpenSim.cs @@ -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) { diff --git a/OpenSim/Region/Application/OpenSimBase.cs b/OpenSim/Region/Application/OpenSimBase.cs index efe80e852a..a41045bb0b 100755 --- a/OpenSim/Region/Application/OpenSimBase.cs +++ b/OpenSim/Region/Application/OpenSimBase.cs @@ -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; + } + } + } + /// /// Handler to supply the current extended status of this sim to a user configured URI /// Sends the statistical data in a json serialization