Esempio n. 1
0
        public override void Respond(HttpApplication application, GlimpseConfiguration config)
        {
            if (!application.IsValidRequest(config, false, checkPath: false))
            {
                var data =
                    JsSerializer.Serialize(new { Error = true, Message = "You are not configured to access history." });
                JsonResponse(application, data);
                return;
            }

            var queue = application.Application[GlimpseConstants.JsonQueue] as Queue<GlimpseRequestMetadata>;
            if (queue != null)
            {
                var filteredQueue = from request in queue
                                    group request by request.ClientName
                                        into clients
                                        select new { Client = clients.Key, RequestCount = clients.Count() };

                var data = JsSerializer.Serialize(filteredQueue);
                JsonResponse(application, data);
                return;
            }
            else
            {
                var data = JsSerializer.Serialize(new { Error = true, Message = "No history avalible." });
                JsonResponse(application, data);
                return;
            }
        }
Esempio n. 2
0
        public override void Respond(HttpApplication application, GlimpseConfiguration configuration)
        {
            var response = application.Response;
            var mode = application.GetGlimpseMode();

            response.Write(
                string.Format(
                    "<html><head><title>Glimpse Config</title><script>function toggleCookie(){{var mode = document.getElementById('glimpseMode'); if (mode.innerHTML==='On'){{mode.innerHTML='Off';document.cookie='glimpseMode=Off; path=/;'}}else{{mode.innerHTML='On';document.cookie='glimpseMode=On; path=/;'}}}}</script><head><body><h1>Glimpse Config Settings:</h1><ul><li>On = {0}</li><li>Allowed IP's = <ol>",
                    configuration.On));
            foreach (IpAddress ipAddress in configuration.IpAddresses)
            {
                response.Write(string.Format("<li>{0}</li>", ipAddress.Address));
            }
            response.Write("</ol></li><li>Allowed ContentType's = <ol>");
            foreach (ContentType contentType in configuration.ContentTypes)
            {
                response.Write(string.Format("<li>{0}</li>", contentType.Content));
            }
            response.Write(
                string.Format(
                    "</ol></li></ul><h1>Your Settings:</h1><ol><li>IP = {0}</li><li>GlimpseMode = <input type='checkbox' id='gChk' onclick='toggleCookie();'{2}/> <label for='gChk' id='glimpseMode'>{1}</lable></li></ol></body></html>",
                    application.Request.ServerVariables["REMOTE_ADDR"], mode,
                    mode == GlimpseMode.On ? " checked" : ""));

            application.CompleteRequest();
        }
Esempio n. 3
0
        public override void Respond(HttpApplication application, GlimpseConfiguration configuration)
        {
            var response = application.Response;
            var mode = application.GetGlimpseMode();

            response.Write("<!DOCTYPE html><html><head><style>body { text-align:center; font-family:\"avante garde\", \"Century Gothic\", Serif; font-size:0.8em; line-height:1.4em; } .content { position:absolute; left:50%; margin-left:-450px; text-align:left; width:900px; } h1, h2, h3, h4 { line-height:1.2em; font-weight:normal; } h1 { font-size:4em; } h2 { font-size:2.5em; } h3 { font-size:2em; } .logo { font-family: \"TitilliumMaps\", helvetica, sans-serif; margin:100px 0 40px; position:relative; background: url(http://getglimpse.com/Content/glimpseLogo.png) -10px -15px no-repeat; padding: 0 0 0 140px; } .logo h1 { color:transparent; } .logo div { font-size:1.5em; margin: 25px 0 0 -10px; } .logo blockquote { width:350px; position:absolute; right:0; top:10px; } blockquote { font: 1.2em/1.6em \"avante garde\", \"Century Gothic\", Serif; width: 400px; background: url(http://getglimpse.com/Content/close-quote.gif) no-repeat right bottom; padding-left: 18px; text-indent: -18px; } blockquote:first-letter { background: url(http://getglimpse.com/Content/open-quote.gif) no-repeat left top; padding-left: 18px; font: italic 1.4em \"avante garde\", \"Century Gothic\", Serif; } .myButton{width:175px; line-height: 1.2em; margin:0.25em 0; text-align:center; -moz-box-shadow:inset 0 1px 0 0 #fff;-webkit-box-shadow:inset 0 1px 0 0 #fff;box-shadow:inset 0 1px 0 0 #fff;background:-webkit-gradient(linear,left top,left bottom,color-stop(0.05,#ededed),color-stop(1,#dfdfdf));background:-moz-linear-gradient(center top,#ededed 5%,#dfdfdf 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ededed',endColorstr='#dfdfdf');background-color:#ededed;-moz-border-radius:6px;-webkit-border-radius:6px;border-radius:6px;border:1px solid #dcdcdc;display:inline-block;color:#777;font-family:arial;font-size:24px;padding:10px 41px;text-decoration:none;text-shadow:1px 1px 0 #fff}.myButton:hover{background:-webkit-gradient(linear,left top,left bottom,color-stop(0.05,#dfdfdf),color-stop(1,#ededed));background:-moz-linear-gradient(center top,#dfdfdf 5%,#ededed 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#dfdfdf',endColorstr='#ededed');background-color:#dfdfdf}.myButton:active{position:relative;top:1px}</style><title>Glimpse Config</title><script>function toggleCookie(){var mode = document.getElementById('glimpseState'); if (mode.innerHTML==='On'){mode.innerHTML='Off';document.cookie='glimpseState=Off; path=/;';}else{mode.innerHTML='On';document.cookie='glimpseState=On; path=/;';}}</script><head><body><div class='content'><div class=\"logo\"><blockquote>What Firebug is for the client, Glimpse does for the server... in other words, a client side Glimpse into whats going on in your server.</blockquote><h1>Glimpse</h1><div>A client side Glimpse to your server</div></div><table width=\"100%\"><tr align=\"center\"><td width=\"50%\"><a class=\"myButton\" href=\"javascript:(function(){document.cookie='glimpseState=On; path=/; expires=Sat, 01 Jan 2050 12:00:00 GMT;'; window.location.reload();})();\">Turn Glimpse On</a></td><td><a class=\"myButton\" href=\"javascript:(function(){document.cookie='glimpseClientName='+ prompt('Client Name?') +'; path=/; expires=Sat, 01 Jan 2050 12:00:00 GMT;'; window.location.reload();})();\">Set Glimpse Session Name</a></td></tr></table><p style=\"text-align:center\">Drag the above button to your favorites bar for quick and easy access to Glimpse.</p>");
            response.Write(string.Format("<h2>Glimpse Config Settings:</h2><p>This section details the Glimpse settings in your web.config file.</p><ul><li>On = {0}</li><li>Allowed IP's = <ol>", configuration.On));

            foreach (IpAddress ipAddress in configuration.IpAddresses)
            {
                response.Write(string.Format("<li>{0}</li>", ipAddress.Address));
            }
            response.Write("</ol></li><li>Allowed ContentType's = <ol>");
            foreach (ContentType contentType in configuration.ContentTypes)
            {
                response.Write(string.Format("<li>{0}</li>", contentType.Content));
            }
            response.Write(
                string.Format(
                    "</ol></li></ul><h2>Your Settings:</h2><p>This section tells you how Glimpse sees your requests.</p><ul><li>IP = {0}</li><li>glimpseState = <label for='gChk' id='glimpseState'>{1}</label></li></ul>",
                    application.Request.ServerVariables["REMOTE_ADDR"], mode));

            response.Write("<h2>Loaded Plugins:</h2><p>This is the list of Glimpse plugins loaded for this web application. Glimpse plugins show up as individual tabs in the Glimpse client.</p><ul>");

            foreach (var plugin in Module.Plugins)
            {
                response.Write("<li>" + plugin.Value.GetType() + "</li>");
            }

            response.Write("</ul><h2>More Info:</h2><p><em>For more info see <a href='http://getGlimpse.com'/>getGlimpse.com</a> or follow <a href='http://twitter.com/#!/search/%23glimpse'/>#glimpse</a> on Twitter</em></p></body></html>");

            application.CompleteRequest();
        }
Esempio n. 4
0
        public override void Respond(HttpApplication application, GlimpseConfiguration configuration)
        {
            var response = application.Response;
            var mode = application.GetGlimpseMode();

            response.Write(
                string.Format(
                    "<html><head><title>Glimpse Config</title><script>function toggleCookie(){{var mode = document.getElementById('glimpseState'); if (mode.innerHTML==='On'){{mode.innerHTML='Off';document.cookie='glimpseState=Off; path=/;'}}else{{mode.innerHTML='On';document.cookie='glimpseState=On; path=/;'}}}}</script><head><body><h1>Glimpse Config Settings:</h1><ul><li>On = {0}</li><li>Allowed IP's = <ol>",
                    configuration.On));
            foreach (IpAddress ipAddress in configuration.IpAddresses)
            {
                response.Write(string.Format("<li>{0}</li>", ipAddress.Address));
            }
            response.Write("</ol></li><li>Allowed ContentType's = <ol>");
            foreach (ContentType contentType in configuration.ContentTypes)
            {
                response.Write(string.Format("<li>{0}</li>", contentType.Content));
            }
            response.Write(
                string.Format(
                    "</ol></li></ul><h1>Your Settings:</h1><ol><li>IP = {0}</li><li>glimpseState = <input type='checkbox' id='gChk' onclick='toggleCookie();'{2}/> <label for='gChk' id='glimpseState'>{1}</lable></li></ol>",
                    application.Request.ServerVariables["REMOTE_ADDR"], mode,
                    mode == GlimpseMode.On ? " checked" : ""));

            response.Write("<h1>Bookmarklets:</h1><p>Drag the following bookmarklets to your favorites bar for quick and easy access to Glimpse.</p><ul><li><a href=\"javascript:(function(){document.cookie='glimpseState=On; path=/; expires=Sat, 01 Jan 2050 12:00:00 GMT;'; window.location.reload();})();\">Glimpse</a> - Used to turn Glimpse on.</li><li><a href=\"javascript:(function(){document.cookie='glimpseClientName='+ prompt('Client Name?') +'; path=/; expires=Sat, 01 Jan 2050 12:00:00 GMT;'; window.location.reload();})();\">Glimpse Name</a> - Used to set the client name in Glimpse requests.</li></ul></body></html>");

            application.CompleteRequest();
        }
        internal static bool IsValidRequest(this object obj, out HttpApplication application, GlimpseConfiguration config, bool checkContentType, bool checkMode = true, bool checkPath = true)
        {
            application = obj as HttpApplication;
            if (application == null) return false;

            return IsValidRequestInternal(application, config, checkContentType, checkMode, checkPath);
        }
Esempio n. 6
0
        public override void Respond(HttpApplication application, GlimpseConfiguration configuration)
        {
            var response = application.Response;

            ////<style>.glimpse-open { display:none; } </style>

            response.Write("<!DOCTYPE html><html><head><title>Glimpse - Popup</title><style type='text/css'>html{color:#000;background:#FFF;} body{margin:0;padding:0;} .glimpse-holder { position:relative !important; display: block !important; } .glimpse-buttons, .glimpse-open { display:none !important; } .glimpse-panel { overflow:visible !important; }</style></head><body><script src='/Scripts/jquery-1.4.4.min.js' type='text/javascript'></script><script type='text/javascript' id='glimpseClient' src='/Glimpse/glimpseClient.js'></script>");

            application.CompleteRequest();
        }
Esempio n. 7
0
        public override void Respond(HttpApplication application, GlimpseConfiguration configuration)
        {
            var response = application.Response;

            var path = VirtualPathUtility.ToAbsolute("~/", application.Context.Request.ApplicationPath);  //TODO need to centralize logic
            var requestId = ""; //TODO need to get this id from somewhere

            response.Write("<!DOCTYPE html><html><head><title>Glimpse - Popup</title>");
            response.Write("<style type='text/css'>html{color:#000;background:#FFF;} body{margin:0;padding:0;} .glimpse-holder { position:relative !important; display: block !important; } .glimpse-popout, .glimpse-popout, .glimpse-terminate, .glimpse-open { display:none !important; } .glimpse-panel { overflow:visible !important; }</style>");
            response.Write("</head><body>");
            response.Write(string.Format(@"<script type='text/javascript' id='glimpseData' data-glimpse-requestID='{1}'>var glimpse, glimpsePath = '{0}'</script>", path, requestId));
            response.Write("<script src='/Scripts/jquery-1.4.4.min.js' type='text/javascript'></script><script type='text/javascript' id='glimpseClient' src='/Glimpse/glimpseClient.js'></script>");
            response.Write("</body></html>");

            application.CompleteRequest();
        }
Esempio n. 8
0
        private static bool IsValidRequestInternal(HttpApplication application, GlimpseConfiguration config, bool checkContentType, bool checkMode, bool checkPath = true)
        {
            var request = application.Request;
            var response = application.Response;
            var store = application.Context.Items;
            var cookies = request.Cookies;

            //check IP address
            var validIp = store["__validIp"] as bool?;
            if (!validIp.HasValue)
                store["__validIp"] = validIp = config.IpAddresses.Contains(request.ServerVariables["REMOTE_ADDR"]);

            if (!validIp.Value) return false;
            //end check

            if (checkMode)
            {
                //check cookie
                var validMode = store["__validMode"] as bool?;
                if (!validMode.HasValue)
                    store["__validMode"] = validMode = application.GetGlimpseMode() == GlimpseMode.On;

                if (!validMode.Value) return false;
                //end check
            }

            if (checkContentType)
            {
                //check contentType
                var validContentType = store["__valueContentType"] as bool?;
                if (!validContentType.HasValue)
                    store["__valueContentType"] = validContentType = config.ContentTypes.Contains(response.ContentType);

                if (!validContentType.Value) return false;
                //end check
            }

            if (checkPath)
            {
                //check path
                var validPath = store["__validPath"] as bool?;
                if (validPath.HasValue && validPath.Value == true) return false;
                //end check)
            }

            return true;
        }
Esempio n. 9
0
        public override void Respond(HttpApplication application, GlimpseConfiguration config)
        {
            var response = application.Response;
            var assembly = Assembly.GetExecutingAssembly();

            using (var resourceStream = assembly.GetManifestResourceStream("Glimpse.Net.glimpseClient.js"))
            {
                if (resourceStream != null)
                {
                    using (var reader = new StreamReader(resourceStream))
                    {
                        response.Write(reader.ReadToEnd());
                    }
                }
            }
            response.AddHeader("Content-Type", "application/x-javascript");
            application.CompleteRequest();
        }
Esempio n. 10
0
        public override void Respond(HttpApplication application, GlimpseConfiguration config)
        {
            var response = application.Response;
            var assembly = Assembly.GetExecutingAssembly();

            using (var resourceStream = assembly.GetManifestResourceStream("Glimpse.Net.glimpseSprite.png"))
            {
                if (resourceStream != null)
                {
                    var byteArray = new byte[resourceStream.Length];
                    resourceStream.Read(byteArray, 0, byteArray.Length);
                    response.OutputStream.Write(byteArray, 0, byteArray.Length);
                }
            }
            response.AddHeader("Content-Type", "image/png");
            application.CompleteRequest();

            return;
        }
Esempio n. 11
0
        public override void Respond(HttpApplication application, GlimpseConfiguration config)
        {
            var response = application.Response;
            var assembly = Assembly.GetExecutingAssembly();

            using (var resourceStream = assembly.GetManifestResourceStream("Glimpse.Net.glimpseSprite.png"))
            {
                if (resourceStream != null)
                {
                    using (var bitmap = new Bitmap(resourceStream))
                    {
                        bitmap.Save(response.OutputStream, ImageFormat.Png);
                    }
                }
            }
            response.AddHeader("Content-Type", "image/png");
            application.CompleteRequest();

            return;
        }
Esempio n. 12
0
        private static bool IsValidRequestInternal(HttpApplication application, GlimpseConfiguration config, bool checkContentType, bool checkMode, bool checkPath = true)
        {
            var request = application.Request;
            var response = application.Response;
            var store = application.Context.Items;

            var validIp = store[GlimpseConstants.ValidIp] as bool?;
            if (!validIp.HasValue)
                store[GlimpseConstants.ValidIp] = validIp = config.IpAddresses.Contains(request.ServerVariables["REMOTE_ADDR"]);

            if (!validIp.Value) return false;

            if (checkMode)
            {
                var validMode = store[GlimpseConstants.ValidMode] as bool?;
                if (!validMode.HasValue)
                    store[GlimpseConstants.ValidMode] = validMode = application.GetGlimpseMode() == GlimpseMode.On;

                if (!validMode.Value) return false;
            }

            if (checkContentType)
            {
                var validContentType = store[GlimpseConstants.ValidContentType] as bool?;
                if (!validContentType.HasValue)
                    store[GlimpseConstants.ValidContentType] = validContentType = config.ContentTypes.Contains(response.ContentType);

                if (!validContentType.Value) return false;
            }

            if (checkPath)
            {
                var validPath = store[GlimpseConstants.ValidPath] as bool?;
                if (validPath.HasValue && validPath.Value == true) return false;
            }

            var validResponseCodes = new List<int> {200, 301, 302};
            if (!validResponseCodes.Contains(response.StatusCode)) return false;

            return true;
        }
Esempio n. 13
0
        public override void Respond(HttpApplication application, GlimpseConfiguration config)
        {
            if (!application.IsValidRequest(config, false, checkPath: false))
            {
                var data =
                    JsSerializer.Serialize(new { Error = true, Message = "You are not configured to access history." });
                JsonResponse(application, data);
                return;
            }

            var queue = application.Application[GlimpseConstants.JsonQueue] as Queue<GlimpseRequestMetadata>;
            if (queue != null)
            {
                var result = new Dictionary<string, object>();
                var sortedQueue = from request in queue orderby request.ClientName select request;
                var lastClient = Guid.NewGuid().ToString();

                foreach (var request in sortedQueue)
                {
                    if (!lastClient.Equals(request.ClientName))
                        result.Add(request.ClientName, new Dictionary<string, object>());

                    var dictionary = result[request.ClientName] as IDictionary<string, object>;

                    dictionary.Add(request.RequestId.ToString(), new {request.Url, request.Browser, request.RequestTime, request.IsAjax, request.Method});

                    lastClient = request.ClientName;
                }

                var data = JsSerializer.Serialize(new {Data = result});
                JsonResponse(application, data);
                return;
            }
            else
            {
                var data = JsSerializer.Serialize(new { Error = true, Message = "No history avalible." });
                JsonResponse(application, data);
                return;
            }
        }
Esempio n. 14
0
        public override void Respond(HttpApplication application, GlimpseConfiguration config)
        {
            if (!application.IsValidRequest(config, false, checkPath: false))
            {
                var data =
                    JsSerializer.Serialize(new {Error = true, Message = "You are not configured to access history."});
                JsonResponse(application, data);
                return;
            }

            var queue = application.Application[GlimpseConstants.JsonQueue] as Queue<GlimpseRequestMetadata>;
            if (queue != null)
            {
                var clientName = application.Request.QueryString[GlimpseConstants.ClientName];
                string data;

                if (string.IsNullOrEmpty(clientName))
                    data = JsSerializer.Serialize(queue);
                else
                {
                    var filteredQueue = from request in queue
                                        where request.ClientName.Equals(clientName)
                                        select request;
                    data = JsSerializer.Serialize(filteredQueue);
                }

                JsonResponse(application, data);
                return;
            }
            else
            {
                var data = JsSerializer.Serialize(new {Error = true, Message = "No history avalible."});
                JsonResponse(application, data);
                return;
            }
        }
Esempio n. 15
0
 public abstract void Respond(HttpApplication application, GlimpseConfiguration config);
Esempio n. 16
0
        public override void Respond(HttpApplication application, GlimpseConfiguration config)
        {
            if (!application.IsValidRequest(config, false, checkPath: false))
            {
                var data =
                    JsSerializer.Serialize(new {Error = true, Message = "You are not configured to access history."});
                JsonResponse(application, data);
                return;
            }

            var queue = application.Application[GlimpseConstants.JsonQueue] as Queue<GlimpseRequestMetadata>;
            if (queue != null)
            {
                var result = new Dictionary<string, object>();
                IEnumerable<GlimpseRequestMetadata> data;

                var requestId = application.Request.QueryString[GlimpseConstants.ClientRequestId];
                if (!string.IsNullOrEmpty(requestId))
                {
                    data = from request in queue
                           where request.RequestId.ToString().Equals(requestId)
                           select request;

                    var requestResult = data.FirstOrDefault();
                    if (requestResult != null)
                        result.Add(requestResult.RequestId.ToString(), new { Data = requestResult.Json });
                }
                else
                {
                    var clientName = application.Request.QueryString[GlimpseConstants.ClientName];

                    if (string.IsNullOrEmpty(clientName))
                        data = queue;
                    else
                    {
                        data = from request in queue
                               where request.ClientName.Equals(clientName)
                               select request;
                    }

                    var lastClient = Guid.NewGuid().ToString();
                    foreach (var request in data.OrderBy(d => d.ClientName))
                    {
                        if (!lastClient.Equals(request.ClientName))
                            result.Add(request.ClientName, new Dictionary<string, object>());

                        var dictionary = result[request.ClientName] as IDictionary<string, object>;
                        dictionary.Add(request.RequestId.ToString(), new { Data = request.Json });

                        lastClient = request.ClientName;
                    }

                    if (!string.IsNullOrEmpty(clientName) && result.Count == 0)
                        result.Add(clientName, new Dictionary<string, object>());
                }

                var json = JsSerializer.Serialize(new { Data = result });
                JsonResponse(application, json);
                return;
            }
            else
            {
                var data = JsSerializer.Serialize(new {Error = true, Message = "No history avalible."});
                JsonResponse(application, data);
                return;
            }
        }
Esempio n. 17
0
 public static bool IsValidRequest(this HttpApplication application, GlimpseConfiguration config, bool checkContentType, bool checkMode = true, bool checkPath = true)
 {
     return IsValidRequestInternal(application, config, checkContentType, checkMode, checkPath);
 }