Data describing an external URL set up by a script.
Beispiel #1
0
        public UUID RequestSecureURL(IScriptModule engine, SceneObjectPart host, UUID itemID)
        {
            UUID urlcode = UUID.Random();
            string url = String.Empty;

            if (m_HttpsServer == null)
            {
                engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_DENIED", "" });
                return urlcode;
            }

            lock (m_UrlMap)
            {
                if (m_UrlMap.Count >= m_TotalUrls)
                {
                    engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_DENIED", "" });
                    return urlcode;
                }

                url = m_HttpsServer.ServerURI + "/lslhttps/" + urlcode.ToString() + "/";

                UrlData urlData = new UrlData
                {
                    hostID = host.UUID,
                    itemID = itemID,
                    engine = engine,
                    url = url,
                    urlcode = urlcode,
                    requests = new List<UUID>()
                };

                m_UrlMap[url] = urlData;
            }

            string uri = "/lslhttps/" + urlcode.ToString() + "/";
            m_HttpServer.AddStreamHandler(new AsyncRequestHandler("POST", uri, AsyncHttpRequest));
            m_HttpServer.AddStreamHandler(new AsyncRequestHandler("GET", uri, AsyncHttpRequest));

            engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_GRANTED", url });

            return urlcode;
        }
Beispiel #2
0
        private void RemoveUrl(UrlData data)
        {
            string url = data.url;
            bool is_ssl = url.Contains("lslhttps");
            string protocol = (is_ssl ? "/lslhttps/" : "/lslhttp/");

            m_HttpServer.RemoveStreamHandler("POST", protocol + data.urlcode.ToString() + "/");
            m_HttpServer.RemoveStreamHandler("GET", protocol + data.urlcode.ToString() + "/");
        }
Beispiel #3
0
        public UUID RequestSecureURL(IScriptModule engine, SceneObjectPart host, UUID itemID)
        {
            UUID urlcode = UUID.Random();

            if (m_HttpsServer == null)
            {
                engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_DENIED", "" });
                return urlcode;
            }

            lock (m_UrlMap)
            {
                if (m_UrlMap.Count >= m_TotalUrls)
                {
                    engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_DENIED", "" });
                    return urlcode;
                }
                string url = "https://" + m_ExternalHostNameForLSL + ":" + m_HttpsServer.Port.ToString() + "/lslhttps/" + urlcode.ToString() + "/";

                UrlData urlData = new UrlData();
                urlData.hostID = host.UUID;
                urlData.itemID = itemID;
                urlData.engine = engine;
                urlData.url = url;
                urlData.urlcode = urlcode;
                urlData.requests = new Dictionary<UUID, RequestData>();

                m_UrlMap[url] = urlData;
                
                string uri = "/lslhttps/" + urlcode.ToString() + "/";
               
                m_HttpsServer.AddPollServiceHTTPHandler(
                    uri,
                    new PollServiceEventArgs(HttpRequestHandler, HasEvents, GetEvents, NoEvents, urlcode));

                m_log.DebugFormat(
                    "[URL MODULE]: Set up incoming secure request url {0} for {1} in {2} {3}",
                    uri, itemID, host.Name, host.LocalId);

                engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_GRANTED", url });
            }

            return urlcode;
        }
Beispiel #4
0
 private void RemoveUrl(UrlData data)
 {
     m_HttpServer.RemoveHTTPHandler("", "/lslhttp/" + data.urlcode.ToString() + "/");
 }
Beispiel #5
0
        public UUID RequestURL(IScriptModule engine, SceneObjectPart host, UUID itemID)
        {
            UUID urlcode = UUID.Random();

            lock (m_UrlMap)
            {
                if (m_UrlMap.Count >= m_TotalUrls)
                {
                    engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_DENIED", "" });
                    return urlcode;
                }
                string url = "http://"+System.Environment.MachineName+":"+m_HttpServer.Port.ToString()+"/lslhttp/"+urlcode.ToString()+"/";

                UrlData urlData = new UrlData();
                urlData.hostID = host.UUID;
                urlData.itemID = itemID;
                urlData.engine = engine;
                urlData.url = url;
                urlData.urlcode = urlcode;
                urlData.requests = new Dictionary<UUID, RequestData>();

                m_UrlMap[url] = urlData;

                m_HttpServer.AddHTTPHandler("/lslhttp/"+urlcode.ToString()+"/", HttpRequestHandler);

                engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_GRANTED", url });
            }

            return urlcode;
        }
Beispiel #6
0
        public UUID RequestURL(IScriptModule engine, SceneObjectPart host, UUID itemID)
        {
            UUID urlcode = UUID.Random();

            lock (m_UrlMap)
            {
                if (m_UrlMap.Count >= m_TotalUrls)
                {
                    engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_DENIED", "" });
                    return urlcode;
                }
                string url = "http://" + m_ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + "/lslhttp/" + urlcode.ToString() + "/";

                UrlData urlData = new UrlData();
                urlData.hostID = host.UUID;
                urlData.itemID = itemID;
                urlData.engine = engine;
                urlData.url = url;
                urlData.urlcode = urlcode;
                urlData.requests = new Dictionary<UUID, RequestData>();
                
                m_UrlMap[url] = urlData;
                
                string uri = "/lslhttp/" + urlcode.ToString() + "/";
               
                m_HttpServer.AddPollServiceHTTPHandler(
                    uri,
                    new PollServiceEventArgs(HttpRequestHandler, HasEvents, GetEvents, NoEvents, urlcode));

                engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_GRANTED", url });
            }

            return urlcode;
        }
 private void RemoveUrl(UrlData data)
 {
     if (data.isSsl)
         m_HttpsServer.RemoveHTTPHandler("", "/lslhttps/"+data.urlcode.ToString()+"/");
     else
         m_HttpServer.RemoveHTTPHandler("", "/lslhttp/"+data.urlcode.ToString()+"/");
 }
Beispiel #8
0
        public UUID RequestSecureURL(IScriptModule engine, SceneObjectPart host, UUID itemID)
        {
            UUID urlcode = UUID.Random();

            if (m_HttpsServer == null)
            {
                engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_DENIED", "" });
                return urlcode;
            }

            lock (m_UrlMap) /* this lock here is for preventing concurrency when checking for Url amount */
            {
                if (m_UrlMap.Count >= TotalUrls)
                {
                    engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_DENIED", "" });
                    return urlcode;
                }
                string url = "https://" + ExternalHostNameForLSL + ":" + m_HttpsServer.Port.ToString() + "/lslhttps/" + urlcode.ToString() + "/";

                UrlData urlData = new UrlData();
                urlData.hostID = host.UUID;
                urlData.itemID = itemID;
                urlData.engine = engine;
                urlData.url = url;
                urlData.urlcode = urlcode;
                urlData.requests = new ThreadedClasses.RwLockedDictionary<UUID, RequestData>();

                m_UrlMap[url] = urlData;
                
                string uri = "/lslhttps/" + urlcode.ToString() + "/";
               
                PollServiceEventArgs args 
                    = new PollServiceEventArgs(HttpRequestHandler, uri, HasEvents, GetEvents, NoEvents, urlcode, 25000);
                args.Type = PollServiceEventArgs.EventType.LslHttp;
                m_HttpsServer.AddPollServiceHTTPHandler(uri, args);

                m_log.DebugFormat(
                    "[URL MODULE]: Set up incoming secure request url {0} for {1} in {2} {3}",
                    uri, itemID, host.Name, host.LocalId);

                engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_GRANTED", url });
            }

            return urlcode;
        }
        public UUID RequestSecureURL(IScriptModule engine, SceneObjectPart host, UUID itemID, Hashtable options)
        {
            UUID urlcode = UUID.Random();

            if (m_HttpsServer == null)
            {
                engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_DENIED", "" });
                return urlcode;
            }

            lock (m_UrlMap)
            {
                if (m_UrlMap.Count >= TotalUrls)
                {
                    engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_DENIED", "" });
                    return urlcode;
                }
                string url = "https://" + ExternalHostNameForLSL + ":" + m_HttpsServer.Port.ToString() + "/lslhttps/" + urlcode.ToString() + "/";

                UrlData urlData = new UrlData();
                urlData.hostID = host.UUID;
                urlData.itemID = itemID;
                urlData.engine = engine;
                urlData.url = url;
                urlData.urlcode = urlcode;
                urlData.isSsl = true;
                urlData.requests = new Dictionary<UUID, RequestData>();
                urlData.allowXss = false;

                if (options != null && options["allowXss"] != null)
                    urlData.allowXss = true;
                
                m_UrlMap[url] = urlData;
                
                string uri = "/lslhttps/" + urlcode.ToString() + "/";
               
                PollServiceEventArgs args 
                    = new PollServiceEventArgs(HttpRequestHandler, uri, HasEvents, GetEvents, NoEvents, urlcode, 25000);
                args.Type = PollServiceEventArgs.EventType.LslHttp;
                m_HttpsServer.AddPollServiceHTTPHandler(uri, args);

//                m_log.DebugFormat(
//                    "[URL MODULE]: Set up incoming secure request url {0} for {1} in {2} {3}",
//                    uri, itemID, host.Name, host.LocalId);

                engine.PostScriptEvent(itemID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_GRANTED", url });
            }

            return urlcode;
        }
Beispiel #10
0
        public void HttpRequestHandler(UUID requestID, Hashtable request)
        {
            lock (request)
            {
                string uri = request["uri"].ToString();

                try
                {
                    Hashtable headers = (Hashtable)request["headers"];

//                    string uri_full = "http://" + m_ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + uri;// "/lslhttp/" + urlcode.ToString() + "/";

                    int    pos1    = uri.IndexOf("/");           // /lslhttp
                    int    pos2    = uri.IndexOf("/", pos1 + 1); // /lslhttp/
                    int    pos3    = uri.IndexOf("/", pos2 + 1); // /lslhttp/<UUID>/
                    string uri_tmp = uri.Substring(0, pos3 + 1);
                    //HTTP server code doesn't provide us with QueryStrings
                    string pathInfo;
                    string queryString;
                    queryString = "";

                    pathInfo = uri.Substring(pos3);

                    UrlData url = m_UrlMap["http://" + m_ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + uri_tmp];

                    //for llGetHttpHeader support we need to store original URI here
                    //to make x-path-info / x-query-string / x-script-url / x-remote-ip headers
                    //as per http://wiki.secondlife.com/wiki/LlGetHTTPHeader

                    RequestData requestData = new RequestData();
                    requestData.requestID   = requestID;
                    requestData.requestDone = false;
                    requestData.startTime   = System.Environment.TickCount;
                    requestData.uri         = uri;
                    if (requestData.headers == null)
                    {
                        requestData.headers = new Dictionary <string, string>();
                    }

                    foreach (DictionaryEntry header in headers)
                    {
                        string key   = (string)header.Key;
                        string value = (string)header.Value;
                        requestData.headers.Add(key, value);
                    }
                    foreach (DictionaryEntry de in request)
                    {
                        if (de.Key.ToString() == "querystringkeys")
                        {
                            System.String[] keys = (System.String[])de.Value;
                            foreach (String key in keys)
                            {
                                if (request.ContainsKey(key))
                                {
                                    string val = (String)request[key];
                                    queryString = queryString + key + "=" + val + "&";
                                }
                            }
                            if (queryString.Length > 1)
                            {
                                queryString = queryString.Substring(0, queryString.Length - 1);
                            }
                        }
                    }

                    //if this machine is behind DNAT/port forwarding, currently this is being
                    //set to address of port forwarding router
                    requestData.headers["x-remote-ip"]    = requestData.headers["remote_addr"];
                    requestData.headers["x-path-info"]    = pathInfo;
                    requestData.headers["x-query-string"] = queryString;
                    requestData.headers["x-script-url"]   = url.url;

                    //requestData.ev = new ManualResetEvent(false);
                    lock (url.requests)
                    {
                        url.requests.Add(requestID, requestData);
                    }
                    lock (m_RequestMap)
                    {
                        //add to request map
                        m_RequestMap.Add(requestID, url);
                    }

                    url.engine.PostScriptEvent(url.itemID, "http_request", new Object[] { requestID.ToString(), request["http-method"].ToString(), request["body"].ToString() });

                    //send initial response?
//                    Hashtable response = new Hashtable();

                    return;
                }
                catch (Exception we)
                {
                    //Hashtable response = new Hashtable();
                    m_log.Warn("[HttpRequestHandler]: http-in request failed");
                    m_log.Warn(we.Message);
                    m_log.Warn(we.StackTrace);
                }
            }
        }
Beispiel #11
0
 private void RemoveUrl(UrlData data)
 {
     m_HttpServer.RemoveHTTPHandler("", "/lslhttp/" + data.urlcode.ToString() + "/");
 }
Beispiel #12
0
        public UUID RequestURL (IScriptModule engine, ISceneChildEntity host, UUID itemID)
        {
            UUID urlcode = UUID.Random();

            lock (m_UrlMap)
            {
                if (m_UrlMap.Count >= m_TotalUrls)
                {
                    engine.PostScriptEvent(itemID, host.UUID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_DENIED", "" });
                    return urlcode;
                }
                string url = m_HttpServer.ServerURI + "/lslhttp/" + urlcode.ToString() + "/";

                UrlData urlData = new UrlData
                                      {
                                          hostID = host.UUID,
                                          itemID = itemID,
                                          engine = engine,
                                          url = url,
                                          urlcode = urlcode,
                                          requests = new Dictionary<UUID, RequestData>()
                                      };


                m_UrlMap[url] = urlData;
                
                string uri = "/lslhttp/" + urlcode.ToString() + "/";
               
                m_HttpServer.AddPollServiceHTTPHandler(uri,HandleHttpPoll,
                        new PollServiceEventArgs(HttpRequestHandler,HasEvents, GetEvents, NoEvents,
                            urlcode));

                engine.PostScriptEvent(itemID, host.UUID, "http_request", new Object[] { urlcode.ToString(), "URL_REQUEST_GRANTED", url });
            }

            return urlcode;
        }
Beispiel #13
0
        public void HttpRequestHandler(UUID requestID, Hashtable request)
        {
            lock (request)
            {
                string uri    = request["uri"].ToString();
                bool   is_ssl = uri.Contains("lslhttps");

                try
                {
                    Hashtable headers = (Hashtable)request["headers"];

//                    string uri_full = "http://" + ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + uri;// "/lslhttp/" + urlcode.ToString() + "/";

                    int pos1 = uri.IndexOf("/");           // /lslhttp
                    int pos2 = uri.IndexOf("/", pos1 + 1); // /lslhttp/
                    int pos3 = uri.IndexOf("/", pos2 + 1); // /lslhttp/urlcode

                    string uri_tmp = uri.Substring(0, pos3 + 1);
                    //HTTP server code doesn't provide us with QueryStrings
                    string pathInfo;
                    string queryString;
                    queryString = "";

                    pathInfo = uri.Substring(pos3);

                    UrlData url = null;
                    string  urlkey;
                    if (!is_ssl)
                    {
                        urlkey = "http://" + ExternalHostNameForLSL + ":" + m_HttpServer.Port.ToString() + uri_tmp;
                    }
                    //m_UrlMap[];
                    else
                    {
                        urlkey = "https://" + ExternalHostNameForLSL + ":" + m_HttpsServer.Port.ToString() + uri_tmp;
                    }

                    if (m_UrlMap.ContainsKey(urlkey))
                    {
                        url = m_UrlMap[urlkey];
                    }
                    else
                    {
                        //m_log.Warn("[HttpRequestHandler]: http-in request failed; no such url: "+urlkey.ToString());
                        return;
                    }

                    //for llGetHttpHeader support we need to store original URI here
                    //to make x-path-info / x-query-string / x-script-url / x-remote-ip headers
                    //as per http://wiki.secondlife.com/wiki/LlGetHTTPHeader

                    RequestData requestData = new RequestData();
                    requestData.requestID   = requestID;
                    requestData.requestDone = false;
                    requestData.startTime   = System.Environment.TickCount;
                    requestData.uri         = uri;
                    requestData.hostID      = url.hostID;
                    requestData.scene       = url.scene;
                    if (requestData.headers == null)
                    {
                        requestData.headers = new Dictionary <string, string>();
                    }

                    foreach (DictionaryEntry header in headers)
                    {
                        string key   = (string)header.Key;
                        string value = (string)header.Value;
                        requestData.headers.Add(key, value);
                        if (key == "cookie")
                        {
                            string[] parts = value.Split(new char[] { '=' });
                            if (parts[0] == "agni_sl_session_id" && parts.Length > 1)
                            {
                                string   cookie = Uri.UnescapeDataString(parts[1]);
                                string[] crumbs = cookie.Split(new char[] { ':' });
                                UUID     owner;
                                if (crumbs.Length == 2 && UUID.TryParse(crumbs[0], out owner))
                                {
                                    if (crumbs[1].Length == 32)
                                    {
                                        Scene scene = requestData.scene;
                                        if (scene != null)
                                        {
                                            SceneObjectPart host = scene.GetSceneObjectPart(requestData.hostID);
                                            if (host != null)
                                            {
                                                if (host.OwnerID == owner)
                                                {
                                                    requestData.allowResponseType = true;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    foreach (DictionaryEntry de in request)
                    {
                        if (de.Key.ToString() == "querystringkeys")
                        {
                            System.String[] keys = (System.String[])de.Value;
                            foreach (String key in keys)
                            {
                                if (request.ContainsKey(key))
                                {
                                    string val = (String)request[key];
                                    if (key != "")
                                    {
                                        queryString = queryString + key + "=" + val + "&";
                                    }
                                    else
                                    {
                                        queryString = queryString + val + "&";
                                    }
                                }
                            }
                            if (queryString.Length > 1)
                            {
                                queryString = queryString.Substring(0, queryString.Length - 1);
                            }
                        }
                    }

                    //if this machine is behind DNAT/port forwarding, currently this is being
                    //set to address of port forwarding router
                    requestData.headers["x-remote-ip"]    = requestData.headers["remote_addr"];
                    requestData.headers["x-path-info"]    = pathInfo;
                    requestData.headers["x-query-string"] = queryString;
                    requestData.headers["x-script-url"]   = url.url;

                    //requestData.ev = new ManualResetEvent(false);
                    lock (url.requests)
                    {
                        url.requests.Add(requestID, requestData);
                    }
                    lock (m_RequestMap)
                    {
                        //add to request map
                        m_RequestMap.Add(requestID, url);
                    }

                    url.engine.PostScriptEvent(url.itemID, "http_request", new Object[] { requestID.ToString(), request["http-method"].ToString(), request["body"].ToString() });

                    //send initial response?
//                    Hashtable response = new Hashtable();

                    return;
                }
                catch (Exception we)
                {
                    //Hashtable response = new Hashtable();
                    m_log.Warn("[HttpRequestHandler]: http-in request failed");
                    m_log.Warn(we.Message);
                    m_log.Warn(we.StackTrace);
                }
            }
        }