Exemple #1
0
        protected override void AddParsedItemInternal(List <SecureItem> secureItems, List <string> messages, RoboFormData rdata)
        {
            if (rdata == null)
            {
                throw new ArgumentNullException("rdata");
            }

            if (secureItems == null)
            {
                throw new ArgumentNullException("secureItems");
            }

            if (messages == null)
            {
                throw new ArgumentNullException("messages");
            }

            if (rdata.IsDictionary)
            {
                if (rdata.Caption == "Person")
                {
                    PBSubType.PersonalInfo.Name identityNameData = new PBSubType.PersonalInfo.Name();

                    identityNameData.FirstName = Helpers.GetValue(rdata.Data, "Name");

                    secureItems.Add(identityNameData.GetSecureItem());

                    TryToProcessPhoneNumber("Phone", secureItems, rdata);
                    TryToProcessPhoneNumber("Home Tel", secureItems, rdata);
                    TryToProcessPhoneNumber("Work Tel", secureItems, rdata);

                    TryToProcessPhoneNumber("Cell Tel", secureItems, rdata);
                    TryToProcessPhoneNumber("Fax", secureItems, rdata);
                    TryToProcessPhoneNumber("Work Tel", secureItems, rdata);

                    if (rdata.Data.ContainsKey("Email"))
                    {
                        PBSubType.PersonalInfo.Email identityEmail = new PBSubType.PersonalInfo.Email();
                        identityEmail.NickName = Helpers.GetValue(rdata.Data, "Name");
                        identityEmail.Address  = Helpers.GetValue(rdata.Data, "Email");
                        secureItems.Add(identityEmail.GetSecureItem());
                    }
                    if (rdata.Data.ContainsKey("Driver Lic"))
                    {
                        PBSubType.PersonalInfo.DriverLicense identityDriverLic = new PBSubType.PersonalInfo.DriverLicense();
                        identityDriverLic.LicenseNickname  = rdata.IdentityName;
                        identityDriverLic.LicenseFirstName = Helpers.GetValue(rdata.Data, "Name");
                        identityDriverLic.LicenseNumber    = Helpers.GetValue(rdata.Data, "Driver Lic");
                        secureItems.Add(identityDriverLic.GetSecureItem());
                    }
                    if (rdata.Data.ContainsKey("Note"))
                    {
                        PBSubType.PersonalInfo.SecureNotes identityData = new PBSubType.PersonalInfo.SecureNotes();
                        identityData.Title = Helpers.GetValue(rdata.Data, "Name");
                        identityData.Notes = Helpers.GetValue(rdata.Data, "Note");
                        secureItems.Add(identityData.GetSecureItem());
                    }
                }                 // Person
                else if (rdata.Caption == "Business")
                {
                    PBSubType.PersonalInfo.Company identData = new PBSubType.PersonalInfo.Company();
                    identData.Name = Helpers.GetValue(rdata.Data, "Company Name");

                    string compnote = "";
                    foreach (KeyValuePair <string, string> data in rdata.Data)
                    {
                        compnote += data.Key == "Company Name" ? "" : data.Key.ToUpperInvariant() + ": " + data.Value + "; ";
                    }
                    identData.Notes = compnote;
                    secureItems.Add(identData.GetSecureItem());
                }                 // Business
                else if (rdata.Caption == "Passport")
                {
                    PBSubType.PersonalInfo.Passport identData = new PBSubType.PersonalInfo.Passport();
                    identData.PassportNickName     = rdata.IdentityName;
                    identData.PassportExpiers      = Helpers.GetValue(rdata.Data, "Passport Exp­iration Date");
                    identData.PassportIssueDate    = Helpers.GetValue(rdata.Data, "Passport Issue Date");
                    identData.PassportPlaceOfIssue = Helpers.GetValue(rdata.Data, "Passport Issue Place");
                    identData.PassportNationality  = Helpers.GetValue(rdata.Data, "Passport­ Type");
                    identData.PassportNumber       = Helpers.GetValue(rdata.Data, "Passport Number");
                    secureItems.Add(identData.GetSecureItem());
                }                 // Passport
                else if (rdata.Caption == "Address")
                {
                    PBSubType.PersonalInfo.Address identData = new PBSubType.PersonalInfo.Address();
                    identData.Nickname = rdata.IdentityName;
                    identData.Address1 = Helpers.GetValue(rdata.Data, "Address Line 1");
                    identData.Address2 = Helpers.GetValue(rdata.Data, "Address Line 2");
                    identData.City     = Helpers.GetValue(rdata.Data, "PostCode City");
                    identData.State    = Helpers.GetValue(rdata.Data, "Country");
                    identData.Notes    = Helpers.GetValue(rdata.Data, "Note");
                    secureItems.Add(identData.GetSecureItem());
                }                 // Address
                else if (rdata.Caption == "Credit Card")
                {
                    PBSubType.DigitalWallet.CreditCard identData = new PBSubType.DigitalWallet.CreditCard();
                    identData.CreditCardNickname = rdata.IdentityName;
                    identData.CardNumber         = Helpers.GetValue(rdata.Data, "Card Number");
                    identData.Cvv          = Helpers.GetValue(rdata.Data, "Validation Code");
                    identData.ExpiresMonth = Helpers.GetValue(rdata.Data, "Card Expires").Split('/')[0];
                    identData.ExpiresYear  = Helpers.GetValue(rdata.Data, "Card Expires").Split('/')[1];
                    identData.IssueBank    = Helpers.GetValue(rdata.Data, "Issuing Bank");
                    identData.NameOnCard   = Helpers.GetValue(rdata.Data, "Card User Name");
                    identData.Pin          = Helpers.GetValue(rdata.Data, "PIN Number");
                    secureItems.Add(identData.GetSecureItem());
                }                 // Credit Card
                else if (rdata.Caption == "Bank Account")
                {
                    PBSubType.DigitalWallet.Bank identData = new PBSubType.DigitalWallet.Bank();
                    identData.AccountNickname      = rdata.IdentityName;
                    identData.AccountBankName      = Helpers.GetValue(rdata.Data, "Bank Name");
                    identData.AccountName          = Helpers.GetValue(rdata.Data, "Account Type");
                    identData.AccountNumber        = Helpers.GetValue(rdata.Data, "Account Number");
                    identData.AccountRoutingNumber = Helpers.GetValue(rdata.Data, "Routing Number");
                    secureItems.Add(identData.GetSecureItem());
                }                 // Bank Account
            }
            else
            {
                PBSubType.PersonalInfo.SecureNotes identityNoteData = new PBSubType.PersonalInfo.SecureNotes();

                identityNoteData.Title = rdata.Caption;

                var notetext = string.IsNullOrEmpty(rdata.SubCaption) ? "" : rdata.SubCaption + "; ";

                if (rdata.IsDictionary)
                {
                    foreach (KeyValuePair <string, string> data in rdata.Data)
                    {
                        notetext += data.Key.ToUpperInvariant() + ": " + data.Value + "; ";
                    }
                }
                else
                {
                    foreach (string note in rdata.DataList)
                    {
                        notetext += note + " ";
                    }
                }

                identityNoteData.Notes = notetext.Trim();

                secureItems.Add(identityNoteData.GetSecureItem());
            }
        }
        protected override ImportFromAppResult ImportInternal(FileImportArgs args)
        {
            if (args == null)
            {
                throw new ArgumentNullException("args");
            }

            var res = new ImportFromAppResult();

            string[] file;

            try
            {
                file = System.IO.File.ReadAllLines(args.FilePath);
            }
            catch
            {
                throw new System.IO.FileLoadException(string.Format(CultureInfo.InvariantCulture, "Error while loading file '{0}'.", args.FilePath));
            }


            int lncnt = 0;

            string[] fline;
            // dashlane export format rules: no rule


            foreach (string fileLine in file)
            {
                lncnt++;

                try
                {
                    /*lineId = fileLine.Substring(0, fileLine.IndexOf(',') - 1).Trim();
                     * csvLine = fileLine.Substring(fileLine.IndexOf(',') + 1);*/

                    fline = fileLine.Substring(1, fileLine.Length - 2).Replace(@""",""", Environment.NewLine).Split(new string[] { Environment.NewLine }, StringSplitOptions.None);


                    if ((fileLine.Trim().Length == 0))
                    {
                        continue;
                    }
                    else if ((fline.Count() == 5) && (!IsPidLike(fline[0].Trim())) /*&& (fline[1].Trim().IndexOf('.') >= 0)*/)                     // may be url login
                    {
                        // eg. "rsg2","rsg.ba","ruspasbos","rusPasbos.7","vijesti"

                        if (fline[0].Trim().ToUpper(CultureInfo.InvariantCulture).IndexOf("PAYPAL", StringComparison.Ordinal) >= 0)
                        {
                            var data = new PBSubType.DigitalWallet.PayPal();

                            data.PaypalNickname = fline[0].Trim();
                            data.Username       = fline[2].Trim();
                            data.Password       = fline[3].Trim();
                            data.PaypalNotes    = fline[4].Trim();

                            res.SecureItems.Add(data.GetSecureItem());
                        }
                        else
                        {
                            var data = new PBSubType.PasswordVault.Login();

                            data.SiteName = fline[0].Trim();
                            data.UserName = fline[2].Trim();
                            data.Password = fline[3].Trim();
                            data.Url      = fline[1].Trim();
                            data.Notes    = fline[4].Trim();
                            if (string.IsNullOrWhiteSpace(data.SiteName))
                            {
                                data.SiteName = data.Url;
                            }
                            res.SecureItems.Add(data.GetSecureItem());
                        }
                    }
                    else if ((fline.Count() == 6) && (!IsPidLike(fline[0].Trim())) /*&& (fline[1].Trim().IndexOf('.') >= 0)*/)                     // may be url login
                    {
                        var data = new PBSubType.PasswordVault.Login();

                        data.SiteName = fline[0].Trim();
                        data.UserName = fline[2].Trim();
                        data.Password = fline[4].Trim();
                        data.Url      = fline[1].Trim();
                        data.Notes    = fline[4].Trim();
                        if (string.IsNullOrWhiteSpace(data.SiteName))
                        {
                            data.SiteName = data.Url;
                        }
                        res.SecureItems.Add(data.GetSecureItem());
                    }
                    else if ((fline.Count() == 1) && (new Common().IsEmailValid(fline[0].Trim())))                     // email
                    {
                        var data = new PBSubType.PersonalInfo.Email();

                        data.NickName = fline[0].Trim();
                        data.Address  = fline[0].Trim();

                        res.SecureItems.Add(data.GetSecureItem());
                    }
                    else if ((fline.Count() >= 3) && (IsPhoneLikeLineId(fline[0].Trim())))
                    {
                        var data = new PBSubType.PersonalInfo.PhoneNumber();

                        data.Nickname = fline[0].Trim();
                        data.Number   = fline[1].Trim();
                        data.Notes    = "";

                        for (int i = 2; i < fline.Count(); i++)
                        {
                            if (fline[i].Trim().Length != 0)
                            {
                                data.Notes += fline[i].Trim() + " ";
                            }
                        }

                        res.SecureItems.Add(data.GetSecureItem());
                    }
                    else if (!IsPidLike(fline[0].Trim()))
                    {
                        res.ImportMessages.Add(string.Format(CultureInfo.InvariantCulture, "Input file:{0}. Error in line:{1}.", args.FilePath, lncnt));
                    }
                    else
                    {
                        res.ImportMessages.Add(string.Format(CultureInfo.InvariantCulture, "Input file:{0}. Error in line:{1}.", args.FilePath, lncnt));
                    }
                }
                catch (Exception ex)
                {
                    if (ex is IndexOutOfRangeException || ex is ArgumentException || ex is NullReferenceException)
                    {
                        res.ImportMessages.Add(string.Format(CultureInfo.InvariantCulture, "Input file:{0}. Error in line:{1}.", args.FilePath, lncnt));
                    }
                    else
                    {
                        throw;
                    }
                }
            }

            return(res);
        }