Beispiel #1
0
        private void Write2Accesslog(BO.LoggingUser lu)
        {
            BO.j90LoginAccessLog c = new BO.j90LoginAccessLog()
            {
                j90BrowserUserAgent = lu.Browser_UserAgent, j90BrowserAvailWidth = lu.Browser_AvailWidth, j90BrowserAvailHeight = lu.Browser_AvailHeight, j90BrowserInnerWidth = lu.Browser_InnerWidth, j90BrowserInnerHeight = lu.Browser_InnerHeight
            };

            if (_f.CurrentUser != null)
            {
                c.j03ID = _f.CurrentUser.pid;
            }

            var uaParser = UAParser.Parser.GetDefault();

            UAParser.ClientInfo client_info = uaParser.Parse(lu.Browser_UserAgent);
            c.j90BrowserOS            = client_info.OS.Family + " " + client_info.OS.Major;
            c.j90BrowserFamily        = client_info.UA.Family + " " + client_info.UA.Major;
            c.j90BrowserDeviceFamily  = client_info.Device.Family;
            c.j90BrowserDeviceType    = lu.Browser_DeviceType;
            c.j90LoginMessage         = lu.Message;
            c.j90LoginName            = lu.Login;
            c.j90CookieExpiresInHours = lu.CookieExpiresInHours;
            c.j90LocationHost         = lu.Browser_Host;

            _f.Write2AccessLog(c);
        }
Beispiel #2
0
        public BO.Result UpdateCurrentUserPing(BO.j92PingLog c)
        {
            var uaParser = UAParser.Parser.GetDefault();

            UAParser.ClientInfo client_info = uaParser.Parse(c.j92BrowserUserAgent);
            c.j92BrowserOS           = client_info.OS.Family + " " + client_info.OS.Major;
            c.j92BrowserFamily       = client_info.UA.Family + " " + client_info.UA.Major;
            c.j92BrowserDeviceFamily = client_info.Device.Family;

            Factory.j03UserBL.UpdateCurrentUserPing(c);

            return(new BO.Result(false));
        }
Beispiel #3
0
        /// <summary>
        /// Parses ClientInfo and gets the device os version. If it cannot be determined returns the OS family string without the platform
        /// </summary>
        /// <param name="client">The client.</param>
        /// <returns></returns>
        private string GetDeviceOsVersion(UAParser.ClientInfo client)
        {
            if (client.OS.Major == null)
            {
                string platform = client.OS.Family.Split(' ').First();
                return(client.OS.Family.Replace(platform, string.Empty).Trim());
            }

            return(string.Format(
                       "{0}.{1}.{2}.{3}",
                       client.OS.Major ?? "0",
                       client.OS.Minor ?? "0",
                       client.OS.Patch ?? "0",
                       client.OS.PatchMinor ?? "0"));
        }
Beispiel #4
0
        /// <summary>
        /// Gets the current device platform info and updates the obj if needed.
        /// </summary>
        /// <param name="personalDevice">The personal device.</param>
        private PersonalDevice VerifyDeviceInfo(string macAddress)
        {
            UAParser.ClientInfo client = UAParser.Parser.GetDefault().Parse(Request.UserAgent);

            RockContext           rockContext           = new RockContext();
            PersonalDeviceService personalDeviceService = new PersonalDeviceService(rockContext);

            PersonalDevice personalDevice = personalDeviceService.GetByMACAddress(macAddress);

            personalDevice.PersonalDeviceTypeValueId = GetDeviceTypeValueId();
            personalDevice.PlatformValueId           = GetDevicePlatformValueId(client);
            personalDevice.DeviceVersion             = GetDeviceOsVersion(client);

            rockContext.SaveChanges();

            return(personalDevice);
        }
Beispiel #5
0
        /// <summary>
        /// Parses ClientInfo to find the OS family
        /// </summary>
        /// <param name="client">The client.</param>
        /// <returns>DefinedValueId for the found OS. Uses "Other" if the OS is not in DefinedValue. Null if there is a data issue and the DefinedType is missing</returns>
        private int?GetDevicePlatformValueId(UAParser.ClientInfo client)
        {
            // get the OS
            string platform = client.OS.Family.Split(' ').First();

            DefinedTypeCache  definedTypeCache  = DefinedTypeCache.Get(Rock.SystemGuid.DefinedType.PERSONAL_DEVICE_PLATFORM.AsGuid());
            DefinedValueCache definedValueCache = null;

            if (definedTypeCache != null)
            {
                definedValueCache = definedTypeCache.DefinedValues.FirstOrDefault(v => v.Value == platform);

                if (definedValueCache == null)
                {
                    definedValueCache = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.PERSONAL_DEVICE_PLATFORM_OTHER.AsGuid());
                }

                return(definedValueCache.Id);
            }

            return(null);
        }
Beispiel #6
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();
        }
        /// <summary>
        /// Enables processing of HTTP Web requests by a custom HttpHandler that implements the <see cref="T:System.Web.IHttpHandler" /> interface.
        /// </summary>
        /// <param name="context">An <see cref="T:System.Web.HttpContext" /> object that provides references to the intrinsic server objects (for example, Request, Response, Session, and Server) used to service HTTP requests.</param>
        public void ProcessRequest(HttpContext context)
        {
            Guid?communicationGuid = context.Request.QueryString["c"].AsGuidOrNull();

            if (communicationGuid.HasValue)
            {
                var rockContext   = new RockContext();
                var communication = new CommunicationService(rockContext).Get(communicationGuid.Value);

                if (communication != null)
                {
                    var mergeFields = Rock.Lava.LavaHelper.GetCommonMergeFields(null);
                    mergeFields.Add("Communication", communication);

                    Person person = null;

                    string encodedKey = context.Request.QueryString["p"];
                    if (!string.IsNullOrWhiteSpace(encodedKey))
                    {
                        // first try and see if we can use the new GetByPersonActionIdentifier() otherwise
                        // fall-back to the old GetByImpersonationToken method.
                        var personService = new PersonService(rockContext);
                        person = personService.GetByPersonActionIdentifier(encodedKey, "Unsubscribe");
                        if (person == null)
                        {
                            // TODO: Support for trying via impersonation token should be removed once we get to Rock v11
                            person = personService.GetByImpersonationToken(encodedKey, true, null);
                        }
                    }

                    if (person == null)
                    {
                        var principal = context.User;
                        if (principal != null && principal.Identity != null)
                        {
                            var userLoginService = new Rock.Model.UserLoginService(new RockContext());
                            var userLogin        = userLoginService.GetByUserName(principal.Identity.Name);

                            if (userLogin != null)
                            {
                                var currentPerson = userLogin.Person;
                                // if a person wasn't specified in the URL, then only show it if the current person has EDIT auth to the communication
                                if (communication.IsAuthorized(Authorization.EDIT, currentPerson))
                                {
                                    person = currentPerson;
                                }
                            }
                        }
                    }

                    if (person != null)
                    {
                        mergeFields.Add("Person", person);

                        var recipient = new CommunicationRecipientService(rockContext).Queryable()
                                        .Where(r =>
                                               r.CommunicationId == communication.Id &&
                                               r.PersonAlias != null &&
                                               r.PersonAlias.PersonId == person.Id)
                                        .FirstOrDefault();

                        if (recipient != null)
                        {
                            // Add any additional merge fields created through a report
                            foreach (var mergeField in recipient.AdditionalMergeValues)
                            {
                                if (!mergeFields.ContainsKey(mergeField.Key))
                                {
                                    mergeFields.Add(mergeField.Key, mergeField.Value);
                                }
                            }
                        }

                        context.Response.ContentType = "text/html";
                        context.Response.Write(GetHtmlPreview(communication, mergeFields));

                        if (recipient != null)
                        {
                            // write an 'opened' interaction
                            var interactionService = new InteractionService(rockContext);

                            InteractionComponent interactionComponent = new InteractionComponentService(rockContext)
                                                                        .GetComponentByEntityId(Rock.SystemGuid.InteractionChannel.COMMUNICATION.AsGuid(),
                                                                                                communication.Id, communication.Subject);
                            rockContext.SaveChanges();

                            var ipAddress = Rock.Web.UI.RockPage.GetClientIpAddress();

                            var userAgent = context.Request.UserAgent ?? "";

                            UAParser.ClientInfo client = UAParser.Parser.GetDefault().Parse(userAgent);
                            var clientOs      = client.OS.ToString();
                            var clientBrowser = client.UA.ToString();
                            var clientType    = InteractionDeviceType.GetClientType(userAgent);

                            interactionService.AddInteraction(interactionComponent.Id, recipient.Id, "Opened", "", recipient.PersonAliasId, RockDateTime.Now, clientBrowser, clientOs, clientType, userAgent, ipAddress, null);

                            rockContext.SaveChanges();
                        }

                        return;
                    }
                }
            }

            context.Response.ContentType = "text/plain";
            context.Response.Write("Sorry, the communication you requested does not exist, or you are not authorized to view it.");
            return;
        }
        /// <summary>
        /// Unsubscribes the person from any lists that were selected.
        /// </summary>
        /// <returns>true if they were actually unsubscribed from something or false otherwise.</returns>
        private bool UnsubscribeFromLists()
        {
            if (_person == null)
            {
                return(false);
            }

            if (!cblUnsubscribeFromLists.SelectedValuesAsInt.Any())
            {
                nbUnsubscribeSuccessMessage.NotificationBoxType = NotificationBoxType.Warning;
                nbUnsubscribeSuccessMessage.Text    = "Please select the lists that you want to unsubscribe from.";
                nbUnsubscribeSuccessMessage.Visible = true;
                return(false);
            }

            List <Group> unsubscribedGroups = new List <Group>();
            var          rockContext        = new RockContext();

            foreach (var communicationListId in cblUnsubscribeFromLists.SelectedValuesAsInt)
            {
                // normally there would be at most 1 group member record for the person, but just in case, mark them all inactive
                var groupMemberRecordsForPerson = new GroupMemberService(rockContext).Queryable().Include(a => a.Group).Where(a => a.GroupId == communicationListId && a.PersonId == _person.Id);
                foreach (var groupMember in groupMemberRecordsForPerson.ToList())
                {
                    groupMember.GroupMemberStatus = GroupMemberStatus.Inactive;
                    if (groupMember.Note.IsNullOrWhiteSpace())
                    {
                        groupMember.Note = "Unsubscribed";
                    }

                    unsubscribedGroups.Add(groupMember.Group);

                    rockContext.SaveChanges();
                }

                // if they selected the CommunicationList associated with the CommunicationId from the Url, log an 'Unsubscribe' Interaction
                if (_communication != null && _communication.ListGroupId.HasValue && communicationListId == _communication.ListGroupId)
                {
                    var communicationRecipient = _communication.GetRecipientsQry(rockContext).Where(a => a.PersonAlias.PersonId == _person.Id).FirstOrDefault();
                    if (communicationRecipient != null)
                    {
                        var interactionService = new InteractionService(rockContext);

                        InteractionComponent interactionComponent = new InteractionComponentService(rockContext)
                                                                    .GetComponentByEntityId(Rock.SystemGuid.InteractionChannel.COMMUNICATION.AsGuid(), _communication.Id, _communication.Subject);

                        rockContext.SaveChanges();

                        var ipAddress = GetClientIpAddress();
                        var userAgent = Request.UserAgent ?? "";

                        UAParser.ClientInfo client = UAParser.Parser.GetDefault().Parse(userAgent);
                        var clientOs      = client.OS.ToString();
                        var clientBrowser = client.UA.ToString();
                        var clientType    = InteractionDeviceType.GetClientType(userAgent);

                        interactionService.AddInteraction(interactionComponent.Id, communicationRecipient.Id, "Unsubscribe", "", communicationRecipient.PersonAliasId, RockDateTime.Now, clientBrowser, clientOs, clientType, userAgent, ipAddress, null);

                        rockContext.SaveChanges();
                    }
                }
            }

            var mergeFields     = Rock.Lava.LavaHelper.GetCommonMergeFields(this.RockPage, this.CurrentPerson);
            int?communicationId = PageParameter(PageParameterKey.CommunicationId).AsIntegerOrNull();

            if (_communication != null)
            {
                mergeFields.Add("Communication", _communication);
            }

            mergeFields.Add("UnsubscribedGroups", unsubscribedGroups);

            nbUnsubscribeSuccessMessage.NotificationBoxType = NotificationBoxType.Success;
            nbUnsubscribeSuccessMessage.Text    = GetAttributeValue(AttributeKey.UnsubscribeSuccessText).ResolveMergeFields(mergeFields);
            nbUnsubscribeSuccessMessage.Visible = true;
            return(true);
        }
Beispiel #9
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);
        }
        private void ShowCommunication()
        {
            pnlViewMessage.Visible = true;

            var communicationGuid = PageParameter("c").AsGuid();

            var    rockContext          = new RockContext();
            var    communicationService = new CommunicationService(rockContext);
            var    personService        = new PersonService(rockContext);
            Person person = null;

            if (PageParameter("p").IsNotNullOrWhiteSpace())
            {
                person = personService.GetByImpersonationToken(PageParameter("p"), true, null);
            }

            if (person == null)
            {
                person = CurrentPerson;
            }

            var communication = communicationService.Get(communicationGuid);

            if (communication == null || !communication.Recipients.Where(r => r.PersonAlias.PersonId == person.Id).Any())
            {
                var message = "<div class='alert alert-info'>This message is currently unavailable</div>";
                lMessageContent.Text = message;

                return;
            }

            var recipient   = communication.Recipients.Where(r => r.PersonAlias.PersonId == person.Id).FirstOrDefault();
            var mergeFields = Rock.Lava.LavaHelper.GetCommonMergeFields(null);

            mergeFields.Add("Communication", "communication");
            mergeFields.Add("Person", person);

            foreach (var mergeField in recipient.AdditionalMergeValues)
            {
                if (!mergeFields.ContainsKey(mergeField.Key))
                {
                    mergeFields.Add(mergeField.Key, mergeField.Value);
                }
            }

            string body = communication.Message.ResolveMergeFields(mergeFields, communication.EnabledLavaCommands);

            body = System.Text.RegularExpressions.Regex.Replace(body, @"\[\[\s*UnsubscribeOption\s*\]\]", string.Empty);
            lMessageContent.Text = body;


            // write an 'opened' interaction
            var interactionService = new InteractionService(rockContext);

            InteractionComponent interactionComponent = new InteractionComponentService(rockContext)
                                                        .GetComponentByEntityId(Rock.SystemGuid.InteractionChannel.COMMUNICATION.AsGuid(),
                                                                                communication.Id, communication.Subject);

            rockContext.SaveChanges();

            var ipAddress = Rock.Web.UI.RockPage.GetClientIpAddress();

            var userAgent = Request.UserAgent ?? "";

            UAParser.ClientInfo client = UAParser.Parser.GetDefault().Parse(userAgent);
            var clientOs      = client.OS.ToString();
            var clientBrowser = client.UA.ToString();
            var clientType    = InteractionDeviceType.GetClientType(userAgent);

            interactionService.AddInteraction(interactionComponent.Id, recipient.Id, "Opened", "", recipient.PersonAliasId, RockDateTime.Now, clientBrowser, clientOs, clientType, userAgent, ipAddress, null);

            rockContext.SaveChanges();
        }