Exemple #1
0
        public static void AddAdminLog(Kooboo.Data.Context.RenderContext context, RenderRespnose response)
        {
            if (response != null && response.ContentType != null && response.ContentType.ToLower().Contains("html"))
            {
                BackendLog model = new BackendLog();
                model.IP = context.Request.IP;
                if (context.User != null)
                {
                    model.UserId   = context.User.Id;
                    model.UserName = context.User.UserName;
                }
                model.Url        = context.Request.RawRelativeUrl;
                model.StatusCode = 200;

                if (context.Request.Cookies != null)
                {
                    foreach (var item in context.Request.Cookies)
                    {
                        model.Data[item.Key] = item.Value;
                    }
                }

                if (context.Request.Forms != null)
                {
                    foreach (var item in context.Request.Forms.AllKeys)
                    {
                        string key   = item;
                        string value = null;

                        var itemvalue = context.Request.Forms.GetValues(item);
                        if (itemvalue != null)
                        {
                            value = string.Join(";", itemvalue);
                        }

                        model.Data[key] = value;
                    }
                }

                if (context.Request.QueryString != null)
                {
                    foreach (var item in context.Request.QueryString.AllKeys)
                    {
                        string key   = item;
                        string value = null;

                        var itemvalue = context.Request.QueryString.GetValues(item);
                        if (itemvalue != null)
                        {
                            value = string.Join(";", itemvalue);
                        }

                        model.Data[key] = value;
                    }
                }

                Add(model);
                Kooboo.Data.Service.UserLoginService.UpdateLastPath(model);
            }
        }
Exemple #2
0
        public static void AddApiLog(Data.Context.RenderContext context, IResponse response)
        {
            if (response != null)
            {
                BackendLog model = new BackendLog();
                model.IsApi = true;
                model.IP    = context.Request.IP;
                if (context.User != null)
                {
                    model.UserId   = context.User.Id;
                    model.UserName = context.User.UserName;
                }
                model.Url        = context.Request.RawRelativeUrl;
                model.StatusCode = 200;

                if (context.Request.Cookies != null)
                {
                    foreach (var item in context.Request.Cookies)
                    {
                        model.Data[item.Key] = item.Value;
                    }
                }

                if (context.Request.Forms != null)
                {
                    foreach (var item in context.Request.Forms.AllKeys)
                    {
                        string key   = item;
                        string value = null;

                        var itemvalue = context.Request.Forms.GetValues(item);
                        if (itemvalue != null)
                        {
                            value = string.Join(";", itemvalue);
                        }

                        model.Data[key] = value;
                    }
                }

                if (context.Request.QueryString != null)
                {
                    foreach (var item in context.Request.QueryString.AllKeys)
                    {
                        string key   = item;
                        string value = null;

                        var itemvalue = context.Request.QueryString.GetValues(item);
                        if (itemvalue != null)
                        {
                            value = string.Join(";", itemvalue);
                        }

                        model.Data[key] = value;
                    }
                }

                Add(model);
            }
        }
Exemple #3
0
        public static void UpdateLastPath(BackendLog log)
        {
            if (log == null || log.UserId == default(Guid) || log.Url == null)
            {
                return;
            }

            if (log.Url.Length > 700)
            {
                return;  // too long.
            }

            var lower = log.Url.ToLower();

            if (lower.StartsWith("/_admin"))
            {
                foreach (var item in IgnorePath)
                {
                    if (lower.StartsWith(item))
                    {
                        return;
                    }
                }

                if (lower.EndsWith(".html") || lower.EndsWith(".js") || lower.EndsWith(".css") || lower.EndsWith(".png"))
                {
                    return;
                }

                var find = LastPath.Get(log.UserId);
                if (find != null && find.ContainsKey("_id"))
                {
                    LastPath.UpdateColumn(find["_id"], "Path", log.Url);
                }
                else
                {
                    Dictionary <string, object> data = new Dictionary <string, object>();
                    data["_id"]  = log.UserId;
                    data["Path"] = log.Url;
                    LastPath.Add(data);
                }

                LastPath.Close();
            }
        }
Exemple #4
0
 public static void Add(BackendLog log)
 {
     LogStore.Add(log);
     LogStore.Flush();
 }