2016-05-02 09:52:09 +03:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2016-05-08 06:11:47 +03:00
|
|
|
|
using Bit.App.Resources;
|
2017-07-23 07:09:24 +03:00
|
|
|
|
using System.Linq;
|
2017-10-19 04:35:33 +03:00
|
|
|
|
using Bit.App.Enums;
|
2017-10-24 06:20:35 +03:00
|
|
|
|
using Bit.App.Abstractions;
|
2016-05-02 09:52:09 +03:00
|
|
|
|
|
2016-05-08 06:11:47 +03:00
|
|
|
|
namespace Bit.App.Models.Page
|
2016-05-02 09:52:09 +03:00
|
|
|
|
{
|
2016-05-08 06:11:47 +03:00
|
|
|
|
public class VaultListPageModel
|
2016-05-02 09:52:09 +03:00
|
|
|
|
{
|
2017-10-19 04:35:33 +03:00
|
|
|
|
public class Cipher
|
2016-05-02 09:52:09 +03:00
|
|
|
|
{
|
2017-10-24 06:20:35 +03:00
|
|
|
|
public Cipher(Models.Cipher cipher, IAppSettingsService appSettings)
|
2016-05-02 09:52:09 +03:00
|
|
|
|
{
|
2017-11-21 00:07:33 +03:00
|
|
|
|
CipherModel = cipher;
|
2017-10-19 03:55:33 +03:00
|
|
|
|
Id = cipher.Id;
|
|
|
|
|
Shared = !string.IsNullOrWhiteSpace(cipher.OrganizationId);
|
|
|
|
|
HasAttachments = cipher.Attachments?.Any() ?? false;
|
|
|
|
|
FolderId = cipher.FolderId;
|
|
|
|
|
Name = cipher.Name?.Decrypt(cipher.OrganizationId);
|
2017-10-19 04:35:33 +03:00
|
|
|
|
Type = cipher.Type;
|
|
|
|
|
|
2017-11-25 23:43:43 +03:00
|
|
|
|
if(string.IsNullOrWhiteSpace(Name) || Name.Length == 0)
|
|
|
|
|
{
|
|
|
|
|
NameGroup = AppResources.Other;
|
|
|
|
|
}
|
|
|
|
|
else if(Char.IsLetter(Name[0]))
|
|
|
|
|
{
|
|
|
|
|
NameGroup = Name[0].ToString();
|
|
|
|
|
}
|
|
|
|
|
else if(Char.IsDigit(Name[0]))
|
|
|
|
|
{
|
|
|
|
|
NameGroup = "0 - 9";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
NameGroup = AppResources.Other;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-19 04:35:33 +03:00
|
|
|
|
switch(cipher.Type)
|
|
|
|
|
{
|
|
|
|
|
case CipherType.Login:
|
2017-10-20 19:47:05 +03:00
|
|
|
|
LoginUsername = cipher.Login?.Username?.Decrypt(cipher.OrganizationId) ?? " ";
|
2017-10-20 22:24:40 +03:00
|
|
|
|
LoginUri = cipher.Login?.Uri?.Decrypt(cipher.OrganizationId) ?? " ";
|
2017-10-20 19:47:05 +03:00
|
|
|
|
LoginPassword = new Lazy<string>(() => cipher.Login?.Password?.Decrypt(cipher.OrganizationId));
|
|
|
|
|
LoginTotp = new Lazy<string>(() => cipher.Login?.Totp?.Decrypt(cipher.OrganizationId));
|
2017-10-19 04:35:33 +03:00
|
|
|
|
|
2017-10-20 22:24:40 +03:00
|
|
|
|
Icon = "login.png";
|
|
|
|
|
var hostnameUri = LoginUri;
|
|
|
|
|
var isWebsite = false;
|
2017-10-24 06:20:35 +03:00
|
|
|
|
var imageEnabled = !appSettings.DisableWebsiteIcons;
|
2017-10-20 22:24:40 +03:00
|
|
|
|
if(hostnameUri.StartsWith("androidapp://"))
|
|
|
|
|
{
|
|
|
|
|
Icon = "android.png";
|
|
|
|
|
}
|
|
|
|
|
else if(hostnameUri.StartsWith("iosapp://"))
|
|
|
|
|
{
|
|
|
|
|
Icon = "apple.png";
|
|
|
|
|
}
|
2017-10-20 23:10:22 +03:00
|
|
|
|
else if(imageEnabled && !hostnameUri.Contains("://") && hostnameUri.Contains("."))
|
2017-10-20 22:24:40 +03:00
|
|
|
|
{
|
|
|
|
|
hostnameUri = $"http://{hostnameUri}";
|
|
|
|
|
isWebsite = true;
|
|
|
|
|
}
|
2017-10-20 23:10:22 +03:00
|
|
|
|
else if(imageEnabled)
|
2017-10-20 22:24:40 +03:00
|
|
|
|
{
|
|
|
|
|
isWebsite = hostnameUri.StartsWith("http") && hostnameUri.Contains(".");
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-20 23:18:30 +03:00
|
|
|
|
if(imageEnabled && isWebsite && Uri.TryCreate(hostnameUri, UriKind.Absolute, out Uri u))
|
2017-10-20 22:24:40 +03:00
|
|
|
|
{
|
2017-10-24 06:20:35 +03:00
|
|
|
|
var iconsUrl = appSettings.IconsUrl;
|
|
|
|
|
if(string.IsNullOrWhiteSpace(iconsUrl))
|
|
|
|
|
{
|
|
|
|
|
if(!string.IsNullOrWhiteSpace(appSettings.BaseUrl))
|
|
|
|
|
{
|
|
|
|
|
iconsUrl = $"{appSettings.BaseUrl}/icons";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
iconsUrl = "https://icons.bitwarden.com";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Icon = $"{iconsUrl}/{u.Host}/icon.png";
|
2017-10-20 22:24:40 +03:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-20 19:47:05 +03:00
|
|
|
|
Subtitle = LoginUsername;
|
2017-10-19 04:35:33 +03:00
|
|
|
|
break;
|
|
|
|
|
case CipherType.SecureNote:
|
2017-10-20 22:24:40 +03:00
|
|
|
|
Icon = "note.png";
|
2017-10-19 04:35:33 +03:00
|
|
|
|
Subtitle = " ";
|
|
|
|
|
break;
|
|
|
|
|
case CipherType.Card:
|
2017-10-20 19:47:05 +03:00
|
|
|
|
CardNumber = cipher.Card?.Number?.Decrypt(cipher.OrganizationId) ?? " ";
|
2017-10-19 04:35:33 +03:00
|
|
|
|
var cardBrand = cipher.Card?.Brand?.Decrypt(cipher.OrganizationId) ?? " ";
|
|
|
|
|
CardCode = new Lazy<string>(() => cipher.Card?.Code?.Decrypt(cipher.OrganizationId));
|
|
|
|
|
|
2017-10-20 22:24:40 +03:00
|
|
|
|
Icon = "card.png";
|
2017-10-20 19:47:05 +03:00
|
|
|
|
Subtitle = cardBrand;
|
|
|
|
|
if(!string.IsNullOrWhiteSpace(CardNumber) && CardNumber.Length >= 4)
|
|
|
|
|
{
|
|
|
|
|
if(!string.IsNullOrWhiteSpace(CardNumber))
|
|
|
|
|
{
|
|
|
|
|
Subtitle += ", ";
|
|
|
|
|
}
|
|
|
|
|
Subtitle += ("*" + CardNumber.Substring(CardNumber.Length - 4));
|
|
|
|
|
}
|
2017-10-19 04:35:33 +03:00
|
|
|
|
break;
|
|
|
|
|
case CipherType.Identity:
|
|
|
|
|
var firstName = cipher.Identity?.FirstName?.Decrypt(cipher.OrganizationId) ?? " ";
|
|
|
|
|
var lastName = cipher.Identity?.LastName?.Decrypt(cipher.OrganizationId) ?? " ";
|
2017-10-20 19:47:05 +03:00
|
|
|
|
|
2017-10-20 22:24:40 +03:00
|
|
|
|
Icon = "id.png";
|
2017-10-20 19:47:05 +03:00
|
|
|
|
Subtitle = " ";
|
|
|
|
|
if(!string.IsNullOrWhiteSpace(firstName))
|
|
|
|
|
{
|
|
|
|
|
Subtitle = firstName;
|
|
|
|
|
}
|
|
|
|
|
if(!string.IsNullOrWhiteSpace(lastName))
|
|
|
|
|
{
|
|
|
|
|
if(!string.IsNullOrWhiteSpace(Subtitle))
|
|
|
|
|
{
|
|
|
|
|
Subtitle += " ";
|
|
|
|
|
}
|
|
|
|
|
Subtitle += lastName;
|
|
|
|
|
}
|
2017-10-19 04:35:33 +03:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2016-05-02 09:52:09 +03:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-21 00:07:33 +03:00
|
|
|
|
public Models.Cipher CipherModel { get; set; }
|
2016-05-03 09:08:50 +03:00
|
|
|
|
public string Id { get; set; }
|
2017-04-24 22:00:55 +03:00
|
|
|
|
public bool Shared { get; set; }
|
2017-07-23 07:09:24 +03:00
|
|
|
|
public bool HasAttachments { get; set; }
|
2016-05-04 02:49:49 +03:00
|
|
|
|
public string FolderId { get; set; }
|
2017-11-25 23:43:43 +03:00
|
|
|
|
public string NameGroup { get; set; }
|
2016-05-02 09:52:09 +03:00
|
|
|
|
public string Name { get; set; }
|
2017-10-19 04:35:33 +03:00
|
|
|
|
public string Subtitle { get; set; }
|
|
|
|
|
public CipherType Type { get; set; }
|
2017-10-20 22:24:40 +03:00
|
|
|
|
public string Icon { get; set; }
|
|
|
|
|
public string Image { get; set; }
|
2017-10-19 04:35:33 +03:00
|
|
|
|
|
|
|
|
|
// Login metadata
|
2017-10-20 19:47:05 +03:00
|
|
|
|
public string LoginUsername { get; set; }
|
|
|
|
|
public Lazy<string> LoginPassword { get; set; }
|
2017-10-20 22:24:40 +03:00
|
|
|
|
public string LoginUri { get; set; }
|
2017-10-20 19:47:05 +03:00
|
|
|
|
public Lazy<string> LoginTotp { get; set; }
|
2017-10-19 04:35:33 +03:00
|
|
|
|
|
|
|
|
|
// Login metadata
|
|
|
|
|
public string CardNumber { get; set; }
|
|
|
|
|
public Lazy<string> CardCode { get; set; }
|
2016-05-02 09:52:09 +03:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-19 04:35:33 +03:00
|
|
|
|
public class AutofillCipher : Cipher
|
2017-02-14 06:10:34 +03:00
|
|
|
|
{
|
2017-10-24 06:20:35 +03:00
|
|
|
|
public AutofillCipher(Models.Cipher cipher, IAppSettingsService appSettings, bool fuzzy = false)
|
|
|
|
|
: base(cipher, appSettings)
|
2017-02-14 06:10:34 +03:00
|
|
|
|
{
|
|
|
|
|
Fuzzy = fuzzy;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool Fuzzy { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-19 04:35:33 +03:00
|
|
|
|
public class Folder : List<Cipher>
|
2016-05-02 09:52:09 +03:00
|
|
|
|
{
|
2016-07-11 08:12:31 +03:00
|
|
|
|
public Folder(Models.Folder folder)
|
2016-05-02 09:52:09 +03:00
|
|
|
|
{
|
2016-07-11 08:12:31 +03:00
|
|
|
|
Id = folder.Id;
|
|
|
|
|
Name = folder.Name?.Decrypt();
|
2016-05-02 09:52:09 +03:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-19 04:35:33 +03:00
|
|
|
|
public Folder(List<Cipher> ciphers)
|
2016-05-02 09:52:09 +03:00
|
|
|
|
{
|
2017-10-19 04:35:33 +03:00
|
|
|
|
AddRange(ciphers);
|
2016-05-02 09:52:09 +03:00
|
|
|
|
}
|
|
|
|
|
|
2016-05-03 09:08:50 +03:00
|
|
|
|
public string Id { get; set; }
|
2016-05-08 06:11:47 +03:00
|
|
|
|
public string Name { get; set; } = AppResources.FolderNone;
|
2016-05-02 09:52:09 +03:00
|
|
|
|
}
|
2017-02-14 03:12:02 +03:00
|
|
|
|
|
2017-11-25 23:43:43 +03:00
|
|
|
|
public class NameGroup : List<Cipher>
|
|
|
|
|
{
|
|
|
|
|
public NameGroup(string nameGroup, List<Cipher> ciphers)
|
|
|
|
|
{
|
|
|
|
|
Name = nameGroup.ToUpperInvariant();
|
|
|
|
|
AddRange(ciphers);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-25 07:15:25 +03:00
|
|
|
|
public class Section : List<Grouping>
|
|
|
|
|
{
|
|
|
|
|
public Section(List<Grouping> groupings, string name)
|
|
|
|
|
{
|
|
|
|
|
AddRange(groupings);
|
|
|
|
|
Name = name.ToUpperInvariant();
|
|
|
|
|
ItemCount = groupings.Count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
public int ItemCount { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class Grouping
|
|
|
|
|
{
|
|
|
|
|
public Grouping(string name, int count)
|
|
|
|
|
{
|
|
|
|
|
Id = null;
|
|
|
|
|
Name = name;
|
|
|
|
|
Folder = true;
|
|
|
|
|
CipherCount = count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Grouping(Models.Folder folder, int count)
|
|
|
|
|
{
|
|
|
|
|
Id = folder.Id;
|
|
|
|
|
Name = folder.Name?.Decrypt();
|
|
|
|
|
Folder = true;
|
|
|
|
|
CipherCount = count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Grouping(Collection collection, int count)
|
|
|
|
|
{
|
|
|
|
|
Id = collection.Id;
|
|
|
|
|
Name = collection.Name?.Decrypt(collection.OrganizationId);
|
|
|
|
|
Collection = true;
|
|
|
|
|
CipherCount = count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Id { get; set; }
|
|
|
|
|
public string Name { get; set; } = AppResources.FolderNone;
|
|
|
|
|
public int CipherCount { get; set; }
|
|
|
|
|
public bool Folder { get; set; }
|
|
|
|
|
public bool Collection { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-19 04:35:33 +03:00
|
|
|
|
public class AutofillGrouping : List<AutofillCipher>
|
2017-02-14 03:12:02 +03:00
|
|
|
|
{
|
2017-10-19 04:35:33 +03:00
|
|
|
|
public AutofillGrouping(List<AutofillCipher> logins, string name)
|
2017-02-14 03:12:02 +03:00
|
|
|
|
{
|
|
|
|
|
AddRange(logins);
|
|
|
|
|
Name = name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
}
|
2016-05-02 09:52:09 +03:00
|
|
|
|
}
|
|
|
|
|
}
|