Example #1
0
        public override byte[] Handle(string path, Stream request,
                OSHttpRequest httpRequest, OSHttpResponse httpResponse)
        {
            XmlSerializer xs = new XmlSerializer(typeof (AssetBase));
            AssetBase asset = (AssetBase) xs.Deserialize(request);

            IGridRegistrationService urlModule =
                            m_registry.RequestModuleInterface<IGridRegistrationService>();
            if (urlModule != null)
                if (!urlModule.CheckThreatLevel("", m_regionHandle, "Asset_Update", ThreatLevel.Full))
                    return new byte[0];
            string[] p = SplitParams(path);
            if (p.Length > 1)
            {
                bool result =
                        m_AssetService.UpdateContent(p[1], asset.Data);

                xs = new XmlSerializer(typeof(bool));
                return WebUtils.SerializeResult(xs, result);
            }

            string id = m_AssetService.Store(asset);

            xs = new XmlSerializer(typeof(string));
            return WebUtils.SerializeResult(xs, id);
        }
        public override byte[] Handle(string path, Stream requestData,
                OSHttpRequest httpRequest, OSHttpResponse httpResponse)
        {
            // path = /wifi/...
            //m_log.DebugFormat("[Wifi]: path = {0}", path);
            //m_log.DebugFormat("[Wifi]: ip address = {0}", httpRequest.RemoteIPEndPoint);
            //foreach (object o in httpRequest.Query.Keys)
            //    m_log.DebugFormat("  >> {0}={1}", o, httpRequest.Query[o]);

            string result = string.Empty;
            try
            {
                Request request = WifiUtils.CreateRequest(string.Empty, httpRequest);
                Diva.Wifi.Environment env = new Diva.Wifi.Environment(request);

                result = m_WebApp.Services.LogoutRequest(env);

                httpResponse.ContentType = "text/html";
            }
            catch (Exception e)
            {
                m_log.DebugFormat("[LOGOUT HANDLER]: Exception {0}: {1}", e.Message, e.StackTrace);
            }

            return WifiUtils.StringToBytes(result);

        }
        public override byte[] Handle(string path, Stream requestData,
                OSHttpRequest httpRequest, OSHttpResponse httpResponse)
        {
            string result = string.Empty;
            try
            {
                Request request = WifiUtils.CreateRequest(string.Empty, httpRequest);
                Diva.Wifi.Environment env = new Diva.Wifi.Environment(request);

                string resource = GetParam(path);
                //m_log.DebugFormat("[XXX]: resource {0}", resource);
                if (resource.StartsWith("/data/simulators"))
                {
                    result = m_WebApp.Services.ConsoleSimulatorsRequest(env);
                    httpResponse.ContentType = "application/xml";
                }
                else if (resource.StartsWith("/heartbeat"))
                {
                    result = m_WebApp.Services.ConsoleHeartbeat(env);
                    httpResponse.ContentType = "application/xml";
                }
                else
                {
                    result = m_WebApp.Services.ConsoleRequest(env);
                    httpResponse.ContentType = "text/html";
                }
            }
            catch (Exception e)
            {
                m_log.DebugFormat("[CONSOLE HANDLER]: Exception {0}: {1}", e.Message, e.StackTrace);
            }

            return WifiUtils.StringToBytes(result);
        }
Example #4
0
        public override byte[] Handle(string path, Stream requestData,
                OSHttpRequest httpRequest, OSHttpResponse httpResponse)
        {
            byte[] result = new byte[0];

            StreamReader sr = new StreamReader(requestData);
            string body = sr.ReadToEnd();
            sr.Close();
            body = body.Trim();

            Dictionary<string, object> request =
                        WebUtils.ParseQueryString(body);

            if (!request.ContainsKey("METHOD"))
                return result; //No method, no work

            string method = request["METHOD"].ToString();
            switch(method)
            {
                case "inform_neighbors_region_is_up":
                    return InformNeighborsRegionIsUp(request);
                case "inform_neighbors_region_is_down":
                    return InformNeighborsRegionIsDown(request);
                case "inform_neighbors_of_chat_message":
                    return InformNeighborsOfChatMessage(request);
                case "get_neighbors":
                    return GetNeighbors(request);
                default :
                    m_log.Warn("[NeighborHandlers]: Unknown method " + method);
                    break;
            }
            return result;
        }
        public override byte[] Handle(string path, Stream requestData,
                OSHttpRequest httpRequest, OSHttpResponse httpResponse)
        {
            StreamReader sr = new StreamReader(requestData);
            string body = sr.ReadToEnd();
            sr.Close();
            body = body.Trim();

            //m_log.DebugFormat("[XXX]: query String: {0}", body);

            try
            {
                Dictionary<string, object> request =
                        ServerUtils.ParseQueryString(body);

                if (!request.ContainsKey("METHOD"))
                    return FailureResult();

                string method = request["METHOD"].ToString();

                switch (method)
                {
                    case "report":
                        return Report(request);
                }
                m_log.DebugFormat("[PRESENCE HANDLER]: unknown method request: {0}", method);
            }
            catch (Exception e)
            {
                m_log.Debug("[PRESENCE HANDLER]: Exception {0}" + e);
            }

            return FailureResult();

        }
Example #6
0
        private string RESTGetUserProfile(string request, string path, string param, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
        {
            // Check IP Endpoint Access
            if (!TrustManager.Instance.IsTrustedPeer(httpRequest.RemoteIPEndPoint))
            {
                httpResponse.StatusCode = 403;
                return ("Access is denied for this IP Endpoint");
            }

            UUID id;
            UserProfileData userProfile;

            try
            {
                id = new UUID(param);
            }
            catch (Exception)
            {
                httpResponse.StatusCode = 500;
                return "Malformed Param [" + param + "]";
            }

            userProfile = m_userDataBaseService.GetUserProfile(id);

            if (userProfile == null)
            {
                httpResponse.StatusCode = 404;
                return "Not Found.";
            }

            return ProfileToXmlRPCResponse(userProfile).ToString();
        }
        public override byte[] Handle(string path, Stream requestData,
                OSHttpRequest httpRequest, OSHttpResponse httpResponse)
        {
            StreamReader sr = new StreamReader(requestData);
            string body = sr.ReadToEnd();
            sr.Close();
            body = body.Trim();

            //m_log.DebugFormat("[XXX]: query String: {0}", body);

            try
            {
                OSDMap map = WebUtils.GetOSDMap(body);
                if (map != null)
                {
                    return NewMessage(map);
                }
            }
            catch (Exception e)
            {
                m_log.WarnFormat("[GRID HANDLER]: Exception {0}", e);
            }

            return FailureResult();
        }
Example #8
0
        public bool ProcessInMsg(OSHttpRequest req, OSHttpResponse resp)
        {
            //                              0        1          2       3
            // http://simulator.com:9000/vwohttp/sessionid/methodname/param
            string[] urlparts = req.Url.AbsolutePath.Split(new char[] {'/'}, StringSplitOptions.RemoveEmptyEntries);

            UUID sessionID;
            // Check for session
            if (!UUID.TryParse(urlparts[1], out sessionID))
                return false;
            // Check we match session
            if (sessionID != SessionId)
                return false;

            string method = urlparts[2];

            string param = String.Empty;
            if (urlparts.Length > 3)
                param = urlparts[3];

            bool found;

            switch (method.ToLower())
            {
                case "textures":
                    found = ProcessTextureRequest(param, resp);
                    break;
                default:
                    found = false;
                    break;
            }

            return found;
        }
        public override byte[] Handle(string path, Stream requestData,
                OSHttpRequest httpRequest, OSHttpResponse httpResponse)
        {
            string resource = GetParam(path);
            //m_log.DebugFormat("[Wifi]: resource {0}", resource);
            resource = resource.Trim(WifiUtils.DirectorySeparatorChars);
            string resourcePath = System.IO.Path.Combine(m_LocalPath, resource);
            resourcePath = Uri.UnescapeDataString(resourcePath);

            string type = WifiUtils.GetContentType(resource);
            httpResponse.ContentType = type;
            //m_log.DebugFormat("[Wifi]: ContentType {0}", type);
            if (type.StartsWith("image"))
                return WifiUtils.ReadBinaryResource(resourcePath);

            if (type.StartsWith("application") || type.StartsWith("text"))
            {
                string res = WifiUtils.ReadTextResource(resourcePath, true);
                return WifiUtils.StringToBytes(res);
            }

            m_log.WarnFormat("[Wifi]: Could not find resource {0} in local path {1}", resource, m_LocalPath);
            httpResponse.ContentType = "text/plain";
            string result = "Boo!";
            return WifiUtils.StringToBytes(result);
        }
 public override byte[] Handle(string path, Stream request,
         OSHttpRequest httpRequest, OSHttpResponse httpResponse)
 {
     //Return the config map
     UTF8Encoding encoding = new UTF8Encoding();
     return encoding.GetBytes(OSDParser.SerializeJsonString(m_configMap));
 }
Example #11
0
        private string RESTGetUserProfile(string request, string path, string param, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
        {
            UUID id;
            UserProfileData userProfile;

            try
            {
                id = new UUID(param);
            }
            catch (Exception)
            {
                httpResponse.StatusCode = 500;
                return "Malformed Param [" + param + "]";
            }

            userProfile = m_userDataBaseService.GetUserProfile(id);

            if (userProfile == null)
            {
                httpResponse.StatusCode = 404;
                return "Not Found.";
            }

            return ProfileToXmlRPCResponse(userProfile).ToString();
        }
        public override byte[] Handle(string path, Stream request,
                OSHttpRequest httpRequest, OSHttpResponse httpResponse)
        {
            string[] p = SplitParams(path);

            if (p.Length > 0)
            {
                switch (p[0])
                {
                case "plain":
                    StreamReader sr = new StreamReader(request);
                    string body = sr.ReadToEnd();
                    sr.Close();

                    return DoPlainMethods(body);
                case "crypt":
                    byte[] buffer = new byte[request.Length];
                    long length = request.Length;
                    if (length > 16384)
                        length = 16384;
                    request.Read(buffer, 0, (int)length);

                    return DoEncryptedMethods(buffer);
                }
            }
            return new byte[0];
        }
        public override byte[] Handle(string path, Stream requestData,
                OSHttpRequest httpRequest, OSHttpResponse httpResponse)
        {
            // path = /wifi/...
            //m_log.DebugFormat("[Wifi]: path = {0}", path);
            //m_log.DebugFormat("[Wifi]: ip address = {0}", httpRequest.RemoteIPEndPoint);
            //foreach (object o in httpRequest.Query.Keys)
            //    m_log.DebugFormat("  >> {0}={1}", o, httpRequest.Query[o]);
            httpResponse.ContentType = "text/html";
            string resource = GetParam(path);
            m_log.DebugFormat("[USER ACCOUNT HANDLER GET]: resource {0}", resource);

            Request request = WifiUtils.CreateRequest(string.Empty, httpRequest);
            Diva.Wifi.Environment env = new Diva.Wifi.Environment(request);

            string result = string.Empty;
            UUID userID = UUID.Zero;
            if (resource == string.Empty || resource == "/")
            {
                result = m_WebApp.Services.NewAccountGetRequest(env);
            }
            else
            {
                UUID.TryParse(resource.Trim(new char[] {'/'}), out userID);
                result = m_WebApp.Services.UserAccountGetRequest(env, userID);
            }

            return WifiUtils.StringToBytes(result);

        }
Example #14
0
        public override byte[] Handle(string path, Stream requestData,
                OSHttpRequest httpRequest, OSHttpResponse httpResponse)
        {
            StreamReader sr = new StreamReader(requestData);
            string body = sr.ReadToEnd();
            sr.Close();
            body = body.Trim();

            //m_log.DebugFormat("[XXX]: query String: {0}", body);
            string method = string.Empty;
            try
            {
                Dictionary<string, object> request = new Dictionary<string, object>();
                request = WebUtils.ParseQueryString(body);
                if (request.Count == 1)
                    request = WebUtils.ParseXmlResponse(body);
                object value = null;
                request.TryGetValue("<?xml version", out value);
                if (value != null)
                    request = WebUtils.ParseXmlResponse(body);

                return ProcessAddCAP(request);
            }
            catch (Exception)
            {
            }

            return null;

        }
 public override byte[] Handle(string path, Stream request,
         OSHttpRequest httpRequest, OSHttpResponse httpResponse)
 {
     // Not implemented yet
     httpResponse.StatusCode = (int)HttpStatusCode.NotImplemented;
     return new byte[] { };
 }
Example #16
0
        public void Init()
        {
            TestHttpRequest threq0 = new TestHttpRequest("utf-8", "text/xml", "OpenSim Test Agent", "192.168.0.1", "4711", 
                                                       new string[] {"text/xml"}, 
                                                       ConnectionType.KeepAlive, 4711, 
                                                       new Uri("http://127.0.0.1/admin/inventory/Dr+Who/Tardis"));
            threq0.Method = "GET";
            threq0.HttpVersion = HttpHelper.HTTP10;

            TestHttpRequest threq1 = new TestHttpRequest("utf-8", "text/xml", "OpenSim Test Agent", "192.168.0.1", "4711", 
                                                       new string[] {"text/xml"}, 
                                                       ConnectionType.KeepAlive, 4711, 
                                                       new Uri("http://127.0.0.1/admin/inventory/Dr+Who/Tardis?a=0&b=1&c=2"));
            threq1.Method = "POST";
            threq1.HttpVersion = HttpHelper.HTTP11;
            threq1.Headers["x-wuff"] = "wuffwuff";
            threq1.Headers["www-authenticate"] = "go away";
            
            req0 = new OSHttpRequest(new TestHttpClientContext(false), threq0);
            req1 = new OSHttpRequest(new TestHttpClientContext(false), threq1);

            rsp0 = new OSHttpResponse(new TestHttpResponse());

            ipEP0 = new IPEndPoint(IPAddress.Parse("192.168.0.1"), 4711);

        }
Example #17
0
        public override byte[] Handle(string path, Stream requestData,
                OSHttpRequest httpRequest, OSHttpResponse httpResponse)
        {
            httpResponse.ContentType = "image/jpeg";

//            StreamReader sr = new StreamReader(requestData);
//            string body = sr.ReadToEnd();
//            sr.Close();
//            body = body.Trim();

            try
            {
                lock (m_RequestLock)
                {
                    Dictionary<string, object> request =
                            new Dictionary<string, object>();
                    foreach (string name in httpRequest.QueryString)
                        request[name] = httpRequest.QueryString[name];

                    return SendWorldView(request);
                }
            }
            catch (Exception e)
            {
                m_log.Debug("[WORLDVIEW]: Exception: " + e.ToString());
            }

            return new Byte[0];
        }
Example #18
0
        public override byte[] Handle(string path, Stream request,
                                      OSHttpRequest httpRequest, OSHttpResponse httpResponse)
        {
            string param = GetParam(path);
            byte[] result = new byte[] {};
            try
            {
                string[] p = param.Split(new char[] {'/', '?', '&'}, StringSplitOptions.RemoveEmptyEntries);

                if (p.Length > 0)
                {
                    UUID assetID = UUID.Zero;

                    if (!UUID.TryParse(p[0], out assetID))
                    {
                        m_log.InfoFormat(
                            "[REST]: GET:/presence ignoring request with malformed UUID {0}", p[0]);
                        return result;
                    }

                }
            }
            catch (Exception e)
            {
                m_log.Error(e.ToString());
            }
            return result;
        }
 public override byte[] Handle(string path, Stream request,
         OSHttpRequest httpRequest, OSHttpResponse httpResponse)
 {
     // Not implemented yet
     Console.WriteLine("--- Get region --- " + path);
     httpResponse.StatusCode = (int)HttpStatusCode.NotImplemented;
     return new byte[] { };
 }
Example #20
0
        public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
        {
            byte[] data = ReadFully(request);
            string param = GetParam(path);
            string responseString = m_method(data, path, param);

            return Encoding.UTF8.GetBytes(responseString);
        }
        public override byte[] Handle(string path, Stream requestData,
                OSHttpRequest httpRequest, OSHttpResponse httpResponse)
        {
            // path = /wifi/...
            //m_log.DebugFormat("[Wifi]: path = {0}", path);
            //m_log.DebugFormat("[Wifi]: ip address = {0}", httpRequest.RemoteIPEndPoint);
            //foreach (object o in httpRequest.Query.Keys)
            //    m_log.DebugFormat("  >> {0}={1}", o, httpRequest.Query[o]);

            string resource = GetParam(path);
            //m_log.DebugFormat("[Wifi]: resource {0}", resource);
            resource = Uri.UnescapeDataString(resource).Trim(WifiUtils.DirectorySeparatorChars);

            Request request = WifiUtils.CreateRequest(resource, httpRequest);
            Diva.Wifi.Environment env = new Diva.Wifi.Environment(request);

            if (resource == string.Empty || resource.StartsWith("index."))
            {
                if (m_WebApp.StatisticsUpdateInterval != TimeSpan.Zero)
                    m_WebApp.Services.ComputeStatistics();

                httpResponse.ContentType = "text/html";

                return WifiUtils.StringToBytes(m_WebApp.Services.DefaultRequest(env));
            }
            else
            {
                string resourcePath = System.IO.Path.Combine(WifiUtils.DocsPath, resource);
                string type = WifiUtils.GetContentType(resource);
                httpResponse.ContentType = type;
                //m_log.DebugFormat("[Wifi]: ContentType {0}", type);
                if (type.StartsWith("image"))
                    return WifiUtils.ReadBinaryResource(resourcePath);

                if (type.StartsWith("application"))
                {
                    string res = WifiUtils.ReadTextResource(resourcePath, true);
                    return WifiUtils.StringToBytes(res);
                }
                if (type.StartsWith("text"))
                {
                    if (m_WebApp.StatisticsUpdateInterval != TimeSpan.Zero)
                        m_WebApp.Services.ComputeStatistics();

                    resourcePath = Localization.LocalizePath(env, resource);
                    Processor p = new Processor(m_WebApp.WifiScriptFace, env);
                    string res = p.Process(WifiUtils.ReadTextResource(resourcePath));
                    if (res == string.Empty)
                        res = m_WebApp.Services.DefaultRequest(env);
                    return WifiUtils.StringToBytes(res);
                }
            }

            httpResponse.ContentType = "text/plain";
            string result = "Boo!";
            return WifiUtils.StringToBytes(result);
        }
        public override byte[] Handle(string path, Stream requestData,
                OSHttpRequest httpRequest, OSHttpResponse httpResponse)
        {
            StreamReader sr = new StreamReader(requestData);
            string body = sr.ReadToEnd();
            sr.Close();
            body = body.Trim();

            //m_log.DebugFormat("[XXX]: query String: {0}", body);

            try
            {
                Dictionary<string, object> request =
                        ServerUtils.ParseQueryString(body);

                if (!request.ContainsKey("METHOD"))
                    return FailureResult();

                string method = request["METHOD"].ToString();

                switch (method)
                {
                    case "register":
                        return Register(request);

                    case "deregister":
                        return Deregister(request);

                    case "get_neighbours":
                        return GetNeighbours(request);

                    case "get_region_by_uuid":
                        return GetRegionByUUID(request);

                    case "get_region_by_position":
                        return GetRegionByPosition(request);

                    case "get_region_by_name":
                        return GetRegionByName(request);

                    case "get_regions_by_name":
                        return GetRegionsByName(request);

                    case "get_region_range":
                        return GetRegionRange(request);

                }
                m_log.DebugFormat("[GRID HANDLER]: unknown method {0} request {1}", method.Length, method);
            }
            catch (Exception e)
            {
                m_log.DebugFormat("[GRID HANDLER]: Exception {0}", e);
            }

            return FailureResult();

        }
Example #23
0
 byte[] GetHandler(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
 {
     string username;
     if (server.AuthenticateRequest(httpRequest, httpResponse, out username))
     {
         System.Net.HttpStatusCode status = server.GET(httpResponse, httpRequest.Url.AbsolutePath, username);
         httpResponse.StatusCode = (int)status;
     }
     return OpenMetaverse.Utils.EmptyBytes;
 }
Example #24
0
 public static DepthHeader ParseDepth(OSHttpRequest request)
 {
     //Clients may submit a Depth Header with a value of "0", "1", "1,noroot" or "infinity".
     //A PROPFIND Method without a Depth Header acts as if a Depth Header value of "infinity" was included.
     string[] depths = request.Headers.GetValues("depth");
     if (depths == null)
     {
         //no depth header found
         throw new ArgumentException("No depth header found");
     }
     if (depths.Length == 1)
     {
         if (depths[0].ToLower() == "infinity")
         {
             return DepthHeader.Infinity;
         }
         else if (depths[0] == "1")
         {
             return DepthHeader.One;
         }
         else if (depths[0] == "0")
         {
             return DepthHeader.Zero;
         }
         else
         {
             //Unknown value
             Console.WriteLine("Unknown depth value " + depths[0]);
             throw new ArgumentException("Unknown value in depth header");
         }
     }
     else if (depths.Length == 2)
     {
         //noroot stuff
         if (depths[0].ToLower() == "infinity" && depths[1].ToLower() == "noroot")
         {
             return DepthHeader.InfinityNoRoot;
         }
         else if (depths[0] == "1" && depths[1].ToLower() == "noroot")
         {
             return DepthHeader.OneNoRoot;
         }
         else
         {
             //Unknown value
             Console.WriteLine("Unknown depth values {0}, {1}", depths[0], depths[1]);
             throw new ArgumentException("Unknown values in depth header");
         }
     }
     else
     {
         //something awful has happened. depth should not contain more than two values
         throw new ArgumentException("More than two arquments in Depth header");
     }
 }
        public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
        {
            Encoding encoding = Encoding.UTF8;
            StreamReader streamReader = new StreamReader(request, encoding);

            string requestBody = streamReader.ReadToEnd();
            streamReader.Close();

            string param = GetParam(path);
            return m_restMethod(requestBody, path, param, httpRequest, httpResponse);
        }
        public override byte[] Handle(string path, Stream requestData,
                OSHttpRequest httpRequest, OSHttpResponse httpResponse)
        {
            StreamReader sr = new StreamReader(requestData);
            string body = sr.ReadToEnd();
            sr.Close();
            body = body.Trim();

            //m_log.DebugFormat("[XXX]: query String: {0}", body);

            try
            {
                Dictionary<string, object> request =
                        WebUtils.ParseQueryString(body);

                if (!request.ContainsKey("METHOD"))
                    return FailureResult();

                string method = request["METHOD"].ToString();

                IGridRegistrationService urlModule =
                            m_registry.RequestModuleInterface<IGridRegistrationService>();
                switch (method)
                {
                    case "getavatar":
                        if (urlModule != null)
                            if (!urlModule.CheckThreatLevel(m_SessionID, method, ThreatLevel.Low))
                                return FailureResult();
                        return GetAvatar(request);
                    case "setavatar":
                        if (urlModule != null)
                            if (!urlModule.CheckThreatLevel(m_SessionID, method, ThreatLevel.High))
                                return FailureResult();
                        return SetAvatar(request);
                    case "resetavatar":
                        if (urlModule != null)
                            if (!urlModule.CheckThreatLevel(m_SessionID, method, ThreatLevel.High))
                                return FailureResult();
                        return ResetAvatar(request);
                    case "cachewearabledata":
                        if (urlModule != null)
                            if (!urlModule.CheckThreatLevel(m_SessionID, method, ThreatLevel.Medium))
                                return FailureResult();
                        return CacheWearableData(request);
                }
                m_log.DebugFormat("[AVATAR HANDLER]: unknown method request: {0}", method);
            }
            catch (Exception e)
            {
                m_log.Debug("[AVATAR HANDLER]: Exception {0}" + e);
            }

            return FailureResult();
        }
        public override byte[] Handle(string path, Stream requestData,
                                      OSHttpRequest httpRequest, OSHttpResponse httpResponse)
        {
            StreamReader sr = new StreamReader(requestData);
            string body = sr.ReadToEnd();
            sr.Close();
            body = body.Trim();

            //MainConsole.Instance.DebugFormat("[XXX]: query String: {0}", body);

            try
            {
                Dictionary<string, object> request =
                    WebUtils.ParseQueryString(body);

                if (!request.ContainsKey("METHOD"))
                    return FailureResult();
                IGridRegistrationService urlModule =
                    m_registry.RequestModuleInterface<IGridRegistrationService>();

                string method = request["METHOD"].ToString();
                            
                switch (method)
                {
                    case "AddAbuseReport":
                        if (urlModule != null)
                            if (!urlModule.CheckThreatLevel(m_SessionID, method, ThreatLevel.Low))
                                return FailureResult();
                        return AddAbuseReport(request);
                    case "GetAbuseReport":
                        if (urlModule != null)
                            if (!urlModule.CheckThreatLevel(m_SessionID, method, ThreatLevel.High))
                                return FailureResult();
                        return GetAbuseReport(request);
                    case "UpdateAbuseReport":
                        if (urlModule != null)
                            if (!urlModule.CheckThreatLevel(m_SessionID, method, ThreatLevel.High))
                                return FailureResult();
                        return UpdateAbuseReport(request);
                    case "UpdateAbuseReports":
                        if (urlModule != null)
                            if (!urlModule.CheckThreatLevel(m_SessionID, method, ThreatLevel.High))
                                return FailureResult();
                        return GetAbuseReports(request);
                }
                MainConsole.Instance.DebugFormat("[ABUSEREPORT HANDLER]: unknown method {0} request {1}", method.Length, method);
            }
            catch (Exception e)
            {
                MainConsole.Instance.DebugFormat("[ABUSEREPORT HANDLER]: Exception {0}", e);
            }

            return FailureResult();
        }
        public override byte[] Handle(string path, Stream requestData,
                OSHttpRequest httpRequest, OSHttpResponse httpResponse)
        {
            StreamReader sr = new StreamReader(requestData);
            string body = sr.ReadToEnd();
            sr.Close();
            body = body.Trim();

            //m_log.DebugFormat("[XXX]: query String: {0}", body);

            try
            {
                Dictionary<string, object> request =
                        WebUtils.ParseQueryString(body);

                if (!request.ContainsKey("METHOD"))
                    return FailureResult();

                string method = request["METHOD"].ToString();

                IGridRegistrationService urlModule =
                            m_registry.RequestModuleInterface<IGridRegistrationService>();

                switch (method)
                {
                    case "getfriends":
                        if (urlModule != null)
                            if (!urlModule.CheckThreatLevel("", m_regionHandle, method, ThreatLevel.Low))
                                return FailureResult();
                        return GetFriends(request);

                    case "storefriend":
                        if (urlModule != null)
                            if (!urlModule.CheckThreatLevel("", m_regionHandle, method, ThreatLevel.High))
                                return FailureResult();
                        return StoreFriend(request);

                    case "deletefriend":
                        if (urlModule != null)
                            if (!urlModule.CheckThreatLevel("", m_regionHandle, method, ThreatLevel.High))
                                return FailureResult();
                        return DeleteFriend(request);

                }
                m_log.DebugFormat("[FRIENDS HANDLER]: unknown method {0} request {1}", method.Length, method);
            }
            catch (Exception e)
            {
                m_log.DebugFormat("[FRIENDS HANDLER]: Exception {0}", e);
            }

            return FailureResult();

        }
        public override byte[] Handle(string path, Stream request,
                                      OSHttpRequest httpRequest, OSHttpResponse httpResponse)
        {
            byte[] result = new byte[] { };

            string[] p = SplitParams(path);

            if (p.Length > 0)
            {
                UUID assetID;
                
                if (!UUID.TryParse(p[0], out assetID))
                {
                    m_log.DebugFormat(
                        "[REST]: GET:/asset ignoring request with malformed UUID {0}", p[0]);
                    return result;
                }

                if (StatsManager.AssetStats != null)
                {
                    StatsManager.AssetStats.AddRequest();
                }

                AssetBase asset = GetAsset(assetID); 

                if (asset != null)
                {
                    if (p.Length > 1 && p[1] == "data")
                    {
                        httpResponse.StatusCode = (int)HttpStatusCode.OK;
                        httpResponse.ContentType = SLAssetTypeToContentType(asset.Type);
                        result = asset.Data;
                    }
                    else
                    {
                        result = GetXml(asset);
                    }
                }
                else
                {
                    m_log.DebugFormat("[REST]: GET:/asset failed to find {0}", assetID);
                    
                    httpResponse.StatusCode = (int)HttpStatusCode.NotFound;
                    
                    if (StatsManager.AssetStats != null)
                    {
                        StatsManager.AssetStats.AddNotFoundRequest();
                    }
                }
            }

            return result;
        }
Example #30
0
        byte[] PutHandler(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
        {
            string username;
            if (server.AuthenticateRequest(httpRequest, httpResponse, out username))
            {
                string[] ifHeaders = httpRequest.Headers.GetValues("If");
                System.Net.HttpStatusCode status = server.PutResource(httpRequest, httpRequest.Url.AbsolutePath, username, ifHeaders);
                httpResponse.StatusCode = (int)status;
            }

            return OpenMetaverse.Utils.EmptyBytes;
        }
Example #31
0
 /// <summary>
 ///     Instantiate an OSHttpResponse object from an OSHttpRequest
 ///     object.
 /// </summary
 /// <param name="req">Incoming OSHttpRequest to which we are
 /// replying</param>
 public OSHttpResponse(OSHttpRequest req)
 {
     _httpResponse      = new HttpResponse(req.IHttpClientContext, req.IHttpRequest);
     _httpClientContext = req.IHttpClientContext;
 }
Example #32
0
        public void Engine()
        {
            OSHttpRequest req = null;

            while (true)
            {
                try
                {
                    // dequeue an OSHttpRequest from OSHttpServer's
                    // request queue
                    req = _queue.Dequeue();

                    // get a copy of the list of registered handlers
                    List <OSHttpHandler> handlers = _server.OSHttpHandlers;

                    // prune list and have it sorted from most
                    // specific to least specific
                    handlers = MatchHandlers(req, handlers);

                    // process req: we try each handler in turn until
                    // we are either out of handlers or get back a
                    // Pass or Done
                    OSHttpHandlerResult rc = OSHttpHandlerResult.Unprocessed;
                    foreach (OSHttpHandler h in handlers)
                    {
                        rc = h.Process(req);

                        // Pass: handler did not process the request,
                        // try next handler
                        if (OSHttpHandlerResult.Pass == rc)
                        {
                            continue;
                        }

                        // Handled: handler has processed the request
                        if (OSHttpHandlerResult.Done == rc)
                        {
                            break;
                        }

                        // hmm, something went wrong
                        throw new Exception(String.Format("[{0}] got unexpected OSHttpHandlerResult {1}", EngineID, rc));
                    }

                    if (OSHttpHandlerResult.Unprocessed == rc)
                    {
                        _log.InfoFormat("[{0}] OSHttpHandler: no handler registered for {1}", EngineID, req);

                        // set up response header
                        OSHttpResponse resp = new OSHttpResponse(req);
                        resp.StatusCode        = (int)OSHttpStatusCode.ClientErrorNotFound;
                        resp.StatusDescription = String.Format("no handler on call for {0}", req);
                        resp.ContentType       = "text/html";

                        // add explanatory message
                        StreamWriter body = new StreamWriter(resp.Body);
                        body.WriteLine("<html>");
                        body.WriteLine("<header><title>Ooops...</title><header>");
                        body.WriteLine(String.Format("<body><p>{0}</p></body>", resp.StatusDescription));
                        body.WriteLine("</html>");
                        body.Flush();

                        // and ship it back
                        resp.Send();
                    }
                }
                catch (Exception e)
                {
                    _log.DebugFormat("[{0}] OSHttpHandler problem: {1}", EngineID, e.ToString());
                    _log.ErrorFormat("[{0}] OSHttpHandler problem: {1}", EngineID, e.Message);
                }
            }
        }
Example #33
0
        protected List <OSHttpHandler> MatchHandlers(OSHttpRequest req, List <OSHttpHandler> handlers)
        {
            Dictionary <OSHttpHandler, int> scoredHandlers = new Dictionary <OSHttpHandler, int>();

            _log.DebugFormat("[{0}] MatchHandlers for {1}", EngineID, req);
            foreach (OSHttpHandler h in handlers)
            {
                // initial anchor
                scoredHandlers[h] = 0;

                // first, check whether IPEndPointWhitelist applies
                // and, if it does, whether client is on that white
                // list.
                if (null != h.IPEndPointWhitelist)
                {
                    // TODO: following code requires code changes to
                    // HttpServer.HttpRequest to become functional

                    IPEndPoint remote = req.RemoteIPEndPoint;
                    if (null != remote)
                    {
                        Match epm = h.IPEndPointWhitelist.Match(remote.ToString());
                        if (!epm.Success)
                        {
                            scoredHandlers.Remove(h);
                            continue;
                        }
                    }
                }

                if (null != h.Method)
                {
                    Match m = h.Method.Match(req.HttpMethod);
                    if (!m.Success)
                    {
                        scoredHandlers.Remove(h);
                        continue;
                    }
                    scoredHandlers[h]++;
                }

                // whitelist ok, now check path
                if (null != h.Path)
                {
                    Match m = h.Path.Match(req.RawUrl);
                    if (!m.Success)
                    {
                        scoredHandlers.Remove(h);
                        continue;
                    }
                    scoredHandlers[h] += m.ToString().Length;
                }

                // whitelist & path ok, now check query string
                if (null != h.Query)
                {
                    int queriesMatch = MatchOnNameValueCollection(req.QueryString, h.Query);
                    if (0 == queriesMatch)
                    {
                        _log.DebugFormat("[{0}] request {1}", EngineID, req);
                        _log.DebugFormat("[{0}] dropping handler {1}", EngineID, h);

                        scoredHandlers.Remove(h);
                        continue;
                    }
                    scoredHandlers[h] += queriesMatch;
                }

                // whitelist, path, query string ok, now check headers
                if (null != h.Headers)
                {
                    int headersMatch = MatchOnNameValueCollection(req.Headers, h.Headers);
                    if (0 == headersMatch)
                    {
                        _log.DebugFormat("[{0}] request {1}", EngineID, req);
                        _log.DebugFormat("[{0}] dropping handler {1}", EngineID, h);

                        scoredHandlers.Remove(h);
                        continue;
                    }
                    scoredHandlers[h] += headersMatch;
                }
            }

            List <OSHttpHandler> matchingHandlers = new List <OSHttpHandler>(scoredHandlers.Keys);

            matchingHandlers.Sort(delegate(OSHttpHandler x, OSHttpHandler y)
            {
                return(scoredHandlers[x] - scoredHandlers[y]);
            });
            LogDumpHandlerList(matchingHandlers);
            return(matchingHandlers);
        }