Пример #1
0
        public static HashSet <BrowserCapability> GetCapabilities(string userAgent)
        {
            var ua = _uaParser.Parse(userAgent ?? "");

            if (_browsers.TryGetValue(ua.UserAgent.Family, out BrowserPredicates predicates))
            {
                var caps = predicates.Where(p => p.Value(ua)).Select(pp => pp.Key);
                return(new HashSet <BrowserCapability>(caps));
            }

            return(new HashSet <BrowserCapability>());
        }
Пример #2
0
        public override void Handle(CommandTarget target, string type, string[] parameters)
        {
            if (!target.IsWeb || Program.DelayManager.AddAndCheck(target.Connection, DelayManager.Database))
            {
                return;
            }

            var userId = target.Connection.Session.Account.Id;

            if (parameters.Length == 1 && parameters[0] == "clear")
            {
                LoginToken.RemoveAll(userId);
                target.Send("Cleared all logins.");
                return;
            }

            var loginTokens = LoginToken.FindAll(userId).ToList();

            if (loginTokens.Count == 0)
            {
                target.Send("No active logins.");
                return;
            }

            var sb = new StringBuilder();

            sb.AppendLine("Active logins:");

            foreach (var login in loginTokens)
            {
                var address  = login.Address;
                var ua       = UserAgentParser.Parse(login.UserAgent);
                var created  = Util.DateTimeFromTimestamp(login.Created);
                var accessed = Util.DateTimeFromTimestamp(login.Accessed);

                sb.AppendFormat("{0} - {1} (created {2}, last accessed {3})", address, ua, created, accessed);
                sb.AppendLine();
            }

            target.Send(sb.ToString().Trim());
        }
Пример #3
0
        protected void Page_Load(object sender, System.EventArgs e)
        {
            System.Console.WriteLine("Hello");
            System.Diagnostics.Debug.WriteLine("world");


            // http://www.useragentstring.com/pages/useragentstring.php
            // http://www.user-agents.org/
            string ua = System.Web.HttpContext.Current.Request.UserAgent;

            ua = @"Googlebot/2.1 (+http://www.google.com/bot.html)";
            ua = @"Googlebot-Image/1.0";
            ua = @"Baiduspider+(+http://www.baidu.com/search/spider.htm)";


            UAParser.Parser     parser = UAParser.Parser.GetDefault();
            UAParser.Device     dev    = parser.ParseDevice(ua);
            UAParser.OS         os     = parser.ParseOS(ua);
            UAParser.UserAgent  pua    = parser.ParseUserAgent(ua);
            UAParser.ClientInfo cli    = parser.Parse(ua);

            string strua = pua.ToString();

            System.Console.WriteLine(strua);


            System.Console.WriteLine(dev);
            System.Console.WriteLine(os);
            System.Console.WriteLine(pua);
            System.Console.WriteLine(cli);



            // System.Web.HttpContext.Current.Request.Browser.IsMobileDevice


            // SomeDbOperations.Test();
        }
Пример #4
0
        protected override void Seed(Rock.Data.RockContext context)
        {
            // Previous to Rock v4.0 the saved routing|account numbers in the PersonBankAccount table may have included
            // leading or trailing spaces for the routing number and/or account number. v4.0 trims these leading/trailing
            // spaces before looking for and saving the routing|account numbers. Because of this, any existing saved
            // values need to be updated so they don't include any spaces. This can probably be removed in a future update
            // after v4.0 -DT
            var txnService            = new Rock.Model.FinancialTransactionService(context);
            var personBankAcctService = new Rock.Model.FinancialPersonBankAccountService(context);

            foreach (string encryptedMicr in txnService
                     .Queryable()
                     .Where(t =>
                            t.CheckMicrParts != null &&
                            t.CheckMicrParts != "")
                     .Select(t => t.CheckMicrParts)
                     .Distinct())
            {
                if (!string.IsNullOrWhiteSpace(encryptedMicr))
                {
                    string clearMicr = Rock.Security.Encryption.DecryptString(encryptedMicr) ?? string.Empty;
                    var    parts     = clearMicr.Split('_');
                    if (parts.Length >= 2 && (parts[0] != parts[0].Trim() || parts[1] != parts[1].Trim()))
                    {
                        string oldHash = Rock.Security.Encryption.GetSHA1Hash(string.Format("{0}|{1}", parts[0], parts[1]));
                        string newHash = Rock.Security.Encryption.GetSHA1Hash(string.Format("{0}|{1}", parts[0].Trim(), parts[1].Trim()));

                        foreach (var match in personBankAcctService.Queryable().Where(a => a.AccountNumberSecured == oldHash))
                        {
                            match.AccountNumberSecured = newHash;
                        }

                        context.SaveChanges();
                    }
                }
            }

            // Previous to Rock v4.0 the PageViews didn't store Browser or OS info. This can probably be removed in a future update
            // after v4.0 -DT
            var pageViewRockContext      = new Rock.Data.RockContext();
            var pageViewUserAgentService = new Rock.Model.PageViewUserAgentService(pageViewRockContext);
            var qryPageViewUserAgent     = pageViewUserAgentService.Queryable().Where(a => a.Browser == null || a.OperatingSystem == null || a.ClientType == null);

            foreach (var pageViewUserAgent in qryPageViewUserAgent.Where(a => a.UserAgent != null))
            {
                try
                {
                    UAParser.Parser     uaParser = UAParser.Parser.GetDefault();
                    UAParser.ClientInfo client   = uaParser.Parse(pageViewUserAgent.UserAgent);
                    pageViewUserAgent.ClientType      = Rock.Model.PageViewUserAgent.GetClientType(pageViewUserAgent.UserAgent);
                    pageViewUserAgent.OperatingSystem = client.OS.ToString();
                    pageViewUserAgent.Browser         = client.UserAgent.ToString();
                }
                catch
                {
                    // shouldn't happen, but skip if unable to parse
                }
            }

            pageViewRockContext.SaveChanges(true);
        }