angular
.module('bit', [
'ui.router',
'ngMessages',
'angular-jwt',
'ui.bootstrap.showErrors',
'toastr',
'angulartics',
'angulartics.google.analytics',
'angular-stripe',
'credit-cards',
'angular-promise-polyfill',
'bit.directives',
'bit.filters',
'bit.services',
'bit.global',
'bit.accounts',
'bit.vault',
'bit.settings',
'bit.tools',
'bit.organization',
'bit.reports'
]);
angular.module("bit")
.constant("appSettings", {"apiUri":"/api","identityUri":"/identity","iconsUri":"https://icons.bitwarden.com","stripeKey":"pk_live_bpN0P37nMxrMQkcaHXtAybJk","braintreeKey":"production_qfbsv8kc_njj2zjtyngtjmbjd","selfHosted":false,"version":"1.26.0","environment":"Production"});
angular
.module('bit.accounts', ['ui.bootstrap', 'ngCookies']);
angular
.module('bit.directives', []);
angular
.module('bit.filters', []);
angular
.module('bit.global', []);
angular
.module('bit.organization', ['ui.bootstrap']);
angular
.module('bit.services', ['ngResource', 'ngStorage', 'angular-jwt']);
angular
.module('bit.reports', ['toastr', 'ngSanitize']);
angular
.module('bit.settings', ['ui.bootstrap', 'toastr']);
angular
.module('bit.vault', ['ui.bootstrap', 'ngclipboard']);
angular
.module('bit.tools', ['ui.bootstrap', 'toastr']);
angular
.module('bit')
.factory('apiInterceptor', ["$injector", "$q", "toastr", "appSettings", "utilsService", function ($injector, $q, toastr, appSettings, utilsService) {
return {
request: function (config) {
if (config.url.indexOf(appSettings.apiUri + '/') === 0) {
config.headers['Device-Type'] = utilsService.getDeviceType();
}
return config;
},
response: function (response) {
if (response.status === 401 || response.status === 403) {
$injector.get('authService').logOut();
$injector.get('$state').go('frontend.login.info').then(function () {
toastr.warning('Your login session has expired.', 'Logged out');
});
}
return response || $q.when(response);
},
responseError: function (rejection) {
if (rejection.status === 401 || rejection.status === 403) {
$injector.get('authService').logOut();
$injector.get('$state').go('frontend.login.info').then(function () {
toastr.warning('Your login session has expired.', 'Logged out');
});
}
return $q.reject(rejection);
}
};
}]);
angular
.module('bit')
.config(["$stateProvider", "$urlRouterProvider", "$httpProvider", "jwtInterceptorProvider", "jwtOptionsProvider", "$uibTooltipProvider", "toastrConfig", "$locationProvider", "$qProvider", "appSettings", "stripeProvider", function ($stateProvider, $urlRouterProvider, $httpProvider, jwtInterceptorProvider, jwtOptionsProvider,
$uibTooltipProvider, toastrConfig, $locationProvider, $qProvider, appSettings
/* jshint ignore:start */
, stripeProvider
/* jshint ignore:end */
) {
angular.extend(appSettings, window.bitwardenAppSettings);
$qProvider.errorOnUnhandledRejections(false);
$locationProvider.hashPrefix('');
jwtOptionsProvider.config({
whiteListedDomains: ['localhost', 'api.bitwarden.com', 'vault.bitwarden.com', 'haveibeenpwned.com']
});
var refreshPromise;
jwtInterceptorProvider.tokenGetter = /*@ngInject*/ ["options", "tokenService", "authService", function (options, tokenService, authService) {
if (options.url.indexOf(appSettings.apiUri + '/') !== 0) {
return;
}
if (refreshPromise) {
return refreshPromise;
}
var token = tokenService.getToken();
if (!token) {
return;
}
if (!tokenService.tokenNeedsRefresh(token)) {
return token;
}
var p = authService.refreshAccessToken();
if (!p) {
return;
}
refreshPromise = p.then(function (newToken) {
refreshPromise = null;
return newToken || token;
});
return refreshPromise;
}];
stripeProvider.setPublishableKey(appSettings.stripeKey);
angular.extend(toastrConfig, {
closeButton: true,
progressBar: true,
showMethod: 'slideDown',
target: '.toast-target'
});
$uibTooltipProvider.options({
popupDelay: 600,
appendToBody: true
});
// stop IE from caching get requests
if (navigator.userAgent.indexOf('MSIE') !== -1 || navigator.appVersion.indexOf('Trident/') > 0) {
if (!$httpProvider.defaults.headers.get) {
$httpProvider.defaults.headers.get = {};
}
$httpProvider.defaults.headers.get['Cache-Control'] = 'no-cache';
$httpProvider.defaults.headers.get.Pragma = 'no-cache';
}
$httpProvider.interceptors.push('apiInterceptor');
$httpProvider.interceptors.push('jwtInterceptor');
$urlRouterProvider.otherwise('/');
$stateProvider
// Backend
.state('backend', {
templateUrl: 'app/views/backendLayout.html',
abstract: true,
data: {
authorize: true
}
})
.state('backend.user', {
templateUrl: 'app/views/userLayout.html',
abstract: true
})
.state('backend.user.vault', {
url: '^/vault',
templateUrl: 'app/vault/views/vault.html',
controller: 'vaultController',
data: {
pageTitle: 'My Vault',
controlSidebar: true
},
params: {
refreshFromServer: false
}
})
.state('backend.user.settings', {
url: '^/settings',
templateUrl: 'app/settings/views/settings.html',
controller: 'settingsController',
data: { pageTitle: 'Settings' }
})
.state('backend.user.settingsDomains', {
url: '^/settings/domains',
templateUrl: 'app/settings/views/settingsDomains.html',
controller: 'settingsDomainsController',
data: { pageTitle: 'Domain Settings' }
})
.state('backend.user.settingsTwoStep', {
url: '^/settings/two-step',
templateUrl: 'app/settings/views/settingsTwoStep.html',
controller: 'settingsTwoStepController',
data: { pageTitle: 'Two-step Login' }
})
.state('backend.user.settingsCreateOrg', {
url: '^/settings/create-organization',
templateUrl: 'app/settings/views/settingsCreateOrganization.html',
controller: 'settingsCreateOrganizationController',
data: { pageTitle: 'Create Organization' }
})
.state('backend.user.settingsBilling', {
url: '^/settings/billing',
templateUrl: 'app/settings/views/settingsBilling.html',
controller: 'settingsBillingController',
data: { pageTitle: 'Billing' }
})
.state('backend.user.settingsPremium', {
url: '^/settings/premium',
templateUrl: 'app/settings/views/settingsPremium.html',
controller: 'settingsPremiumController',
data: { pageTitle: 'Go Premium' }
})
.state('backend.user.tools', {
url: '^/tools',
templateUrl: 'app/tools/views/tools.html',
controller: 'toolsController',
data: { pageTitle: 'Tools' }
})
.state('backend.user.reportsBreach', {
url: '^/reports/breach',
templateUrl: 'app/reports/views/reportsBreach.html',
controller: 'reportsBreachController',
data: { pageTitle: 'Data Breach Report' }
})
.state('backend.org', {
templateUrl: 'app/views/organizationLayout.html',
abstract: true
})
.state('backend.org.dashboard', {
url: '^/organization/:orgId',
templateUrl: 'app/organization/views/organizationDashboard.html',
controller: 'organizationDashboardController',
data: { pageTitle: 'Organization Dashboard' }
})
.state('backend.org.people', {
url: '/organization/:orgId/people?viewEvents&search',
templateUrl: 'app/organization/views/organizationPeople.html',
controller: 'organizationPeopleController',
data: { pageTitle: 'Organization People' }
})
.state('backend.org.collections', {
url: '/organization/:orgId/collections?search',
templateUrl: 'app/organization/views/organizationCollections.html',
controller: 'organizationCollectionsController',
data: { pageTitle: 'Organization Collections' }
})
.state('backend.org.settings', {
url: '/organization/:orgId/settings',
templateUrl: 'app/organization/views/organizationSettings.html',
controller: 'organizationSettingsController',
data: { pageTitle: 'Organization Settings' }
})
.state('backend.org.billing', {
url: '/organization/:orgId/billing',
templateUrl: 'app/organization/views/organizationBilling.html',
controller: 'organizationBillingController',
data: { pageTitle: 'Organization Billing' }
})
.state('backend.org.vault', {
url: '/organization/:orgId/vault?viewEvents&search',
templateUrl: 'app/organization/views/organizationVault.html',
controller: 'organizationVaultController',
data: {
pageTitle: 'Organization Vault',
controlSidebar: true
}
})
.state('backend.org.groups', {
url: '/organization/:orgId/groups?search',
templateUrl: 'app/organization/views/organizationGroups.html',
controller: 'organizationGroupsController',
data: { pageTitle: 'Organization Groups' }
})
.state('backend.org.events', {
url: '/organization/:orgId/events',
templateUrl: 'app/organization/views/organizationEvents.html',
controller: 'organizationEventsController',
data: { pageTitle: 'Organization Events' }
})
// Frontend
.state('frontend', {
templateUrl: 'app/views/frontendLayout.html',
abstract: true,
data: {
authorize: false
}
})
.state('frontend.login', {
templateUrl: 'app/accounts/views/accountsLogin.html',
controller: 'accountsLoginController',
params: {
returnState: null,
email: null,
premium: null,
org: null
},
data: {
bodyClass: 'login-page'
}
})
.state('frontend.login.info', {
url: '^/?org&premium&email',
templateUrl: 'app/accounts/views/accountsLoginInfo.html',
data: {
pageTitle: 'Log In'
}
})
.state('frontend.login.twoFactor', {
url: '^/two-step?org&premium&email',
templateUrl: 'app/accounts/views/accountsLoginTwoFactor.html',
data: {
pageTitle: 'Log In (Two-step)'
}
})
.state('frontend.logout', {
url: '^/logout',
controller: 'accountsLogoutController',
data: {
authorize: true
}
})
.state('frontend.passwordHint', {
url: '^/password-hint',
templateUrl: 'app/accounts/views/accountsPasswordHint.html',
controller: 'accountsPasswordHintController',
data: {
pageTitle: 'Master Password Hint',
bodyClass: 'login-page'
}
})
.state('frontend.recover', {
url: '^/recover',
templateUrl: 'app/accounts/views/accountsRecover.html',
controller: 'accountsRecoverController',
data: {
pageTitle: 'Recover Account',
bodyClass: 'login-page'
}
})
.state('frontend.recover-delete', {
url: '^/recover-delete',
templateUrl: 'app/accounts/views/accountsRecoverDelete.html',
controller: 'accountsRecoverDeleteController',
data: {
pageTitle: 'Delete Account',
bodyClass: 'login-page'
}
})
.state('frontend.verify-recover-delete', {
url: '^/verify-recover-delete?userId&token&email',
templateUrl: 'app/accounts/views/accountsVerifyRecoverDelete.html',
controller: 'accountsVerifyRecoverDeleteController',
data: {
pageTitle: 'Confirm Delete Account',
bodyClass: 'login-page'
}
})
.state('frontend.register', {
url: '^/register?org&premium',
templateUrl: 'app/accounts/views/accountsRegister.html',
controller: 'accountsRegisterController',
params: {
returnState: null,
email: null,
org: null,
premium: null
},
data: {
pageTitle: 'Register',
bodyClass: 'register-page'
}
})
.state('frontend.organizationAccept', {
url: '^/accept-organization?organizationId&organizationUserId&token&email&organizationName',
templateUrl: 'app/accounts/views/accountsOrganizationAccept.html',
controller: 'accountsOrganizationAcceptController',
data: {
pageTitle: 'Accept Organization Invite',
bodyClass: 'login-page',
skipAuthorize: true
}
})
.state('frontend.verifyEmail', {
url: '^/verify-email?userId&token',
templateUrl: 'app/accounts/views/accountsVerifyEmail.html',
controller: 'accountsVerifyEmailController',
data: {
pageTitle: 'Verifying Email',
bodyClass: 'login-page',
skipAuthorize: true
}
});
}])
.run(["$rootScope", "authService", "$state", function ($rootScope, authService, $state) {
$rootScope.$on('$stateChangeSuccess', function () {
$('html, body').animate({ scrollTop: 0 }, 200);
});
$rootScope.$on('$stateChangeStart', function (event, toState, toParams) {
if (!toState.data || !toState.data.authorize) {
if (toState.data && toState.data.skipAuthorize) {
return;
}
if (!authService.isAuthenticated()) {
return;
}
event.preventDefault();
$state.go('backend.user.vault');
return;
}
if (!authService.isAuthenticated()) {
event.preventDefault();
authService.logOut();
$state.go('frontend.login.info');
return;
}
// user is guaranteed to be authenticated becuase of previous check
if (toState.name.indexOf('backend.org.') > -1 && toParams.orgId) {
// clear vault rootScope when visiting org admin section
$rootScope.vaultCiphers = $rootScope.vaultFolders = $rootScope.vaultCollections = null;
authService.getUserProfile().then(function (profile) {
var orgs = profile.organizations;
if (!orgs || !(toParams.orgId in orgs) || orgs[toParams.orgId].status !== 2 ||
orgs[toParams.orgId].type === 2) {
event.preventDefault();
$state.go('backend.user.vault');
}
});
}
});
}]);
angular.module('bit')
.constant('constants', {
rememberedEmailCookieName: 'bit.rememberedEmail',
encType: {
AesCbc256_B64: 0,
AesCbc128_HmacSha256_B64: 1,
AesCbc256_HmacSha256_B64: 2,
Rsa2048_OaepSha256_B64: 3,
Rsa2048_OaepSha1_B64: 4,
Rsa2048_OaepSha256_HmacSha256_B64: 5,
Rsa2048_OaepSha1_HmacSha256_B64: 6
},
orgUserType: {
owner: 0,
admin: 1,
user: 2
},
orgUserStatus: {
invited: 0,
accepted: 1,
confirmed: 2
},
twoFactorProvider: {
u2f: 4,
yubikey: 3,
duo: 2,
authenticator: 0,
email: 1,
remember: 5,
organizationDuo: 6
},
cipherType: {
login: 1,
secureNote: 2,
card: 3,
identity: 4
},
fieldType: {
text: 0,
hidden: 1,
boolean: 2
},
deviceType: {
android: 0,
ios: 1,
chromeExt: 2,
firefoxExt: 3,
operaExt: 4,
edgeExt: 5,
windowsDesktop: 6,
macOsDesktop: 7,
linuxDesktop: 8,
chrome: 9,
firefox: 10,
opera: 11,
edge: 12,
ie: 13,
unknown: 14,
uwp: 16,
safari: 17,
vivaldi: 18,
vivaldiExt: 19
},
eventType: {
User_LoggedIn: 1000,
User_ChangedPassword: 1001,
User_Enabled2fa: 1002,
User_Disabled2fa: 1003,
User_Recovered2fa: 1004,
User_FailedLogIn: 1005,
User_FailedLogIn2fa: 1006,
Cipher_Created: 1100,
Cipher_Updated: 1101,
Cipher_Deleted: 1102,
Cipher_AttachmentCreated: 1103,
Cipher_AttachmentDeleted: 1104,
Cipher_Shared: 1105,
Cipher_UpdatedCollections: 1106,
Collection_Created: 1300,
Collection_Updated: 1301,
Collection_Deleted: 1302,
Group_Created: 1400,
Group_Updated: 1401,
Group_Deleted: 1402,
OrganizationUser_Invited: 1500,
OrganizationUser_Confirmed: 1501,
OrganizationUser_Updated: 1502,
OrganizationUser_Removed: 1503,
OrganizationUser_UpdatedGroups: 1504,
Organization_Updated: 1600
},
twoFactorProviderInfo: [
{
type: 0,
name: 'Authenticator App',
description: 'Use an authenticator app (such as Authy or Google Authenticator) to generate time-based ' +
'verification codes.',
enabled: false,
active: true,
free: true,
image: 'authapp.png',
displayOrder: 0,
priority: 1,
requiresUsb: false,
organization: false
},
{
type: 3,
name: 'YubiKey OTP Security Key',
description: 'Use a YubiKey to access your account. Works with YubiKey 4, 4 Nano, 4C, and NEO devices.',
enabled: false,
active: true,
image: 'yubico.png',
displayOrder: 1,
priority: 3,
requiresUsb: true,
organization: false
},
{
type: 2,
name: 'Duo',
description: 'Verify with Duo Security using the Duo Mobile app, SMS, phone call, or U2F security key.',
enabled: false,
active: true,
image: 'duo.png',
displayOrder: 2,
priority: 2,
requiresUsb: false,
organization: false
},
{
type: 4,
name: 'FIDO U2F Security Key',
description: 'Use any FIDO U2F enabled security key to access your account.',
enabled: false,
active: true,
image: 'fido.png',
displayOrder: 3,
priority: 4,
requiresUsb: true,
organization: false
},
{
type: 1,
name: 'Email',
description: 'Verification codes will be emailed to you.',
enabled: false,
active: true,
free: true,
image: 'gmail.png',
displayOrder: 4,
priority: 0,
requiresUsb: false,
organization: false
},
{
type: 6,
name: 'Duo (Organization)',
description: 'Verify with Duo Security for your organization using the Duo Mobile app, SMS, ' +
'phone call, or U2F security key.',
enabled: false,
active: true,
image: 'duo.png',
displayOrder: 1,
priority: 10,
requiresUsb: false,
organization: true
}
],
plans: {
free: {
basePrice: 0,
noAdditionalSeats: true,
noPayment: true,
upgradeSortOrder: -1
},
families: {
basePrice: 1,
annualBasePrice: 12,
baseSeats: 5,
noAdditionalSeats: true,
annualPlanType: 'familiesAnnually',
upgradeSortOrder: 1
},
teams: {
basePrice: 5,
annualBasePrice: 60,
monthlyBasePrice: 8,
baseSeats: 5,
seatPrice: 2,
annualSeatPrice: 24,
monthlySeatPrice: 2.5,
monthPlanType: 'teamsMonthly',
annualPlanType: 'teamsAnnually',
upgradeSortOrder: 2
},
enterprise: {
seatPrice: 3,
annualSeatPrice: 36,
monthlySeatPrice: 4,
monthPlanType: 'enterpriseMonthly',
annualPlanType: 'enterpriseAnnually',
upgradeSortOrder: 3
}
},
storageGb: {
price: 0.33,
monthlyPrice: 0.50,
yearlyPrice: 4
},
premium: {
price: 10,
yearlyPrice: 10
}
});
angular
.module('bit.accounts')
.controller('accountsLoginController', ["$scope", "$rootScope", "$cookies", "apiService", "cryptoService", "authService", "$state", "constants", "$analytics", "$uibModal", "$timeout", "$window", "$filter", "toastr", function ($scope, $rootScope, $cookies, apiService, cryptoService, authService,
$state, constants, $analytics, $uibModal, $timeout, $window, $filter, toastr) {
$scope.state = $state;
$scope.twoFactorProviderConstants = constants.twoFactorProvider;
$scope.rememberTwoFactor = { checked: false };
var stopU2fCheck = true;
$scope.returnState = $state.params.returnState;
$scope.stateEmail = $state.params.email;
if (!$scope.returnState && $state.params.org) {
$scope.returnState = {
name: 'backend.user.settingsCreateOrg',
params: { plan: $state.params.org }
};
}
else if (!$scope.returnState && $state.params.premium) {
$scope.returnState = {
name: 'backend.user.settingsPremium'
};
}
if ($state.current.name.indexOf('twoFactor') > -1 && (!$scope.twoFactorProviders || !$scope.twoFactorProviders.length)) {
$state.go('frontend.login.info', { returnState: $scope.returnState });
}
var rememberedEmail = $cookies.get(constants.rememberedEmailCookieName);
if (rememberedEmail || $scope.stateEmail) {
$scope.model = {
email: $scope.stateEmail || rememberedEmail,
rememberEmail: rememberedEmail !== null
};
$timeout(function () {
$("#masterPassword").focus();
});
}
else {
$timeout(function () {
$("#email").focus();
});
}
var _email,
_masterPassword;
$scope.twoFactorProviders = null;
$scope.twoFactorProvider = null;
$scope.login = function (model) {
$scope.loginPromise = authService.logIn(model.email, model.masterPassword).then(function (twoFactorProviders) {
if (model.rememberEmail) {
var cookieExpiration = new Date();
cookieExpiration.setFullYear(cookieExpiration.getFullYear() + 10);
$cookies.put(
constants.rememberedEmailCookieName,
model.email,
{ expires: cookieExpiration });
}
else {
$cookies.remove(constants.rememberedEmailCookieName);
}
if (twoFactorProviders && Object.keys(twoFactorProviders).length > 0) {
_email = model.email;
_masterPassword = model.masterPassword;
$scope.twoFactorProviders = cleanProviders(twoFactorProviders);
$scope.twoFactorProvider = getDefaultProvider($scope.twoFactorProviders);
$analytics.eventTrack('Logged In To Two-step');
$state.go('frontend.login.twoFactor', { returnState: $scope.returnState }).then(function () {
$timeout(function () {
$("#code").focus();
init();
});
});
}
else {
$analytics.eventTrack('Logged In');
loggedInGo();
}
model.masterPassword = '';
});
};
function getDefaultProvider(twoFactorProviders) {
var keys = Object.keys(twoFactorProviders);
var providerType = null;
var providerPriority = -1;
for (var i = 0; i < keys.length; i++) {
var provider = $filter('filter')(constants.twoFactorProviderInfo, { type: keys[i], active: true });
if (provider.length && provider[0].priority > providerPriority) {
if (provider[0].type === constants.twoFactorProvider.u2f && !u2f.isSupported) {
continue;
}
providerType = provider[0].type;
providerPriority = provider[0].priority;
}
}
if (providerType === null) {
return null;
}
return parseInt(providerType);
}
function cleanProviders(twoFactorProviders) {
if (canUseSecurityKey()) {
return twoFactorProviders;
}
var keys = Object.keys(twoFactorProviders);
for (var i = 0; i < keys.length; i++) {
var provider = $filter('filter')(constants.twoFactorProviderInfo, {
type: keys[i],
active: true,
requiresUsb: false
});
if (!provider.length) {
delete twoFactorProviders[keys[i]];
}
}
return twoFactorProviders;
}
// ref: https://stackoverflow.com/questions/11381673/detecting-a-mobile-browser
function canUseSecurityKey() {
var mobile = false;
(function (a) {
if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0, 4))) {
mobile = true;
}
})(navigator.userAgent || navigator.vendor || window.opera);
return !mobile && !navigator.userAgent.match(/iPad/i);
}
$scope.twoFactor = function (token) {
if ($scope.twoFactorProvider === constants.twoFactorProvider.email ||
$scope.twoFactorProvider === constants.twoFactorProvider.authenticator) {
token = token.replace(' ', '');
}
$scope.twoFactorPromise = authService.logIn(_email, _masterPassword, token, $scope.twoFactorProvider,
$scope.rememberTwoFactor.checked || false);
$scope.twoFactorPromise.then(function () {
$analytics.eventTrack('Logged In From Two-step');
loggedInGo();
}, function () {
if ($scope.twoFactorProvider === constants.twoFactorProvider.u2f) {
init();
}
});
};
$scope.anotherMethod = function () {
var modal = $uibModal.open({
animation: true,
templateUrl: 'app/accounts/views/accountsTwoFactorMethods.html',
controller: 'accountsTwoFactorMethodsController',
resolve: {
providers: function () { return $scope.twoFactorProviders; }
}
});
modal.result.then(function (provider) {
$scope.twoFactorProvider = provider;
$timeout(function () {
$("#code").focus();
init();
});
});
};
$scope.sendEmail = function (doToast) {
if ($scope.twoFactorProvider !== constants.twoFactorProvider.email) {
return;
}
return cryptoService.makeKeyAndHash(_email, _masterPassword).then(function (result) {
return apiService.twoFactor.sendEmailLogin({
email: _email,
masterPasswordHash: result.hash
}).$promise;
}).then(function () {
if (doToast) {
toastr.success('Verification email sent to ' + $scope.twoFactorEmail + '.');
}
}, function () {
toastr.error('Could not send verification email.');
});
};
$scope.$on('$destroy', function () {
stopU2fCheck = true;
});
function loggedInGo() {
if ($scope.returnState) {
$state.go($scope.returnState.name, $scope.returnState.params);
}
else {
$state.go('backend.user.vault');
}
}
function init() {
stopU2fCheck = true;
var params;
if ($scope.twoFactorProvider === constants.twoFactorProvider.duo ||
$scope.twoFactorProvider === constants.twoFactorProvider.organizationDuo) {
params = $scope.twoFactorProviders[$scope.twoFactorProvider];
$window.Duo.init({
host: params.Host,
sig_request: params.Signature,
submit_callback: function (theForm) {
var response = $(theForm).find('input[name="sig_response"]').val();
$scope.twoFactor(response);
}
});
}
else if ($scope.twoFactorProvider === constants.twoFactorProvider.u2f) {
stopU2fCheck = false;
params = $scope.twoFactorProviders[constants.twoFactorProvider.u2f];
var challenges = JSON.parse(params.Challenges);
initU2f(challenges);
}
else if ($scope.twoFactorProvider === constants.twoFactorProvider.email) {
params = $scope.twoFactorProviders[constants.twoFactorProvider.email];
$scope.twoFactorEmail = params.Email;
if (Object.keys($scope.twoFactorProviders).length > 1) {
$scope.sendEmail(false);
}
}
}
function initU2f(challenges) {
if (stopU2fCheck) {
return;
}
if (challenges.length < 1 || $scope.twoFactorProvider !== constants.twoFactorProvider.u2f) {
return;
}
console.log('listening for u2f key...');
$window.u2f.sign(challenges[0].appId, challenges[0].challenge, [{
version: challenges[0].version,
keyHandle: challenges[0].keyHandle
}], function (data) {
if ($scope.twoFactorProvider !== constants.twoFactorProvider.u2f) {
return;
}
if (data.errorCode) {
console.log(data.errorCode);
$timeout(function () {
initU2f(challenges);
}, data.errorCode === 5 ? 0 : 1000);
return;
}
$scope.twoFactor(JSON.stringify(data));
}, 10);
}
}]);
angular
.module('bit.accounts')
.controller('accountsLogoutController', ["$scope", "authService", "$state", "$analytics", function ($scope, authService, $state, $analytics) {
authService.logOut();
$analytics.eventTrack('Logged Out');
$state.go('frontend.login.info');
}]);
angular
.module('bit.accounts')
.controller('accountsOrganizationAcceptController', ["$scope", "$state", "apiService", "authService", "toastr", "$analytics", function ($scope, $state, apiService, authService, toastr, $analytics) {
$scope.state = {
name: $state.current.name,
params: $state.params
};
if (!$state.params.organizationId || !$state.params.organizationUserId || !$state.params.token ||
!$state.params.email || !$state.params.organizationName) {
$state.go('frontend.login.info').then(function () {
toastr.error('Invalid parameters.');
});
return;
}
$scope.$on('$viewContentLoaded', function () {
if (authService.isAuthenticated()) {
$scope.accepting = true;
apiService.organizationUsers.accept(
{
orgId: $state.params.organizationId,
id: $state.params.organizationUserId
},
{
token: $state.params.token
}, function () {
$analytics.eventTrack('Accepted Invitation');
$state.go('backend.user.vault', null, { location: 'replace' }).then(function () {
toastr.success('You can access this organization once an administrator confirms your membership.' +
' We\'ll send an email when that happens.', 'Invite Accepted', { timeOut: 10000 });
});
}, function () {
$analytics.eventTrack('Failed To Accept Invitation');
$state.go('backend.user.vault', null, { location: 'replace' }).then(function () {
toastr.error('Unable to accept invitation.', 'Error');
});
});
}
else {
$scope.loading = false;
}
});
}]);
angular
.module('bit.accounts')
.controller('accountsPasswordHintController', ["$scope", "$rootScope", "apiService", "$analytics", function ($scope, $rootScope, apiService, $analytics) {
$scope.success = false;
$scope.submit = function (model) {
$scope.submitPromise = apiService.accounts.postPasswordHint({ email: model.email }, function () {
$analytics.eventTrack('Requested Password Hint');
$scope.success = true;
}).$promise;
};
}]);
angular
.module('bit.accounts')
.controller('accountsRecoverController', ["$scope", "apiService", "cryptoService", "$analytics", function ($scope, apiService, cryptoService, $analytics) {
$scope.success = false;
$scope.submit = function (model) {
var email = model.email.toLowerCase();
$scope.submitPromise = cryptoService.makeKeyAndHash(model.email, model.masterPassword).then(function (result) {
return apiService.twoFactor.recover({
email: email,
masterPasswordHash: result.hash,
recoveryCode: model.code.replace(/\s/g, '').toLowerCase()
}).$promise;
}).then(function () {
$analytics.eventTrack('Recovered 2FA');
$scope.success = true;
});
};
}]);
angular
.module('bit.accounts')
.controller('accountsRecoverDeleteController', ["$scope", "$rootScope", "apiService", "$analytics", function ($scope, $rootScope, apiService, $analytics) {
$scope.success = false;
$scope.submit = function (model) {
$scope.submitPromise = apiService.accounts.postDeleteRecover({ email: model.email }, function () {
$analytics.eventTrack('Started Delete Recovery');
$scope.success = true;
}).$promise;
};
}]);
angular
.module('bit.accounts')
.controller('accountsRegisterController', ["$scope", "$location", "apiService", "cryptoService", "validationService", "$analytics", "$state", "$timeout", function ($scope, $location, apiService, cryptoService, validationService,
$analytics, $state, $timeout) {
var params = $location.search();
var stateParams = $state.params;
$scope.createOrg = stateParams.org;
if (!stateParams.returnState && stateParams.org) {
$scope.returnState = {
name: 'backend.user.settingsCreateOrg',
params: { plan: $state.params.org }
};
}
else if (!stateParams.returnState && stateParams.premium) {
$scope.returnState = {
name: 'backend.user.settingsPremium',
params: { plan: $state.params.org }
};
}
else {
$scope.returnState = stateParams.returnState;
}
$scope.success = false;
$scope.model = {
email: params.email ? params.email : stateParams.email
};
$scope.readOnlyEmail = stateParams.email !== null;
$timeout(function () {
if ($scope.model.email) {
$("#name").focus();
}
else {
$("#email").focus();
}
});
$scope.registerPromise = null;
$scope.register = function (form) {
var error = false;
if ($scope.model.masterPassword.length < 8) {
validationService.addError(form, 'MasterPassword', 'Master password must be at least 8 characters long.', true);
error = true;
}
if ($scope.model.masterPassword !== $scope.model.confirmMasterPassword) {
validationService.addError(form, 'ConfirmMasterPassword', 'Master password confirmation does not match.', true);
error = true;
}
if (error) {
return;
}
var email = $scope.model.email.toLowerCase();
var makeResult, encKey;
$scope.registerPromise = cryptoService.makeKeyAndHash(email, $scope.model.masterPassword).then(function (result) {
makeResult = result;
encKey = cryptoService.makeEncKey(result.key);
return cryptoService.makeKeyPair(encKey.encKey);
}).then(function (result) {
var request = {
name: $scope.model.name,
email: email,
masterPasswordHash: makeResult.hash,
masterPasswordHint: $scope.model.masterPasswordHint,
key: encKey.encKeyEnc,
keys: {
publicKey: result.publicKey,
encryptedPrivateKey: result.privateKeyEnc
}
};
return apiService.accounts.register(request).$promise;
}, function (errors) {
validationService.addError(form, null, 'Problem generating keys.', true);
return false;
}).then(function (result) {
if (result === false) {
return;
}
$scope.success = true;
$analytics.eventTrack('Registered');
});
};
}]);
angular
.module('bit.accounts')
.controller('accountsTwoFactorMethodsController', ["$scope", "$uibModalInstance", "$analytics", "providers", "constants", function ($scope, $uibModalInstance, $analytics, providers, constants) {
$analytics.eventTrack('accountsTwoFactorMethodsController', { category: 'Modal' });
$scope.providers = [];
if (providers.hasOwnProperty(constants.twoFactorProvider.organizationDuo)) {
add(constants.twoFactorProvider.organizationDuo);
}
if (providers.hasOwnProperty(constants.twoFactorProvider.authenticator)) {
add(constants.twoFactorProvider.authenticator);
}
if (providers.hasOwnProperty(constants.twoFactorProvider.yubikey)) {
add(constants.twoFactorProvider.yubikey);
}
if (providers.hasOwnProperty(constants.twoFactorProvider.email)) {
add(constants.twoFactorProvider.email);
}
if (providers.hasOwnProperty(constants.twoFactorProvider.duo)) {
add(constants.twoFactorProvider.duo);
}
if (providers.hasOwnProperty(constants.twoFactorProvider.u2f) && u2f.isSupported) {
add(constants.twoFactorProvider.u2f);
}
$scope.choose = function (provider) {
$uibModalInstance.close(provider.type);
};
$scope.close = function () {
$uibModalInstance.dismiss('close');
};
function add(type) {
for (var i = 0; i < constants.twoFactorProviderInfo.length; i++) {
if (constants.twoFactorProviderInfo[i].type === type) {
$scope.providers.push(constants.twoFactorProviderInfo[i]);
}
}
}
}]);
angular
.module('bit.accounts')
.controller('accountsVerifyEmailController', ["$scope", "$state", "apiService", "toastr", "$analytics", function ($scope, $state, apiService, toastr, $analytics) {
if (!$state.params.userId || !$state.params.token) {
$state.go('frontend.login.info').then(function () {
toastr.error('Invalid parameters.');
});
return;
}
$scope.$on('$viewContentLoaded', function () {
apiService.accounts.verifyEmailToken({},
{
token: $state.params.token,
userId: $state.params.userId
}, function () {
$analytics.eventTrack('Verified Email');
$state.go('frontend.login.info', null, { location: 'replace' }).then(function () {
toastr.success('Your email has been verified. Thank you.', 'Success');
});
}, function () {
$state.go('frontend.login.info', null, { location: 'replace' }).then(function () {
toastr.error('Unable to verify email.', 'Error');
});
});
});
}]);
angular
.module('bit.accounts')
.controller('accountsVerifyRecoverDeleteController', ["$scope", "$state", "apiService", "toastr", "$analytics", function ($scope, $state, apiService, toastr, $analytics) {
if (!$state.params.userId || !$state.params.token || !$state.params.email) {
$state.go('frontend.login.info').then(function () {
toastr.error('Invalid parameters.');
});
return;
}
$scope.email = $state.params.email;
$scope.delete = function () {
if (!confirm('Are you sure you want to delete this account? This cannot be undone.')) {
return;
}
$scope.deleting = true;
apiService.accounts.postDeleteRecoverToken({},
{
token: $state.params.token,
userId: $state.params.userId
}, function () {
$analytics.eventTrack('Recovered Delete');
$state.go('frontend.login.info', null, { location: 'replace' }).then(function () {
toastr.success('Your account has been deleted. You can register a new account again if you like.',
'Success');
});
}, function () {
$state.go('frontend.login.info', null, { location: 'replace' }).then(function () {
toastr.error('Unable to delete account.', 'Error');
});
});
};
}]);
angular
.module('bit.directives')
.directive('apiField', function () {
var linkFn = function (scope, element, attrs, ngModel) {
ngModel.$registerApiError = registerApiError;
ngModel.$validators.apiValidate = apiValidator;
function apiValidator() {
ngModel.$setValidity('api', true);
return true;
}
function registerApiError() {
ngModel.$setValidity('api', false);
}
};
return {
require: 'ngModel',
restrict: 'A',
compile: function (elem, attrs) {
if (!attrs.name || attrs.name === '') {
throw 'api-field element does not have a valid name attribute';
}
return linkFn;
}
};
});
angular
.module('bit.directives')
.directive('apiForm', ["$rootScope", "validationService", "$timeout", function ($rootScope, validationService, $timeout) {
return {
require: 'form',
restrict: 'A',
link: function (scope, element, attrs, formCtrl) {
var watchPromise = attrs.apiForm || null;
if (watchPromise !== void 0) {
scope.$watch(watchPromise, formSubmitted.bind(null, formCtrl, scope));
}
}
};
function formSubmitted(form, scope, promise) {
if (!promise || !promise.then) {
return;
}
// reset errors
form.$errors = null;
// start loading
form.$loading = true;
promise.then(function success(response) {
$timeout(function () {
form.$loading = false;
});
}, function failure(reason) {
$timeout(function () {
form.$loading = false;
if (typeof reason === 'string') {
validationService.addError(form, null, reason, true);
}
else {
validationService.addErrors(form, reason);
}
scope.$broadcast('show-errors-check-validity');
$('html, body').animate({ scrollTop: 0 }, 200);
});
});
}
}]);
angular
.module('bit.directives')
.directive('fallbackSrc', function () {
return function (scope, element, attrs) {
var el = $(element);
el.bind('error', function (event) {
el.attr('src', attrs.fallbackSrc);
});
};
});
angular
.module('bit.directives')
// adaptation of https://github.com/uttesh/ngletteravatar
.directive('letterAvatar', function () {
// ref: http://stackoverflow.com/a/16348977/1090359
function stringToColor(str) {
var hash = 0,
i = 0;
for (i = 0; i < str.length; i++) {
hash = str.charCodeAt(i) + ((hash << 5) - hash);
}
var color = '#';
for (i = 0; i < 3; i++) {
var value = (hash >> (i * 8)) & 0xFF;
color += ('00' + value.toString(16)).substr(-2);
}
return color;
}
function getFirstLetters(data, count) {
var parts = data.split(' ');
if (parts && parts.length > 1) {
var text = '';
for (var i = 0; i < count; i++) {
text += parts[i].substr(0, 1);
}
return text;
}
return null;
}
function getSvg(width, height, color) {
var svgTag = angular.element('')
.attr({
'xmlns': 'http://www.w3.org/2000/svg',
'pointer-events': 'none',
'width': width,
'height': height
})
.css({
'background-color': color,
'width': width + 'px',
'height': height + 'px'
});
return svgTag;
}
function getCharText(character, textColor, fontFamily, fontWeight, fontsize) {
var textTag = angular.element('
' + shortId + '';
}
return '' +
'' + shortId + '';
}
function formatGroupId(ev) {
var shortId = ev.GroupId.substring(0, 8);
return '' +
'' + shortId + '';
}
function formatCollectionId(ev) {
var shortId = ev.CollectionId.substring(0, 8);
return '' +
'' + shortId + '';
}
function formatOrgUserId(ev) {
var shortId = ev.OrganizationUserId.substring(0, 8);
return '' +
'' + shortId + '';
}
return _service;
}]);
angular
.module('bit.services')
.factory('importService', ["constants", function (constants) {
var _service = {};
_service.import = function (source, file, success, error) {
if (!file) {
error();
return;
}
switch (source) {
case 'bitwardencsv':
importBitwardenCsv(file, success, error);
break;
case 'lastpass':
importLastPass(file, success, error, false);
break;
case 'safeincloudxml':
importSafeInCloudXml(file, success, error);
break;
case 'keepass2xml':
importKeePass2Xml(file, success, error);
break;
case 'keepassxcsv':
importKeePassXCsv(file, success, error);
break;
case 'padlockcsv':
importPadlockCsv(file, success, error);
break;
case '1password1pif':
import1Password1Pif(file, success, error);
break;
case '1password6wincsv':
import1Password6WinCsv(file, success, error);
break;
case 'chromecsv':
case 'vivaldicsv':
case 'operacsv':
importChromeCsv(file, success, error);
break;
case 'firefoxpasswordexportercsv':
importFirefoxPasswordExporterCsv(file, success, error);
break;
case 'upmcsv':
importUpmCsv(file, success, error);
break;
case 'keepercsv':
importKeeperCsv(file, success, error);
break;
case 'passworddragonxml':
importPasswordDragonXml(file, success, error);
break;
case 'enpasscsv':
importEnpassCsv(file, success, error);
break;
case 'pwsafexml':
importPasswordSafeXml(file, success, error);
break;
case 'dashlanecsv':
importDashlaneCsv(file, success, error);
break;
case 'stickypasswordxml':
importStickyPasswordXml(file, success, error);
break;
case 'msecurecsv':
importmSecureCsv(file, success, error);
break;
case 'truekeycsv':
importTrueKeyCsv(file, success, error);
break;
case 'clipperzhtml':
importClipperzHtml(file, success, error);
break;
case 'avirajson':
importAviraJson(file, success, error);
break;
case 'roboformhtml':
importRoboFormHtml(file, success, error);
break;
case 'saferpasscsv':
importSaferPassCsv(file, success, error);
break;
case 'ascendocsv':
importAscendoCsv(file, success, error);
break;
case 'passwordbossjson':
importPasswordBossJson(file, success, error);
break;
case 'zohovaultcsv':
importZohoVaultCsv(file, success, error);
break;
case 'splashidcsv':
importSplashIdCsv(file, success, error);
break;
case 'meldiumcsv':
importMeldiumCsv(file, success, error);
break;
case 'passkeepcsv':
importPassKeepCsv(file, success, error);
break;
case 'gnomejson':
importGnomeJson(file, success, error);
break;
default:
error();
break;
}
};
_service.importOrg = function (source, file, success, error) {
if (!file) {
error();
return;
}
switch (source) {
case 'bitwardencsv':
importBitwardenOrgCsv(file, success, error);
break;
case 'lastpass':
importLastPass(file, success, error, true);
break;
default:
error();
break;
}
};
// helpers
var _passwordFieldNames = [
'password', 'pass word', 'passphrase', 'pass phrase',
'pass', 'code', 'code word', 'codeword',
'secret', 'secret word', 'personpwd',
'key', 'keyword', 'key word', 'keyphrase', 'key phrase',
'form_pw', 'wppassword', 'pin', 'pwd', 'pw', 'pword', 'passwd',
'p', 'serial', 'serial#', 'license key', 'reg #',
// Non-English names
'passwort'
];
var _usernameFieldNames = [
'user', 'name', 'user name', 'username', 'login name',
'email', 'e-mail', 'id', 'userid', 'user id',
'login', 'form_loginname', 'wpname', 'mail',
'loginid', 'login id', 'log', 'personlogin',
'first name', 'last name', 'card#', 'account #',
'member', 'member #',
// Non-English names
'nom', 'benutzername'
];
var _notesFieldNames = [
"note", "notes", "comment", "comments", "memo",
"description", "free form", "freeform",
"free text", "freetext", "free",
// Non-English names
"kommentar"
];
var _uriFieldNames = [
'url', 'hyper link', 'hyperlink', 'link',
'host', 'hostname', 'host name', 'server', 'address',
'hyper ref', 'href', 'web', 'website', 'web site', 'site',
'web-site', 'uri',
// Non-English names
'ort', 'adresse'
];
function loginNameFromUrl(url) {
var a = document.createElement('a');
a.href = url;
return a.hostname.startsWith('www.') ? a.hostname.replace('www.', '') : a.hostname;
}
function isField(fieldText, refFieldValues) {
if (!fieldText || fieldText === '') {
return false;
}
fieldText = fieldText.trim().toLowerCase();
for (var i = 0; i < refFieldValues.length; i++) {
if (fieldText === refFieldValues[i]) {
return true;
}
}
return false;
}
function fixUri(uri) {
uri = uri.toLowerCase().trim();
if (uri.indexOf('://') === -1 && uri.indexOf('.') >= 0) {
uri = 'http://' + uri;
}
if (uri.length > 1000) {
return uri.substring(0, 1000);
}
return uri;
}
function makeUriArray(uri) {
if (!uri) {
return null;
}
if (typeof uri === 'string') {
return [{
uri: fixUri(uri),
match: null
}];
}
if (uri.length) {
var returnArr = [];
for (var i = 0; i < uri.length; i++) {
returnArr.push({
uri: fixUri(uri[i]),
match: null
});
}
return returnArr;
}
return null;
}
function parseSingleRowCsv(rowData) {
if (!rowData || rowData === '') {
return null;
}
var parsedRow = Papa.parse(rowData);
if (parsedRow && parsedRow.data && parsedRow.data.length && parsedRow.data[0].length) {
return parsedRow.data[0];
}
return null;
}
function parseCsvErrors(results) {
if (results.errors && results.errors.length) {
for (var i = 0; i < results.errors.length; i++) {
console.warn('Error parsing row ' + results.errors[i].row + ': ' + results.errors[i].message);
}
}
}
function getFileContents(file, contentsCallback, errorCallback) {
if (typeof file === 'string') {
contentsCallback(file);
}
else {
var reader = new FileReader();
reader.readAsText(file, 'utf-8');
reader.onload = function (evt) {
contentsCallback(evt.target.result);
};
reader.onerror = function (evt) {
errorCallback();
};
}
}
function getXmlFileContents(file, xmlCallback, errorCallback) {
getFileContents(file, function (fileContents) {
xmlCallback($.parseXML(fileContents));
}, errorCallback);
}
// ref https://stackoverflow.com/a/5911300
function getCardType(number) {
if (!number) {
return null;
}
// Visa
var re = new RegExp('^4');
if (number.match(re) != null) {
return 'Visa';
}
// Mastercard
// Updated for Mastercard 2017 BINs expansion
if (/^(5[1-5][0-9]{14}|2(22[1-9][0-9]{12}|2[3-9][0-9]{13}|[3-6][0-9]{14}|7[0-1][0-9]{13}|720[0-9]{12}))$/.test(number)) {
return 'Mastercard';
}
// AMEX
re = new RegExp('^3[47]');
if (number.match(re) != null) {
return 'Amex';
}
// Discover
re = new RegExp('^(6011|622(12[6-9]|1[3-9][0-9]|[2-8][0-9]{2}|9[0-1][0-9]|92[0-5]|64[4-9])|65)');
if (number.match(re) != null) {
return 'Discover';
}
// Diners
re = new RegExp('^36');
if (number.match(re) != null) {
return 'Diners Club';
}
// Diners - Carte Blanche
re = new RegExp('^30[0-5]');
if (number.match(re) != null) {
return 'Diners Club';
}
// JCB
re = new RegExp('^35(2[89]|[3-8][0-9])');
if (number.match(re) != null) {
return 'JCB';
}
// Visa Electron
re = new RegExp('^(4026|417500|4508|4844|491(3|7))');
if (number.match(re) != null) {
return 'Visa';
}
return null;
}
// importers
function importBitwardenCsv(file, success, error) {
Papa.parse(file, {
header: true,
encoding: 'UTF-8',
complete: function (results) {
parseCsvErrors(results);
var folders = [],
ciphers = [],
folderRelationships = [],
i = 0;
angular.forEach(results.data, function (value, key) {
var folderIndex = folders.length,
cipherIndex = ciphers.length,
hasFolder = value.folder && value.folder !== '',
addFolder = hasFolder;
if (hasFolder) {
for (i = 0; i < folders.length; i++) {
if (folders[i].name === value.folder) {
addFolder = false;
folderIndex = i;
break;
}
}
}
var cipher = {
favorite: value.favorite && value.favorite !== '' && value.favorite !== '0' ? true : false,
notes: value.notes && value.notes !== '' ? value.notes : null,
name: value.name && value.name !== '' ? value.name : '--',
type: constants.cipherType.login
};
if (value.fields && value.fields !== '') {
var fields = value.fields.split(/(?:\r\n|\r|\n)/);
for (i = 0; i < fields.length; i++) {
if (!fields[i] || fields[i] === '') {
continue;
}
var delimPosition = fields[i].lastIndexOf(': ');
if (delimPosition === -1) {
continue;
}
if (!cipher.fields) {
cipher.fields = [];
}
var field = {
name: fields[i].substr(0, delimPosition),
value: null,
type: constants.fieldType.text
};
if (fields[i].length > (delimPosition + 2)) {
field.value = fields[i].substr(delimPosition + 2);
}
cipher.fields.push(field);
}
}
var valueType = value.type ? value.type.toLowerCase() : null;
switch (valueType) {
case 'login':
case null:
case undefined:
cipher.type = constants.cipherType.login;
var totp = value.login_totp || value.totp;
var uris = parseSingleRowCsv(value.login_uri || value.uri);
var username = value.login_username || value.username;
var password = value.login_password || value.password;
cipher.login = {
totp: totp && totp !== '' ? totp : null,
uris: makeUriArray(uris),
username: username && username !== '' ? username : null,
password: password && password !== '' ? password : null
};
break;
case 'note':
cipher.type = constants.cipherType.secureNote;
cipher.secureNote = {
type: 0 // generic note
};
break;
default:
break;
}
ciphers.push(cipher);
if (addFolder) {
folders.push({
name: value.folder
});
}
if (hasFolder) {
var relationship = {
key: cipherIndex,
value: folderIndex
};
folderRelationships.push(relationship);
}
});
success(folders, ciphers, folderRelationships);
}
});
}
function importBitwardenOrgCsv(file, success, error) {
Papa.parse(file, {
header: true,
encoding: 'UTF-8',
complete: function (results) {
parseCsvErrors(results);
var collections = [],
ciphers = [],
collectionRelationships = [],
i;
angular.forEach(results.data, function (value, key) {
var cipherIndex = ciphers.length;
if (value.collections && value.collections !== '') {
var cipherCollections = value.collections.split(',');
for (i = 0; i < cipherCollections.length; i++) {
var addCollection = true;
var collectionIndex = collections.length;
for (var j = 0; j < collections.length; j++) {
if (collections[j].name === cipherCollections[i]) {
addCollection = false;
collectionIndex = j;
break;
}
}
if (addCollection) {
collections.push({
name: cipherCollections[i]
});
}
collectionRelationships.push({
key: cipherIndex,
value: collectionIndex
});
}
}
var cipher = {
favorite: false,
notes: value.notes && value.notes !== '' ? value.notes : null,
name: value.name && value.name !== '' ? value.name : '--',
type: constants.cipherType.login
};
if (value.fields && value.fields !== '') {
var fields = value.fields.split(/(?:\r\n|\r|\n)/);
for (i = 0; i < fields.length; i++) {
if (!fields[i] || fields[i] === '') {
continue;
}
var delimPosition = fields[i].lastIndexOf(': ');
if (delimPosition === -1) {
continue;
}
if (!cipher.fields) {
cipher.fields = [];
}
var field = {
name: fields[i].substr(0, delimPosition),
value: null,
type: constants.fieldType.text
};
if (fields[i].length > (delimPosition + 2)) {
field.value = fields[i].substr(delimPosition + 2);
}
cipher.fields.push(field);
}
}
var valueType = value.type ? value.type.toLowerCase() : null;
switch (valueType) {
case 'login':
case null:
case undefined:
cipher.type = constants.cipherType.login;
var totp = value.login_totp || value.totp;
var uris = parseSingleRowCsv(value.login_uri || value.uri);
var username = value.login_username || value.username;
var password = value.login_password || value.password;
cipher.login = {
totp: totp && totp !== '' ? totp : null,
uris: makeUriArray(uris),
username: username && username !== '' ? username : null,
password: password && password !== '' ? password : null
};
break;
case 'note':
cipher.type = constants.cipherType.secureNote;
cipher.secureNote = {
type: 0 // generic note
};
break;
default:
break;
}
ciphers.push(cipher);
});
success(collections, ciphers, collectionRelationships);
}
});
}
function importLastPass(file, success, error, org) {
if (typeof file !== 'string' && file.type && file.type === 'text/html') {
var reader = new FileReader();
reader.readAsText(file, 'utf-8');
reader.onload = function (evt) {
var doc = $(evt.target.result);
var pre = doc.find('pre');
var csv, results;
if (pre.length === 1) {
csv = pre.text().trim();
results = Papa.parse(csv, {
header: true,
encoding: 'UTF-8'
});
parseData(results.data);
}
else {
var foundPre = false;
for (var i = 0; i < doc.length; i++) {
if (doc[i].tagName.toLowerCase() === 'pre') {
foundPre = true;
csv = doc[i].outerText.trim();
results = Papa.parse(csv, {
header: true,
encoding: 'UTF-8'
});
parseData(results.data);
break;
}
}
if (!foundPre) {
error();
}
}
};
reader.onerror = function (evt) {
error();
};
}
else {
Papa.parse(file, {
header: true,
encoding: 'UTF-8',
complete: function (results) {
parseCsvErrors(results);
parseData(results.data);
},
beforeFirstChunk: function (chunk) {
return chunk.replace(/^\s+/, '');
}
});
}
function parseSecureNoteMapping(extraParts, map, skip) {
var obj = {
dataObj: {},
notes: null
};
for (var i = 0; i < extraParts.length; i++) {
var fieldParts = extraParts[i].split(':');
if (fieldParts.length < 1 || fieldParts[0] === 'NoteType' || skip.indexOf(fieldParts[0]) > -1 ||
!fieldParts[1] || fieldParts[1] === '') {
continue;
}
if (fieldParts[0] === 'Notes') {
if (obj.notes) {
obj.notes += ('\n' + fieldParts[1]);
}
else {
obj.notes = fieldParts[1];
}
}
else if (map.hasOwnProperty(fieldParts[0])) {
obj.dataObj[map[fieldParts[0]]] = fieldParts[1];
}
else {
if (obj.notes) {
obj.notes += '\n';
}
else {
obj.notes = '';
}
obj.notes += (fieldParts[0] + ': ' + fieldParts[1]);
}
}
return obj;
}
function parseCard(value) {
var cardData = {
cardholderName: value.ccname && value.ccname !== '' ? value.ccname : null,
number: value.ccnum && value.ccnum !== '' ? value.ccnum : null,
brand: value.ccnum && value.ccnum !== '' ? getCardType(value.ccnum) : null,
code: value.cccsc && value.cccsc !== '' ? value.cccsc : null
};
if (value.ccexp && value.ccexp !== '' && value.ccexp.indexOf('-') > -1) {
var ccexpParts = value.ccexp.split('-');
if (ccexpParts.length > 1) {
cardData.expYear = ccexpParts[0];
cardData.expMonth = ccexpParts[1];
if (cardData.expMonth.length === 2 && cardData.expMonth[0] === '0') {
cardData.expMonth = cardData.expMonth[1];
}
}
}
return cardData;
}
function parseData(data) {
var folders = [],
ciphers = [],
cipherRelationships = [],
i = 0;
angular.forEach(data, function (value, key) {
var folderIndex = folders.length,
cipherIndex = ciphers.length,
hasFolder = value.grouping && value.grouping !== '' && value.grouping !== '(none)',
addFolder = hasFolder;
if (hasFolder) {
for (i = 0; i < folders.length; i++) {
if (folders[i].name === value.grouping) {
addFolder = false;
folderIndex = i;
break;
}
}
}
var cipher;
if (value.hasOwnProperty('profilename') && value.hasOwnProperty('profilelanguage')) {
// form fill
cipher = {
favorite: false,
name: value.profilename && value.profilename !== '' ? value.profilename : '--',
type: constants.cipherType.card
};
if (value.title !== '' || value.firstname !== '' || value.lastname !== '' ||
value.address1 !== '' || value.phone !== '' || value.username !== '' ||
value.email !== '') {
cipher.type = constants.cipherType.identity;
}
}
else {
// site or secure note
cipher = {
favorite: org ? false : value.fav === '1',
name: value.name && value.name !== '' ? value.name : '--',
type: value.url === 'http://sn' ? constants.cipherType.secureNote : constants.cipherType.login
};
}
if (cipher.type === constants.cipherType.login) {
cipher.login = {
uris: makeUriArray(value.url),
username: value.username && value.username !== '' ? value.username : null,
password: value.password && value.password !== '' ? value.password : null
};
cipher.notes = value.extra && value.extra !== '' ? value.extra : null;
}
else if (cipher.type === constants.cipherType.secureNote) {
var extraParts = value.extra.split(/(?:\r\n|\r|\n)/),
processedNote = false;
if (extraParts.length) {
var typeParts = extraParts[0].split(':');
if (typeParts.length > 1 && typeParts[0] === 'NoteType' &&
(typeParts[1] === 'Credit Card' || typeParts[1] === 'Address')) {
var mappedData = null;
if (typeParts[1] === 'Credit Card') {
mappedData = parseSecureNoteMapping(extraParts, {
'Number': 'number',
'Name on Card': 'cardholderName',
'Security Code': 'code'
}, []);
cipher.type = constants.cipherType.card;
cipher.card = mappedData.dataObj;
}
else if (typeParts[1] === 'Address') {
mappedData = parseSecureNoteMapping(extraParts, {
'Title': 'title',
'First Name': 'firstName',
'Last Name': 'lastName',
'Middle Name': 'middleName',
'Company': 'company',
'Address 1': 'address1',
'Address 2': 'address2',
'Address 3': 'address3',
'City / Town': 'city',
'State': 'state',
'Zip / Postal Code': 'postalCode',
'Country': 'country',
'Email Address': 'email',
'Username': 'username'
}, []);
cipher.type = constants.cipherType.identity;
cipher.identity = mappedData.dataObj;
}
processedNote = true;
cipher.notes = mappedData.notes;
}
}
if (!processedNote) {
cipher.secureNote = {
type: 0
};
cipher.notes = value.extra && value.extra !== '' ? value.extra : null;
}
}
else if (cipher.type === constants.cipherType.card) {
cipher.card = parseCard(value);
cipher.notes = value.notes && value.notes !== '' ? value.notes : null;
}
else if (cipher.type === constants.cipherType.identity) {
cipher.identity = {
title: value.title && value.title !== '' ? value.title : null,
firstName: value.firstname && value.firstname !== '' ? value.firstname : null,
middleName: value.middlename && value.middlename !== '' ? value.middlename : null,
lastName: value.lastname && value.lastname !== '' ? value.lastname : null,
username: value.username && value.username !== '' ? value.username : null,
company: value.company && value.company !== '' ? value.company : null,
ssn: value.ssn && value.ssn !== '' ? value.ssn : null,
address1: value.address1 && value.address1 !== '' ? value.address1 : null,
address2: value.address2 && value.address2 !== '' ? value.address2 : null,
address3: value.address3 && value.address3 !== '' ? value.address3 : null,
city: value.city && value.city !== '' ? value.city : null,
state: value.state && value.state !== '' ? value.state : null,
postalCode: value.zip && value.zip !== '' ? value.zip : null,
country: value.country && value.country !== '' ? value.country : null,
email: value.email && value.email !== '' ? value.email : null,
phone: value.phone && value.phone !== '' ? value.phone : null
};
cipher.notes = value.notes && value.notes !== '' ? value.notes : null;
if (cipher.identity.title) {
cipher.identity.title = cipher.identity.title.charAt(0).toUpperCase() +
cipher.identity.title.slice(1);
}
if (value.ccnum && value.ccnum !== '') {
// there is a card on this identity too
var cardCipher = JSON.parse(JSON.stringify(cipher)); // cloned
cardCipher.identity = null;
cardCipher.type = constants.cipherType.card;
cardCipher.card = parseCard(value);
ciphers.push(cardCipher);
}
}
ciphers.push(cipher);
if (addFolder) {
folders.push({
name: value.grouping
});
}
if (hasFolder) {
var relationship = {
key: cipherIndex,
value: folderIndex
};
cipherRelationships.push(relationship);
}
});
success(folders, ciphers, cipherRelationships);
}
}
function importSafeInCloudXml(file, success, error) {
var folders = [],
ciphers = [],
cipherRelationships = [],
foldersIndex = [],
i = 0,
j = 0;
getXmlFileContents(file, parse, error);
function parse(xmlDoc) {
var xml = $(xmlDoc);
var db = xml.find('database');
if (db.length) {
var labels = db.find('> label');
if (labels.length) {
for (i = 0; i < labels.length; i++) {
var label = $(labels[i]);
foldersIndex[label.attr('id')] = folders.length;
folders.push({
name: label.attr('name')
});
}
}
var cards = db.find('> card');
if (cards.length) {
for (i = 0; i < cards.length; i++) {
var card = $(cards[i]);
if (card.attr('template') === 'true') {
continue;
}
var cipher = {
favorite: false,
notes: '',
name: card.attr('title'),
fields: null
};
if (!cipher.name || cipher.name === '') {
cipher.name = '--';
}
if (card.attr('type') === 'note') {
cipher.type = constants.cipherType.secureNote;
cipher.secureNote = {
type: 0 // generic note
};
}
else {
cipher.type = constants.cipherType.login;
cipher.login = {};
var fields = card.find('> field');
for (j = 0; j < fields.length; j++) {
var field = $(fields[j]);
var text = field.text();
var type = field.attr('type');
var name = field.attr('name');
if (text && text !== '') {
if (type === 'login') {
cipher.login.username = text;
}
else if (type === 'password') {
cipher.login.password = text;
}
else if (type === 'notes') {
cipher.notes += (text + '\n');
}
else if (type === 'weblogin' || type === 'website') {
cipher.login.uris = makeUriArray(text);
}
else if (text.length > 200) {
cipher.notes += (name + ': ' + text + '\n');
}
else {
if (!cipher.fields) {
cipher.fields = [];
}
cipher.fields.push({
name: name,
value: text,
type: constants.fieldType.text
});
}
}
}
}
var notes = card.find('> notes');
for (j = 0; j < notes.length; j++) {
cipher.notes += ($(notes[j]).text() + '\n');
}
if (cipher.notes === '') {
cipher.notes = null;
}
ciphers.push(cipher);
labels = card.find('> label_id');
if (labels.length) {
var labelId = $(labels[0]).text();
var folderIndex = foldersIndex[labelId];
if (labelId !== null && labelId !== '' && folderIndex !== null) {
cipherRelationships.push({
key: ciphers.length - 1,
value: folderIndex
});
}
}
}
}
success(folders, ciphers, cipherRelationships);
}
else {
error();
}
}
}
function importPadlockCsv(file, success, error) {
Papa.parse(file, {
encoding: 'UTF-8',
complete: function (results) {
parseCsvErrors(results);
var folders = [],
ciphers = [],
folderRelationships = [];
var customFieldHeaders = [];
// CSV index ref: 0 = name, 1 = category, 2 = username, 3 = password, 4+ = custom fields
var i = 0,
j = 0;
for (i = 0; i < results.data.length; i++) {
var value = results.data[i];
if (i === 0) {
// header row
for (j = 4; j < value.length; j++) {
customFieldHeaders.push(value[j]);
}
continue;
}
var folderIndex = folders.length,
cipherIndex = ciphers.length,
hasFolder = value[1] && value[1] !== '',
addFolder = hasFolder;
if (hasFolder) {
for (j = 0; j < folders.length; j++) {
if (folders[j].name === value[1]) {
addFolder = false;
folderIndex = j;
break;
}
}
}
var cipher = {
favorite: false,
type: constants.cipherType.login,
notes: null,
name: value[0] && value[0] !== '' ? value[0] : '--',
login: {
uris: null,
username: value[2] && value[2] !== '' ? value[2] : null,
password: value[3] && value[3] !== '' ? value[3] : null
},
fields: null
};
if (customFieldHeaders.length) {
for (j = 4; j < value.length; j++) {
var cf = value[j];
if (!cf || cf === '') {
continue;
}
var cfHeader = customFieldHeaders[j - 4];
if (cfHeader.toLowerCase() === 'url' || cfHeader.toLowerCase() === 'uri') {
cipher.login.uris = makeUriArray(cf);
}
else {
if (!cipher.fields) {
cipher.fields = [];
}
cipher.fields.push({
name: cfHeader,
value: cf,
type: constants.fieldType.text
});
}
}
}
ciphers.push(cipher);
if (addFolder) {
folders.push({
name: value[1]
});
}
if (hasFolder) {
folderRelationships.push({
key: cipherIndex,
value: folderIndex
});
}
}
success(folders, ciphers, folderRelationships);
}
});
}
function importKeePass2Xml(file, success, error) {
var folders = [],
ciphers = [],
folderRelationships = [];
getXmlFileContents(file, parse, error);
function parse(xmlDoc) {
var xml = $(xmlDoc);
var root = xml.find('Root');
if (root.length) {
var group = root.find('> Group');
if (group.length) {
traverse($(group[0]), true, '');
success(folders, ciphers, folderRelationships);
}
}
else {
error();
}
}
function traverse(node, isRootNode, groupNamePrefix) {
var nodeEntries = [];
var folderIndex = folders.length;
var groupName = groupNamePrefix;
if (!isRootNode) {
if (groupName !== '') {
groupName += ' > ';
}
groupName += node.find('> Name').text();
folders.push({
name: groupName
});
}
var entries = node.find('> Entry');
if (entries.length) {
for (var i = 0; i < entries.length; i++) {
var entry = $(entries[i]);
var cipherIndex = ciphers.length;
var cipher = {
favorite: false,
notes: null,
name: null,
type: constants.cipherType.login,
login: {
uris: null,
username: null,
password: null
},
fields: null
};
var entryStrings = entry.find('> String');
for (var j = 0; j < entryStrings.length; j++) {
var entryString = $(entryStrings[j]);
var key = entryString.find('> Key').text();
var value = entryString.find('> Value').text();
if (value === '') {
continue;
}
switch (key) {
case 'URL':
cipher.login.uris = makeUriArray(value);
break;
case 'UserName':
cipher.login.username = value;
break;
case 'Password':
cipher.login.password = value;
break;
case 'Title':
cipher.name = value;
break;
case 'Notes':
cipher.notes = cipher.notes === null ? value + '\n' : cipher.notes + value + '\n';
break;
default:
if (value.length > 200 || value.indexOf('\n') > -1) {
if (!cipher.notes) {
cipher.notes = '';
}
cipher.notes += (key + ': ' + value + '\n');
}
else {
if (!cipher.fields) {
cipher.fields = [];
}
// other custom fields
cipher.fields.push({
name: key,
value: value,
type: constants.fieldType.text
});
}
break;
}
}
if (cipher.name === null) {
cipher.name = '--';
}
ciphers.push(cipher);
if (!isRootNode) {
folderRelationships.push({
key: cipherIndex,
value: folderIndex
});
}
}
}
var groups = node.find('> Group');
if (groups.length) {
for (var k = 0; k < groups.length; k++) {
traverse($(groups[k]), false, groupName);
}
}
}
}
function importKeePassXCsv(file, success, error) {
Papa.parse(file, {
header: true,
encoding: 'UTF-8',
complete: function (results) {
parseCsvErrors(results);
var folders = [],
ciphers = [],
folderRelationships = [];
angular.forEach(results.data, function (value, key) {
value.Group = value.Group.startsWith('Root/') ?
value.Group.replace('Root/', '') : value.Group;
var groupName = value.Group && value.Group !== '' ?
value.Group.split('/').join(' > ') : null;
var folderIndex = folders.length,
cipherIndex = ciphers.length,
hasFolder = groupName !== null,
addFolder = hasFolder,
i = 0;
if (hasFolder) {
for (i = 0; i < folders.length; i++) {
if (folders[i].name === groupName) {
addFolder = false;
folderIndex = i;
break;
}
}
}
var cipher = {
type: constants.cipherType.login,
favorite: false,
notes: value.Notes && value.Notes !== '' ? value.Notes : null,
name: value.Title && value.Title !== '' ? value.Title : '--',
login: {
uris: makeUriArray(value.URL),
username: value.Username && value.Username !== '' ? value.Username : null,
password: value.Password && value.Password !== '' ? value.Password : null
}
};
if (value.Title) {
ciphers.push(cipher);
}
if (addFolder) {
folders.push({
name: groupName
});
}
if (hasFolder) {
var relationship = {
key: cipherIndex,
value: folderIndex
};
folderRelationships.push(relationship);
}
});
success(folders, ciphers, folderRelationships);
}
});
}
function import1Password1Pif(file, success, error) {
var folders = [],
ciphers = [],
i = 0;
function parseFields(fields, cipher, designationKey, valueKey, nameKey) {
for (var j = 0; j < fields.length; j++) {
var field = fields[j];
if (!field[valueKey] || field[valueKey] === '') {
continue;
}
var fieldValue = field[valueKey].toString();
if (cipher.type == constants.cipherType.login && !cipher.login.username &&
field[designationKey] && field[designationKey] === 'username') {
cipher.login.username = fieldValue;
}
else if (cipher.type == constants.cipherType.login && !cipher.login.password &&
field[designationKey] && field[designationKey] === 'password') {
cipher.login.password = fieldValue;
}
else if (cipher.type == constants.cipherType.login && !cipher.login.totp &&
field[designationKey] && field[designationKey].startsWith("TOTP_")) {
cipher.login.totp = fieldValue;
}
else if (fieldValue) {
var fieldName = (field[nameKey] || 'no_name');
if (fieldValue.indexOf('\\n') > -1 || fieldValue.length > 200) {
if (cipher.notes === null) {
cipher.notes = '';
}
else {
cipher.notes += '\n';
}
cipher.notes += (fieldName + ': ' +
fieldValue.split('\\r\\n').join('\n').split('\\n').join('\n'));
}
else {
if (!cipher.fields) {
cipher.fields = [];
}
cipher.fields.push({
name: fieldName,
value: fieldValue,
type: constants.fieldType.text
});
}
}
}
}
getFileContents(file, parse, error);
function parse(fileContent) {
var fileLines = fileContent.split(/(?:\r\n|\r|\n)/);
for (i = 0; i < fileLines.length; i++) {
var line = fileLines[i];
if (!line.length || line[0] !== '{') {
continue;
}
var item = JSON.parse(line);
var cipher = {
type: constants.cipherType.login,
favorite: item.openContents && item.openContents.faveIndex ? true : false,
notes: null,
name: item.title && item.title !== '' ? item.title : '--',
fields: null
};
if (item.typeName === 'securenotes.SecureNote') {
cipher.type = constants.cipherType.secureNote;
cipher.secureNote = {
type: 0 // generic note
};
}
else {
cipher.type = constants.cipherType.login;
cipher.login = {
uris: makeUriArray(item.location),
username: null,
password: null,
totp: null
};
}
if (item.secureContents) {
if (item.secureContents.notesPlain && item.secureContents.notesPlain !== '') {
cipher.notes = item.secureContents.notesPlain
.split('\\r\\n').join('\n').split('\\n').join('\n');
}
if (item.secureContents.fields) {
parseFields(item.secureContents.fields, cipher, 'designation', 'value', 'name');
}
if (item.secureContents.sections) {
for (var j = 0; j < item.secureContents.sections.length; j++) {
if (item.secureContents.sections[j].fields) {
parseFields(item.secureContents.sections[j].fields, cipher, 'n', 'v', 't');
}
}
}
}
ciphers.push(cipher);
}
success(folders, ciphers, []);
}
}
function import1Password6WinCsv(file, success, error) {
var folders = [],
ciphers = [];
Papa.parse(file, {
encoding: 'UTF-8',
header: true,
complete: function (results) {
parseCsvErrors(results);
for (var i = 0; i < results.data.length; i++) {
var value = results.data[i];
if (!value.title) {
continue;
}
var cipher = {
type: constants.cipherType.login,
favorite: false,
notes: value.notesPlain && value.notesPlain !== '' ? value.notesPlain : '',
name: value.title && value.title !== '' ? value.title : '--',
login: {
uris: null,
username: null,
password: null
}
};
for (var property in value) {
if (value.hasOwnProperty(property)) {
if (value[property] === null || value[property] === '') {
continue;
}
if (!cipher.login.password && property === 'password') {
cipher.login.password = value[property];
}
else if (!cipher.login.username && property === 'username') {
cipher.login.username = value[property];
}
else if (!cipher.login.uris && property === 'urls') {
var urls = value[property].split(/(?:\r\n|\r|\n)/);
cipher.login.uris = makeUriArray(urls);
}
else if (property !== 'ainfo' && property !== 'autosubmit' && property !== 'notesPlain' &&
property !== 'ps' && property !== 'scope' && property !== 'tags' && property !== 'title' &&
property !== 'uuid' && !property.startsWith('section:')) {
if (cipher.notes !== '') {
cipher.notes += '\n';
}
cipher.notes += (property + ': ' + value[property]);
}
}
}
if (cipher.notes === '') {
cipher.notes = null;
}
ciphers.push(cipher);
}
success(folders, ciphers, []);
}
});
}
function importChromeCsv(file, success, error) {
Papa.parse(file, {
header: true,
encoding: 'UTF-8',
complete: function (results) {
parseCsvErrors(results);
var folders = [],
ciphers = [];
angular.forEach(results.data, function (value, key) {
ciphers.push({
type: constants.cipherType.login,
favorite: false,
notes: null,
name: value.name && value.name !== '' ? value.name : '--',
login: {
uris: makeUriArray(value.url),
username: value.username && value.username !== '' ? value.username : null,
password: value.password && value.password !== '' ? value.password : null
}
});
});
success(folders, ciphers, []);
}
});
}
function importFirefoxPasswordExporterCsv(file, success, error) {
Papa.parse(file, {
header: true,
encoding: 'UTF-8',
complete: function (results) {
parseCsvErrors(results);
var folders = [],
ciphers = [];
angular.forEach(results.data, function (value, key) {
ciphers.push({
type: constants.cipherType.login,
favorite: false,
notes: null,
name: value.hostname && value.hostname !== '' ? loginNameFromUrl(value.hostname) : '--',
login: {
uris: makeUriArray(value.hostname),
username: value.username && value.username !== '' ? value.username : null,
password: value.password && value.password !== '' ? value.password : null
}
});
});
success(folders, ciphers, []);
}
});
}
function importUpmCsv(file, success, error) {
Papa.parse(file, {
encoding: 'UTF-8',
complete: function (results) {
parseCsvErrors(results);
var folders = [],
ciphers = [];
angular.forEach(results.data, function (value, key) {
if (value.length === 5) {
ciphers.push({
type: constants.cipherType.login,
favorite: false,
notes: value[4] && value[4] !== '' ? value[4] : null,
name: value[0] && value[0] !== '' ? value[0] : '--',
login: {
uris: makeUriArray(value[3]),
username: value[1] && value[1] !== '' ? value[1] : null,
password: value[2] && value[2] !== '' ? value[2] : null
}
});
}
});
success(folders, ciphers, []);
}
});
}
function importKeeperCsv(file, success, error) {
Papa.parse(file, {
encoding: 'UTF-8',
complete: function (results) {
parseCsvErrors(results);
var folders = [],
ciphers = [],
folderRelationships = [];
angular.forEach(results.data, function (value, key) {
if (value.length >= 6) {
var folderIndex = folders.length,
cipherIndex = ciphers.length,
hasFolder = value[0] && value[0] !== '',
addFolder = hasFolder,
i = 0;
if (hasFolder) {
for (i = 0; i < folders.length; i++) {
if (folders[i].name === value[0]) {
addFolder = false;
folderIndex = i;
break;
}
}
}
var cipher = {
type: constants.cipherType.login,
favorite: false,
notes: value[5] && value[5] !== '' ? value[5] : null,
name: value[1] && value[1] !== '' ? value[1] : '--',
login: {
uris: makeUriArray(value[4]),
username: value[2] && value[2] !== '' ? value[2] : null,
password: value[3] && value[3] !== '' ? value[3] : null
},
fields: null
};
if (value.length > 6) {
// we have some custom fields.
for (i = 6; i < value.length; i = i + 2) {
if (value[i + 1] && value[i + 1].length > 200) {
if (!cipher.notes) {
cipher.notes = '';
}
cipher.notes += (value[i] + ': ' + value[i + 1] + '\n');
}
else {
if (!cipher.fields) {
cipher.fields = [];
}
cipher.fields.push({
name: value[i],
value: value[i + 1],
type: constants.fieldType.text
});
}
}
}
ciphers.push(cipher);
if (addFolder) {
folders.push({
name: value[0]
});
}
if (hasFolder) {
var relationship = {
key: cipherIndex,
value: folderIndex
};
folderRelationships.push(relationship);
}
}
});
success(folders, ciphers, folderRelationships);
}
});
}
function importPasswordDragonXml(file, success, error) {
var folders = [],
ciphers = [],
folderRelationships = [],
foldersIndex = [],
j = 0;
getXmlFileContents(file, parseXml, error);
function parseXml(xmlDoc) {
var xml = $(xmlDoc);
var pwManager = xml.find('PasswordManager');
if (pwManager.length) {
var records = pwManager.find('> record');
if (records.length) {
for (var i = 0; i < records.length; i++) {
var record = $(records[i]);
var accountNameNode = record.find('> Account-Name'),
accountName = accountNameNode.length ? $(accountNameNode) : null,
userIdNode = record.find('> User-Id'),
userId = userIdNode.length ? $(userIdNode) : null,
passwordNode = record.find('> Password'),
password = passwordNode.length ? $(passwordNode) : null,
urlNode = record.find('> URL'),
url = urlNode.length ? $(urlNode) : null,
notesNode = record.find('> Notes'),
notes = notesNode.length ? $(notesNode) : null,
categoryNode = record.find('> Category'),
category = categoryNode.length ? $(categoryNode) : null,
categoryText = category ? category.text() : null;
var folderIndex = folders.length,
cipherIndex = ciphers.length,
hasFolder = categoryText && categoryText !== '' && categoryText !== 'Unfiled',
addFolder = hasFolder;
if (hasFolder) {
for (j = 0; j < folders.length; j++) {
if (folders[j].name === categoryText) {
addFolder = false;
folderIndex = j;
break;
}
}
}
var cipher = {
type: constants.cipherType.login,
favorite: false,
notes: notes && notes.text() !== '' ? notes.text() : null,
name: accountName && accountName.text() !== '' ? accountName.text() : '--',
login: {
uris: url ? makeUriArray(url.text()) : null,
username: userId && userId.text() !== '' ? userId.text() : null,
password: password && password.text() !== '' ? password.text() : null
},
fields: null
};
var attributesSelector = '';
for (j = 1; j <= 10; j++) {
attributesSelector += '> Attribute-' + j;
if (j < 10) {
attributesSelector += ', ';
}
}
var attributes = record.find(attributesSelector);
if (attributes.length) {
// we have some attributes. add them as fields
for (j = 0; j < attributes.length; j++) {
var attr = $(attributes[j]),
attrName = attr.prop('tagName'),
attrValue = attr.text();
if (!attrValue || attrValue === '' || attrValue === 'null') {
continue;
}
if (attrValue.length > 200) {
if (!cipher.notes) {
cipher.notes = '';
}
cipher.notes += (attrName + ': ' + attrValue + '\n');
}
else {
if (!cipher.fields) {
cipher.fields = [];
}
cipher.fields.push({
name: attrName,
value: attrValue,
type: constants.fieldType.text
});
}
}
}
ciphers.push(cipher);
if (addFolder) {
folders.push({
name: categoryText
});
}
if (hasFolder) {
var relationship = {
key: cipherIndex,
value: folderIndex
};
folderRelationships.push(relationship);
}
}
}
success(folders, ciphers, folderRelationships);
}
else {
error();
}
}
}
function importEnpassCsv(file, success, error) {
Papa.parse(file, {
encoding: 'UTF-8',
complete: function (results) {
parseCsvErrors(results);
var folders = [],
ciphers = [];
for (var j = 0; j < results.data.length; j++) {
var row = results.data[j];
if (row.length < 2) {
continue;
}
if (j === 0 && row[0] === 'Title') {
continue;
}
var note = row[row.length - 1];
var cipher = {
type: constants.cipherType.login,
name: row[0],
favorite: false,
notes: note && note !== '' ? note : null,
fields: null,
login: {
uris: null,
password: null,
username: null,
totp: null
}
};
if (row.length > 2 && (row.length % 2) === 0) {
for (var i = 0; i < row.length - 2; i += 2) {
var value = row[i + 2];
if (!value || value === '') {
continue;
}
var field = row[i + 1];
var fieldLower = field.toLowerCase();
if (fieldLower === 'url' && !cipher.login.uris) {
cipher.login.uris = makeUriArray(value);
}
else if ((fieldLower === 'username' || fieldLower === 'email') && !cipher.login.username) {
cipher.login.username = value;
}
else if (fieldLower === 'password' && !cipher.login.password) {
cipher.login.password = value;
}
else if (fieldLower === 'totp' && !cipher.login.totp) {
cipher.login.totp = value;
}
else if (value.length > 200) {
if (!cipher.notes) {
cipher.notes = '';
}
cipher.notes += (field + ': ' + value + '\n');
}
else {
// other fields
if (!cipher.fields) {
cipher.fields = [];
}
cipher.fields.push({
name: field,
value: value,
type: constants.fieldType.text
});
}
}
}
ciphers.push(cipher);
}
success(folders, ciphers, []);
}
});
}
function importPasswordSafeXml(file, success, error) {
var folders = [],
ciphers = [],
folderRelationships = [],
foldersIndex = [],
j = 0;
getXmlFileContents(file, parseXml, error);
function parseXml(xmlDoc) {
var xml = $(xmlDoc);
var pwsafe = xml.find('passwordsafe');
if (pwsafe.length) {
var notesDelimiter = pwsafe.attr('delimiter');
var entries = pwsafe.find('> entry');
if (entries.length) {
for (var i = 0; i < entries.length; i++) {
var entry = $(entries[i]);
var titleNode = entry.find('> title'),
title = titleNode.length ? $(titleNode) : null,
usernameNode = entry.find('> username'),
username = usernameNode.length ? $(usernameNode) : null,
emailNode = entry.find('> email'),
email = emailNode.length ? $(emailNode) : null,
emailText = email ? email.text() : null,
passwordNode = entry.find('> password'),
password = passwordNode.length ? $(passwordNode) : null,
urlNode = entry.find('> url'),
url = urlNode.length ? $(urlNode) : null,
notesNode = entry.find('> notes'),
notes = notesNode.length ? $(notesNode) : null,
notesText = notes ? notes.text().split(notesDelimiter).join('\n') : null,
groupNode = entry.find('> group'),
group = groupNode.length ? $(groupNode) : null,
groupText = group ? group.text().split('.').join(' > ') : null;
var folderIndex = folders.length,
cipherIndex = ciphers.length,
hasFolder = groupText && groupText !== '',
addFolder = hasFolder;
if (hasFolder) {
for (j = 0; j < folders.length; j++) {
if (folders[j].name === groupText) {
addFolder = false;
folderIndex = j;
break;
}
}
}
var cipher = {
type: constants.cipherType.login,
favorite: false,
notes: notes && notesText !== '' ? notesText : null,
name: title && title.text() !== '' ? title.text() : '--',
login: {
uris: url ? makeUriArray(url.text()) : null,
username: username && username.text() !== '' ? username.text() : null,
password: password && password.text() !== '' ? password.text() : null
}
};
if (!cipher.login.username && emailText && emailText !== '') {
cipher.login.username = emailText;
}
else if (emailText && emailText !== '') {
cipher.notes = cipher.notes === null ? 'Email: ' + emailText
: cipher.notes + '\n' + 'Email: ' + emailText;
}
ciphers.push(cipher);
if (addFolder) {
folders.push({
name: groupText
});
}
if (hasFolder) {
var relationship = {
key: cipherIndex,
value: folderIndex
};
folderRelationships.push(relationship);
}
}
}
success(folders, ciphers, folderRelationships);
}
else {
error();
}
}
}
function importDashlaneCsv(file, success, error) {
Papa.parse(file, {
encoding: 'UTF-8',
complete: function (results) {
parseCsvErrors(results);
var folders = [],
ciphers = [];
for (var j = 0; j < results.data.length; j++) {
var skip = false;
var row = results.data[j];
if (!row.length || row.length === 1) {
continue;
}
var cipher = {
type: constants.cipherType.login,
name: row[0] && row[0] !== '' ? row[0] : '--',
favorite: false,
notes: null,
login: {
uris: null,
password: null,
username: null
}
};
if (row.length === 2) {
cipher.login.uris = makeUriArray(row[1]);
}
else if (row.length === 3) {
cipher.login.uris = makeUriArray(row[1]);
cipher.login.username = row[2];
}
else if (row.length === 4) {
if (row[2] === '' && row[3] === '') {
cipher.login.username = row[1];
cipher.notes = row[2] + '\n' + row[3];
}
else {
cipher.login.username = row[2];
cipher.notes = row[1] + '\n' + row[3];
}
}
else if (row.length === 5) {
cipher.login.uris = makeUriArray(row[1]);
cipher.login.username = row[2];
cipher.login.password = row[3];
cipher.notes = row[4];
}
else if (row.length === 6) {
if (row[2] === '') {
cipher.login.username = row[3];
cipher.login.password = row[4];
cipher.notes = row[5];
}
else {
cipher.login.username = row[2];
cipher.login.password = row[3];
cipher.notes = row[4] + '\n' + row[5];
}
cipher.login.uris = makeUriArray(row[1]);
}
else if (row.length === 7) {
if (row[2] === '') {
cipher.login.username = row[3];
cipher.notes = row[4] + '\n' + row[6];
}
else {
cipher.login.username = row[2];
cipher.notes = row[3] + '\n' + row[4] + '\n' + row[6];
}
cipher.login.uris = makeUriArray(row[1]);
cipher.login.password = row[5];
}
else {
cipher.notes = '';
for (var i = 1; i < row.length; i++) {
cipher.notes = cipher.notes + row[i] + '\n';
if (row[i] === 'NO_TYPE') {
skip = true;
break;
}
}
}
if (skip) {
continue;
}
if (cipher.login.username === '') {
cipher.login.username = null;
}
if (cipher.login.password === '') {
cipher.login.password = null;
}
if (cipher.notes === '') {
cipher.notes = null;
}
ciphers.push(cipher);
}
success(folders, ciphers, []);
}
});
}
function importStickyPasswordXml(file, success, error) {
var folders = [],
ciphers = [],
folderRelationships = [],
foldersIndex = [],
j = 0;
function buildGroupText(database, groupId, groupText) {
var group = database.find('> Groups > Group[ID="' + groupId + '"]');
if (group.length) {
if (groupText && groupText !== '') {
groupText = ' > ' + groupText;
}
groupText = group.attr('Name') + groupText;
var parentGroupId = group.attr('ParentID');
return buildGroupText(database, parentGroupId, groupText);
}
return groupText;
}
getXmlFileContents(file, parseXml, error);
function parseXml(xmlDoc) {
var xml = $(xmlDoc);
var database = xml.find('root > Database');
if (database.length) {
var loginNodes = database.find('> Logins > Login');
if (loginNodes.length) {
for (var i = 0; i < loginNodes.length; i++) {
var loginNode = $(loginNodes[i]);
var usernameText = loginNode.attr('Name'),
passwordText = loginNode.attr('Password'),
accountId = loginNode.attr('ID'),
titleText = null,
linkText = null,
notesText = null,
groupId = null,
groupText = null;
if (accountId && accountId !== '') {
var accountLogin =
database.find('> Accounts > Account > LoginLinks > Login[SourceLoginID="' + accountId + '"]');
if (accountLogin.length) {
var account = accountLogin.parent().parent();
if (account.length) {
titleText = account.attr('Name');
linkText = account.attr('Link');
groupId = account.attr('ParentID');
notesText = account.attr('Comments');
if (notesText) {
notesText = notesText.split('/n').join('\n');
}
}
}
}
if (groupId && groupId !== '') {
groupText = buildGroupText(database, groupId, '');
}
var folderIndex = folders.length,
cipherIndex = ciphers.length,
hasFolder = groupText && groupText !== '',
addFolder = hasFolder;
if (hasFolder) {
for (j = 0; j < folders.length; j++) {
if (folders[j].name === groupText) {
addFolder = false;
folderIndex = j;
break;
}
}
}
var cipher = {
type: constants.cipherType.login,
favorite: false,
notes: notesText && notesText !== '' ? notesText : null,
name: titleText && titleText !== '' ? titleText : '--',
login: {
uris: makeUriArray(linkText),
username: usernameText && usernameText !== '' ? usernameText : null,
password: passwordText && passwordText !== '' ? passwordText : null
}
};
ciphers.push(cipher);
if (addFolder) {
folders.push({
name: groupText
});
}
if (hasFolder) {
var relationship = {
key: cipherIndex,
value: folderIndex
};
folderRelationships.push(relationship);
}
}
}
success(folders, ciphers, folderRelationships);
}
else {
error();
}
}
}
function importmSecureCsv(file, success, error) {
Papa.parse(file, {
encoding: 'UTF-8',
complete: function (results) {
parseCsvErrors(results);
var folders = [],
ciphers = [],
folderRelationships = [];
angular.forEach(results.data, function (value, key) {
if (value.length >= 3) {
var folderIndex = folders.length,
cipherIndex = ciphers.length,
hasFolder = value[0] && value[0] !== '' && value[0] !== 'Unassigned',
addFolder = hasFolder,
i = 0;
if (hasFolder) {
for (i = 0; i < folders.length; i++) {
if (folders[i].name === value[0]) {
addFolder = false;
folderIndex = i;
break;
}
}
}
var cipher = {
type: constants.cipherType.login,
favorite: false,
notes: '',
name: value[2] && value[2] !== '' ? value[2] : null,
login: {
uris: null,
username: null,
password: null
}
};
if (value[1] === 'Web Logins') {
cipher.login.uris = makeUriArray(value[4]);
cipher.login.username = value[5] && value[5] !== '' ? value[5] : null;
cipher.login.password = value[6] && value[6] !== '' ? value[6] : null;
cipher.notes = value[3] && value[3] !== '' ? value[3].split('\\n').join('\n') : null;
}
else if (value.length > 3) {
for (var j = 3; j < value.length; j++) {
if (value[j] && value[j] !== '') {
if (cipher.notes !== '') {
cipher.notes = cipher.notes + '\n';
}
cipher.notes = cipher.notes + value[j];
}
}
}
if (value[1] && value[1] !== '' && value[1] !== 'Web Logins') {
cipher.name = value[1] + ': ' + cipher.name;
}
if (cipher.notes === '') {
cipher.notes = null;
}
ciphers.push(cipher);
if (addFolder) {
folders.push({
name: value[0]
});
}
if (hasFolder) {
var relationship = {
key: cipherIndex,
value: folderIndex
};
folderRelationships.push(relationship);
}
}
});
success(folders, ciphers, folderRelationships);
}
});
}
function importTrueKeyCsv(file, success, error) {
var folders = [],
ciphers = [],
propsToIgnore = [
'kind',
'autologin',
'favorite',
'hexcolor',
'protectedwithpassword',
'subdomainonly',
'type',
'tk_export_version',
'note',
'title',
'document_content'
];
Papa.parse(file, {
header: true,
encoding: 'UTF-8',
complete: function (results) {
parseCsvErrors(results);
angular.forEach(results.data, function (value, key) {
var cipher = {
type: constants.cipherType.login,
favorite: value.favorite && value.favorite.toLowerCase() === 'true' ? true : false,
notes: value.memo && value.memo !== '' ? value.memo : null,
name: value.name && value.name !== '' ? value.name : '--',
login: {
uris: makeUriArray(value.url),
username: value.login && value.login !== '' ? value.login : null,
password: value.password && value.password !== '' ? value.password : null
},
fields: null
};
if (value.kind !== 'login') {
cipher.name = value.title && value.title !== '' ? value.title : '--';
cipher.notes = value.note && value.note !== '' ? value.note : null;
if (!cipher.notes) {
cipher.notes = value.document_content && value.document_content !== '' ?
value.document_content : null;
}
for (var property in value) {
if (value.hasOwnProperty(property) && propsToIgnore.indexOf(property.toLowerCase()) < 0 &&
value[property] && value[property] !== '') {
if (value[property].length > 200) {
if (!cipher.notes) {
cipher.notes = '';
}
cipher.notes += (property + ': ' + value[property] + '\n');
}
else {
if (!cipher.fields) {
cipher.fields = [];
}
// other custom fields
cipher.fields.push({
name: property,
value: value[property],
type: constants.fieldType.text
});
}
}
}
}
ciphers.push(cipher);
});
success(folders, ciphers, []);
}
});
}
function importClipperzHtml(file, success, error) {
var folders = [],
ciphers = [];
getFileContents(file, parse, error);
function parse(fileContents) {
var doc = $(fileContents);
var textarea = doc.find('textarea');
var json = textarea && textarea.length ? textarea.val() : null;
var entries = json ? JSON.parse(json) : null;
if (entries && entries.length) {
for (var i = 0; i < entries.length; i++) {
var entry = entries[i];
var cipher = {
type: constants.cipherType.login,
favorite: false,
notes: '',
name: entry.label && entry.label !== '' ? entry.label.split(' ')[0] : '--',
login: {
uris: null,
username: null,
password: null
},
fields: null
};
if (entry.data && entry.data.notes && entry.data.notes !== '') {
cipher.notes = entry.data.notes.split('\\n').join('\n');
}
if (entry.currentVersion && entry.currentVersion.fields) {
for (var property in entry.currentVersion.fields) {
if (entry.currentVersion.fields.hasOwnProperty(property)) {
var field = entry.currentVersion.fields[property];
var actionType = field.actionType.toLowerCase();
switch (actionType) {
case 'password':
cipher.login.password = field.value;
break;
case 'email':
case 'username':
case 'user':
case 'name':
cipher.login.username = field.value;
break;
case 'url':
cipher.login.uris = makeUriArray(field.value);
break;
default:
if (!cipher.login.username && isField(field.label, _usernameFieldNames)) {
cipher.login.username = field.value;
}
else if (!cipher.login.password && isField(field.label, _passwordFieldNames)) {
cipher.login.password = field.value;
}
else if (field.value.length > 200) {
if (!cipher.notes) {
cipher.notes = '';
}
cipher.notes += (field.label + ': ' + field.value + '\n');
}
else {
if (!cipher.fields) {
cipher.fields = [];
}
cipher.fields.push({
name: field.label,
value: field.value,
type: constants.fieldType.text
});
}
break;
}
}
}
}
if (cipher.notes === '') {
cipher.notes = null;
}
ciphers.push(cipher);
}
}
success(folders, ciphers, []);
}
}
function importAviraJson(file, success, error) {
var folders = [],
ciphers = [],
i = 0;
getFileContents(file, parseJson, error);
function parseJson(fileContent) {
var fileJson = JSON.parse(fileContent);
if (fileJson) {
if (fileJson.accounts) {
for (i = 0; i < fileJson.accounts.length; i++) {
var account = fileJson.accounts[i];
var cipher = {
type: constants.cipherType.login,
favorite: account.is_favorite && account.is_favorite === true,
notes: null,
name: account.label && account.label !== '' ? account.label : account.domain,
login: {
uris: makeUriArray(account.domain),
username: account.username && account.username !== '' ? account.username : null,
password: account.password && account.password !== '' ? account.password : null
}
};
if (account.email && account.email !== '') {
if (!cipher.login.username || cipher.login.username === '') {
cipher.login.username = account.email;
}
else {
cipher.notes = account.email;
}
}
if (!cipher.name || cipher.name === '') {
cipher.name = '--';
}
ciphers.push(cipher);
}
}
}
success(folders, ciphers, []);
}
}
function importRoboFormHtml(file, success, error) {
var folders = [],
ciphers = [];
getFileContents(file, parse, error);
function parse(fileContents) {
var doc = $(fileContents.split('').join('').split('Bitwarden two-step login recovery code:
' + '' + $scope.code + '' +
'' + new Date() + '
'); w.print(); w.close(); }; function formatString(s) { if (!s) { return null; } return s.replace(/(.{4})/g, '$1 ').trim().toUpperCase(); } $scope.close = function () { $uibModalInstance.close(); }; }]); angular .module('bit.settings') .controller('settingsTwoStepU2fController', ["$scope", "apiService", "$uibModalInstance", "cryptoService", "authService", "toastr", "$analytics", "constants", "$timeout", "$window", function ($scope, apiService, $uibModalInstance, cryptoService, authService, toastr, $analytics, constants, $timeout, $window) { $analytics.eventTrack('settingsTwoStepU2fController', { category: 'Modal' }); var _masterPasswordHash; var closed = false; $scope.deviceResponse = null; $scope.deviceListening = false; $scope.deviceError = false; $timeout(function () { $("#masterPassword").focus(); }); $scope.auth = function (model) { $scope.authPromise = cryptoService.hashPassword(model.masterPassword).then(function (hash) { _masterPasswordHash = hash; return apiService.twoFactor.getU2f({}, { masterPasswordHash: _masterPasswordHash }).$promise; }).then(function (response) { $scope.enabled = response.Enabled; $scope.challenge = response.Challenge; $scope.authed = true; return $scope.readDevice(); }); }; $scope.readDevice = function () { if (closed || $scope.enabled) { return; } console.log('listening for key...'); $scope.deviceResponse = null; $scope.deviceError = false; $scope.deviceListening = true; $window.u2f.register($scope.challenge.AppId, [{ version: $scope.challenge.Version, challenge: $scope.challenge.Challenge }], [], function (data) { $scope.deviceListening = false; if (data.errorCode === 5) { $scope.readDevice(); return; } else if (data.errorCode) { $timeout(function () { $scope.deviceError = true; }); console.log('error: ' + data.errorCode); return; } $timeout(function () { $scope.deviceResponse = JSON.stringify(data); }); }, 10); }; $scope.submit = function () { if ($scope.enabled) { disable(); return; } update(); }; function disable() { if (!confirm('Are you sure you want to disable the U2F provider?')) { return; } $scope.submitPromise = apiService.twoFactor.disable({}, { masterPasswordHash: _masterPasswordHash, type: constants.twoFactorProvider.u2f }, function (response) { $analytics.eventTrack('Disabled Two-step U2F'); toastr.success('U2F has been disabled.'); $scope.enabled = response.Enabled; $scope.close(); }).$promise; } function update() { $scope.submitPromise = apiService.twoFactor.putU2f({}, { deviceResponse: $scope.deviceResponse, masterPasswordHash: _masterPasswordHash }, function (response) { $analytics.eventTrack('Enabled Two-step U2F'); $scope.enabled = response.Enabled; $scope.challenge = null; $scope.deviceResponse = null; $scope.deviceError = false; }).$promise; } $scope.close = function () { closed = true; $uibModalInstance.close($scope.enabled); }; $scope.$on('modal.closing', function (e, reason, isClosed) { if (closed) { return; } e.preventDefault(); $scope.close(); }); }]); angular .module('bit.settings') .controller('settingsTwoStepYubiController', ["$scope", "apiService", "$uibModalInstance", "cryptoService", "authService", "toastr", "$analytics", "constants", "$timeout", function ($scope, apiService, $uibModalInstance, cryptoService, authService, toastr, $analytics, constants, $timeout) { $analytics.eventTrack('settingsTwoStepYubiController', { category: 'Modal' }); var _profile = null, _masterPasswordHash; $timeout(function () { $("#masterPassword").focus(); }); $scope.auth = function (model) { var response = null; $scope.authPromise = cryptoService.hashPassword(model.masterPassword).then(function (hash) { _masterPasswordHash = hash; return apiService.twoFactor.getYubi({}, { masterPasswordHash: _masterPasswordHash }).$promise; }).then(function (apiResponse) { response = apiResponse; return authService.getUserProfile(); }).then(function (profile) { _profile = profile; processResult(response); $scope.authed = true; }); }; $scope.remove = function (model) { model.key = null; model.existingKey = null; }; $scope.submit = function (model) { $scope.submitPromise = apiService.twoFactor.putYubi({}, { key1: model.key1.key, key2: model.key2.key, key3: model.key3.key, nfc: model.nfc, masterPasswordHash: _masterPasswordHash }, function (response) { $analytics.eventTrack('Saved Two-step YubiKey'); toastr.success('YubiKey saved.'); processResult(response); }).$promise; }; $scope.disable = function () { if (!confirm('Are you sure you want to disable the YubiKey provider?')) { return; } $scope.disableLoading = true; $scope.submitPromise = apiService.twoFactor.disable({}, { masterPasswordHash: _masterPasswordHash, type: constants.twoFactorProvider.yubikey }, function (response) { $scope.disableLoading = false; $analytics.eventTrack('Disabled Two-step YubiKey'); toastr.success('YubiKey has been disabled.'); $scope.enabled = response.Enabled; $scope.close(); }, function (response) { toastr.error('Failed to disable.'); $scope.disableLoading = false; }).$promise; }; function processResult(response) { $scope.enabled = response.Enabled; $scope.updateModel = { key1: { key: response.Key1, existingKey: padRight(response.Key1, '*', 44) }, key2: { key: response.Key2, existingKey: padRight(response.Key2, '*', 44) }, key3: { key: response.Key3, existingKey: padRight(response.Key3, '*', 44) }, nfc: response.Nfc === true || !response.Enabled }; } function padRight(str, character, size) { if (!str || !character || str.length >= size) { return str; } var max = (size - str.length) / character.length; for (var i = 0; i < max; i++) { str += character; } return str; } var closing = false; $scope.close = function () { closing = true; $uibModalInstance.close($scope.enabled); }; $scope.$on('modal.closing', function (e, reason, closed) { if (closing) { return; } e.preventDefault(); $scope.close(); }); }]); angular .module('bit.settings') .controller('settingsUpdateKeyController', ["$scope", "$state", "apiService", "$uibModalInstance", "cipherService", "cryptoService", "authService", "validationService", "toastr", "$analytics", "$q", function ($scope, $state, apiService, $uibModalInstance, cipherService, cryptoService, authService, validationService, toastr, $analytics, $q) { $analytics.eventTrack('settingsUpdateKeyController', { category: 'Modal' }); $scope.save = function (form) { var encKey = cryptoService.getEncKey(); if (encKey) { validationService.addError(form, 'MasterPasswordHash', 'You do not need to update. You are already using the new encryption key.', true); return; } $scope.savePromise = cryptoService.hashPassword($scope.masterPassword).then(function (hash) { return updateKey(hash); }).then(function () { $uibModalInstance.dismiss('cancel'); authService.logOut(); $analytics.eventTrack('Key Updated'); return $state.go('frontend.login.info'); }, function (e) { throw e ? e : 'Error occurred.'; }).then(function () { toastr.success('Please log back in. If you are using other Bitwarden applications, ' + 'log out and back in to those as well.', 'Key Updated', { timeOut: 10000 }); }); }; function updateKey(masterPasswordHash) { var madeEncKey = cryptoService.makeEncKey(null); var reencryptedCiphers = []; var ciphersPromise = apiService.ciphers.list({}, function (encryptedCiphers) { var filteredEncryptedCiphers = []; for (var i = 0; i < encryptedCiphers.Data.length; i++) { if (encryptedCiphers.Data[i].OrganizationId) { continue; } filteredEncryptedCiphers.push(encryptedCiphers.Data[i]); } var unencryptedCiphers = cipherService.decryptCiphers(filteredEncryptedCiphers); reencryptedCiphers = cipherService.encryptCiphers(unencryptedCiphers, madeEncKey.encKey); }).$promise; var reencryptedFolders = []; var foldersPromise = apiService.folders.list({}, function (encryptedFolders) { var unencryptedFolders = cipherService.decryptFolders(encryptedFolders.Data); reencryptedFolders = cipherService.encryptFolders(unencryptedFolders, madeEncKey.encKey); }).$promise; var privateKey = cryptoService.getPrivateKey('raw'), reencryptedPrivateKey = null; if (privateKey) { reencryptedPrivateKey = cryptoService.encrypt(privateKey, madeEncKey.encKey, 'raw'); } return $q.all([ciphersPromise, foldersPromise]).then(function () { var request = { masterPasswordHash: masterPasswordHash, ciphers: reencryptedCiphers, folders: reencryptedFolders, privateKey: reencryptedPrivateKey, key: madeEncKey.encKeyEnc }; return apiService.accounts.putKey(request).$promise; }, function () { throw 'Error while encrypting data.'; }).then(function () { cryptoService.setEncKey(madeEncKey.encKey, null, true); }); } $scope.close = function () { $uibModalInstance.dismiss('cancel'); }; }]); angular .module('bit.vault') .controller('vaultAddCipherController', ["$scope", "apiService", "$uibModalInstance", "cryptoService", "cipherService", "passwordService", "selectedFolder", "$analytics", "checkedFavorite", "$rootScope", "authService", "$uibModal", "constants", "$filter", "selectedType", function ($scope, apiService, $uibModalInstance, cryptoService, cipherService, passwordService, selectedFolder, $analytics, checkedFavorite, $rootScope, authService, $uibModal, constants, $filter, selectedType) { $analytics.eventTrack('vaultAddCipherController', { category: 'Modal' }); $scope.folders = $rootScope.vaultFolders; $scope.constants = constants; $scope.selectedType = selectedType ? selectedType.toString() : constants.cipherType.login.toString(); $scope.cipher = { folderId: selectedFolder ? selectedFolder.id : null, favorite: checkedFavorite === true, type: selectedType || constants.cipherType.login, login: { uris: [{ uri: null, match: null, matchValue: null }] }, identity: {}, card: {}, secureNote: { type: 0 } }; authService.getUserProfile().then(function (profile) { $scope.useTotp = profile.premium; }); $scope.typeChanged = function () { $scope.cipher.type = parseInt($scope.selectedType); }; $scope.savePromise = null; $scope.save = function () { if ($scope.cipher.type === constants.cipherType.login && $scope.cipher.login.uris.length === 1 && ($scope.cipher.login.uris[0].uri == null || $scope.cipher.login.uris[0].uri === '')) { $scope.cipher.login.uris = null; } var cipher = cipherService.encryptCipher($scope.cipher); $scope.savePromise = apiService.ciphers.post(cipher, function (cipherResponse) { $analytics.eventTrack('Created Cipher'); var decCipher = cipherService.decryptCipherPreview(cipherResponse); $uibModalInstance.close(decCipher); }).$promise; }; $scope.generatePassword = function () { if (!$scope.cipher.login.password || confirm('Are you sure you want to overwrite the current password?')) { $analytics.eventTrack('Generated Password From Add'); $scope.cipher.login.password = passwordService.generatePassword({ length: 14, special: true }); } }; $scope.addUri = function () { if (!$scope.cipher.login) { return; } if (!$scope.cipher.login.uris) { $scope.cipher.login.uris = []; } $scope.cipher.login.uris.push({ uri: null, match: null, matchValue: null }); }; $scope.removeUri = function (uri) { if (!$scope.cipher.login || !$scope.cipher.login.uris) { return; } var index = $scope.cipher.login.uris.indexOf(uri); if (index > -1) { $scope.cipher.login.uris.splice(index, 1); } }; $scope.uriMatchChanged = function (uri) { if ((!uri.matchValue && uri.matchValue !== 0) || uri.matchValue === '') { uri.match = null; } else { uri.match = parseInt(uri.matchValue); } }; $scope.addField = function () { if (!$scope.cipher.fields) { $scope.cipher.fields = []; } $scope.cipher.fields.push({ type: constants.fieldType.text.toString(), name: null, value: null }); }; $scope.removeField = function (field) { var index = $scope.cipher.fields.indexOf(field); if (index > -1) { $scope.cipher.fields.splice(index, 1); } }; $scope.toggleFavorite = function () { $scope.cipher.favorite = !$scope.cipher.favorite; }; $scope.clipboardSuccess = function (e) { e.clearSelection(); selectPassword(e); }; $scope.clipboardError = function (e, password) { if (password) { selectPassword(e); } alert('Your web browser does not support easy clipboard copying. Copy it manually instead.'); }; $scope.folderSort = function (item) { if (!item.id) { return ''; } return item.name.toLowerCase(); }; function selectPassword(e) { var target = $(e.trigger).parent().prev(); if (target.attr('type') === 'text') { target.select(); } } $scope.close = function () { $uibModalInstance.dismiss('close'); }; $scope.showUpgrade = function () { $uibModal.open({ animation: true, templateUrl: 'app/views/premiumRequired.html', controller: 'premiumRequiredController' }); }; }]); angular .module('bit.vault') .controller('vaultAddFolderController', ["$scope", "apiService", "$uibModalInstance", "cryptoService", "cipherService", "$analytics", function ($scope, apiService, $uibModalInstance, cryptoService, cipherService, $analytics) { $analytics.eventTrack('vaultAddFolderController', { category: 'Modal' }); $scope.savePromise = null; $scope.save = function (model) { var folder = cipherService.encryptFolder(model); $scope.savePromise = apiService.folders.post(folder, function (response) { $analytics.eventTrack('Created Folder'); var decFolder = cipherService.decryptFolder(response); $uibModalInstance.close(decFolder); }).$promise; }; $scope.close = function () { $uibModalInstance.dismiss('close'); }; }]); angular .module('bit.vault') .controller('vaultAttachmentsController', ["$scope", "apiService", "$uibModalInstance", "cryptoService", "cipherService", "cipherId", "$analytics", "validationService", "toastr", "$timeout", "authService", "$uibModal", function ($scope, apiService, $uibModalInstance, cryptoService, cipherService, cipherId, $analytics, validationService, toastr, $timeout, authService, $uibModal) { $analytics.eventTrack('vaultAttachmentsController', { category: 'Modal' }); $scope.cipher = {}; $scope.readOnly = true; $scope.loading = true; $scope.isPremium = true; $scope.canUseAttachments = true; var closing = false; authService.getUserProfile().then(function (profile) { $scope.isPremium = profile.premium; return apiService.ciphers.get({ id: cipherId }).$promise; }).then(function (cipher) { $scope.cipher = cipherService.decryptCipher(cipher); $scope.readOnly = !$scope.cipher.edit; $scope.canUseAttachments = $scope.isPremium || $scope.cipher.organizationId; $scope.loading = false; }, function () { $scope.loading = false; }); $scope.save = function (form) { var fileEl = document.getElementById('file'); var files = fileEl.files; if (!files || !files.length) { validationService.addError(form, 'file', 'Select a file.', true); return; } $scope.savePromise = cipherService.encryptAttachmentFile(getKeyForCipher(), files[0]).then(function (encValue) { var fd = new FormData(); var blob = new Blob([encValue.data], { type: 'application/octet-stream' }); fd.append('data', blob, encValue.fileName); return apiService.ciphers.postAttachment({ id: cipherId }, fd).$promise; }).then(function (response) { $analytics.eventTrack('Added Attachment'); $scope.cipher = cipherService.decryptCipher(response); // reset file input // ref: https://stackoverflow.com/a/20552042 fileEl.type = ''; fileEl.type = 'file'; fileEl.value = ''; }, function (e) { var errors = validationService.parseErrors(e); toastr.error(errors.length ? errors[0] : 'An error occurred.'); }); }; $scope.download = function (attachment) { attachment.loading = true; if (!$scope.canUseAttachments) { attachment.loading = false; alert('Premium membership is required to use this feature.'); return; } cipherService.downloadAndDecryptAttachment(getKeyForCipher(), attachment, true).then(function (res) { $timeout(function () { attachment.loading = false; }); }, function () { $timeout(function () { attachment.loading = false; }); }); }; function getKeyForCipher() { if ($scope.cipher.organizationId) { return cryptoService.getOrgKey($scope.cipher.organizationId); } return null; } $scope.remove = function (attachment) { if (!confirm('Are you sure you want to delete this attachment (' + attachment.fileName + ')?')) { return; } attachment.loading = true; apiService.ciphers.delAttachment({ id: cipherId, attachmentId: attachment.id }).$promise.then(function () { attachment.loading = false; $analytics.eventTrack('Deleted Attachment'); var index = $scope.cipher.attachments.indexOf(attachment); if (index > -1) { $scope.cipher.attachments.splice(index, 1); } }, function () { toastr.error('Cannot delete attachment.'); attachment.loading = false; }); }; $scope.close = function () { $uibModalInstance.dismiss('cancel'); }; $scope.$on('modal.closing', function (e, reason, closed) { if (closing) { return; } e.preventDefault(); closing = true; $uibModalInstance.close(!!$scope.cipher.attachments && $scope.cipher.attachments.length > 0); }); $scope.showUpgrade = function () { $uibModal.open({ animation: true, templateUrl: 'app/views/premiumRequired.html', controller: 'premiumRequiredController' }); }; }]); angular .module('bit.vault') .controller('vaultCipherCollectionsController', ["$scope", "apiService", "$uibModalInstance", "cipherService", "cipherId", "$analytics", function ($scope, apiService, $uibModalInstance, cipherService, cipherId, $analytics) { $analytics.eventTrack('vaultCipherCollectionsController', { category: 'Modal' }); $scope.cipher = {}; $scope.readOnly = false; $scope.loadingCipher = true; $scope.loadingCollections = true; $scope.selectedCollections = {}; $scope.collections = []; var cipherAndCols = null; $uibModalInstance.opened.then(function () { apiService.ciphers.getDetails({ id: cipherId }).$promise.then(function (cipher) { $scope.loadingCipher = false; $scope.readOnly = !cipher.Edit; if (cipher.Edit && cipher.OrganizationId) { if (cipher.Type === 1) { $scope.cipher = cipherService.decryptCipherPreview(cipher); } var collections = {}; if (cipher.CollectionIds) { for (var i = 0; i < cipher.CollectionIds.length; i++) { collections[cipher.CollectionIds[i]] = null; } } return { cipher: cipher, cipherCollections: collections }; } return null; }).then(function (result) { if (!result) { $scope.loadingCollections = false; return false; } cipherAndCols = result; return apiService.collections.listMe({ writeOnly: true }).$promise; }).then(function (response) { if (response === false) { return; } var collections = []; var selectedCollections = {}; var writeableCollections = response.Data; for (var i = 0; i < writeableCollections.length; i++) { // clean out selectCollections that aren't from this organization if (writeableCollections[i].OrganizationId !== cipherAndCols.cipher.OrganizationId) { continue; } if (writeableCollections[i].Id in cipherAndCols.cipherCollections) { selectedCollections[writeableCollections[i].Id] = true; } var decCollection = cipherService.decryptCollection(writeableCollections[i]); collections.push(decCollection); } $scope.loadingCollections = false; $scope.collections = collections; $scope.selectedCollections = selectedCollections; }); }); $scope.toggleCollectionSelectionAll = function ($event) { var collections = {}; if ($event.target.checked) { for (var i = 0; i < $scope.collections.length; i++) { collections[$scope.collections[i].id] = true; } } $scope.selectedCollections = collections; }; $scope.toggleCollectionSelection = function (id) { if (id in $scope.selectedCollections) { delete $scope.selectedCollections[id]; } else { $scope.selectedCollections[id] = true; } }; $scope.collectionSelected = function (collection) { return collection.id in $scope.selectedCollections; }; $scope.allSelected = function () { return Object.keys($scope.selectedCollections).length === $scope.collections.length; }; $scope.submit = function () { var request = { collectionIds: [] }; for (var id in $scope.selectedCollections) { if ($scope.selectedCollections.hasOwnProperty(id)) { request.collectionIds.push(id); } } $scope.submitPromise = apiService.ciphers.putCollections({ id: cipherId }, request) .$promise.then(function (response) { $analytics.eventTrack('Edited Cipher Collections'); $uibModalInstance.close({ action: 'collectionsEdit', collectionIds: request.collectionIds }); }); }; $scope.close = function () { $uibModalInstance.dismiss('cancel'); }; }]); angular .module('bit.vault') .controller('vaultController', ["$scope", "$uibModal", "apiService", "$filter", "cryptoService", "authService", "toastr", "cipherService", "$q", "$localStorage", "$timeout", "$rootScope", "$state", "$analytics", "constants", "validationService", function ($scope, $uibModal, apiService, $filter, cryptoService, authService, toastr, cipherService, $q, $localStorage, $timeout, $rootScope, $state, $analytics, constants, validationService) { $scope.loadingCiphers = true; $scope.loadingGroupings = true; $scope.ciphers = []; $scope.folders = []; $scope.collections = []; $scope.constants = constants; $scope.filter = undefined; $scope.selectedType = undefined; $scope.selectedFolder = undefined; $scope.selectedCollection = undefined; $scope.selectedFavorites = false; $scope.selectedAll = true; $scope.selectedTitle = 'All'; $scope.selectedIcon = 'fa-th'; if ($state.params.refreshFromServer) { $rootScope.vaultFolders = $rootScope.vaultCollections = $rootScope.vaultCiphers = null; } $scope.$on('$viewContentLoaded', function () { $timeout(function () { if ($('body').hasClass('control-sidebar-open')) { $("#search").focus(); } }, 500); if (($rootScope.vaultFolders || $rootScope.vaultCollections) && $rootScope.vaultCiphers) { $scope.loadingCiphers = $scope.loadingGroupings = false; loadCipherData($rootScope.vaultCiphers); return; } loadDataFromServer(); }); function loadDataFromServer() { var decFolders = [{ id: null, name: 'No Folder' }]; var decCollections = []; var collectionPromise = apiService.collections.listMe({ writeOnly: false }, function (collections) { for (var i = 0; i < collections.Data.length; i++) { var decCollection = cipherService.decryptCollection(collections.Data[i], null, true); decCollections.push(decCollection); } }).$promise; var folderPromise = apiService.folders.list({}, function (folders) { for (var i = 0; i < folders.Data.length; i++) { var decFolder = cipherService.decryptFolderPreview(folders.Data[i]); decFolders.push(decFolder); } }).$promise; var groupingPromise = $q.all([collectionPromise, folderPromise]).then(function () { $rootScope.vaultCollections = decCollections; $rootScope.vaultFolders = decFolders; $scope.loadingGroupings = false; }); apiService.ciphers.list({}, function (ciphers) { var decCiphers = []; for (var i = 0; i < ciphers.Data.length; i++) { var decCipher = cipherService.decryptCipherPreview(ciphers.Data[i]); decCiphers.push(decCipher); } groupingPromise.then(function () { loadCipherData(decCiphers); }); }); } function loadCipherData(decCiphers) { $rootScope.vaultCiphers = $scope.ciphers = $filter('orderBy')(decCiphers, ['sort', 'name', 'subTitle']); var chunks = chunk($rootScope.vaultCiphers, 200); if (chunks.length > 0) { $scope.ciphers = chunks[0]; var delay = 200; angular.forEach(chunks, function (value, index) { delay += 200; // skip the first chuck if (index > 0) { $timeout(function () { Array.prototype.push.apply($scope.ciphers, value); }, delay); } }); } $scope.loadingCiphers = false; } function sortScopedCipherData() { $rootScope.vaultCiphers = $scope.ciphers = $filter('orderBy')($rootScope.vaultCiphers, ['name', 'subTitle']); } function chunk(arr, len) { var chunks = [], i = 0, n = arr.length; while (i < n) { chunks.push(arr.slice(i, i += len)); } return chunks; } $scope.groupingSort = function (item) { if (!item.id) { return ''; } return item.name.toLowerCase(); }; $scope.clipboardError = function (e) { alert('Your web browser does not support easy clipboard copying. ' + 'Edit the item and copy it manually instead.'); }; $scope.editCipher = function (cipher) { var editModel = $uibModal.open({ animation: true, templateUrl: 'app/vault/views/vaultEditCipher.html', controller: 'vaultEditCipherController', resolve: { cipherId: function () { return cipher.id; } } }); editModel.result.then(function (returnVal) { if (returnVal.action === 'edit') { var index = $scope.ciphers.indexOf(cipher); if (index > -1) { // restore collection ids since those cannot change on edit here. returnVal.data.collectionIds = $rootScope.vaultCiphers[index].collectionIds; $rootScope.vaultCiphers[index] = returnVal.data; } sortScopedCipherData(); } else if (returnVal.action === 'partialEdit') { cipher.folderId = returnVal.data.folderId; cipher.favorite = returnVal.data.favorite; } else if (returnVal.action === 'delete') { removeCipherFromScopes(cipher); } }); }; $scope.$on('vaultAddCipher', function (event, args) { $scope.addCipher(); }); $scope.addCipher = function () { var addModel = $uibModal.open({ animation: true, templateUrl: 'app/vault/views/vaultAddCipher.html', controller: 'vaultAddCipherController', resolve: { selectedFolder: function () { return $scope.selectedFolder; }, selectedType: function () { return $scope.selectedType; }, checkedFavorite: function () { return $scope.selectedFavorites; } } }); addModel.result.then(function (addedCipher) { $rootScope.vaultCiphers.push(addedCipher); sortScopedCipherData(); }); }; $scope.deleteCipher = function (cipher) { if (!confirm('Are you sure you want to delete this item (' + cipher.name + ')?')) { return; } apiService.ciphers.del({ id: cipher.id }, function () { $analytics.eventTrack('Deleted Item'); removeCipherFromScopes(cipher); }); }; $scope.attachments = function (cipher) { authService.getUserProfile().then(function (profile) { return { isPremium: profile.premium, orgUseStorage: cipher.organizationId && !!profile.organizations[cipher.organizationId].maxStorageGb }; }).then(function (perms) { if (!cipher.hasAttachments) { if (cipher.organizationId && !perms.orgUseStorage) { $uibModal.open({ animation: true, templateUrl: 'app/views/paidOrgRequired.html', controller: 'paidOrgRequiredController', resolve: { orgId: function () { return cipher.organizationId; } } }); return; } if (!cipher.organizationId && !perms.isPremium) { $uibModal.open({ animation: true, templateUrl: 'app/views/premiumRequired.html', controller: 'premiumRequiredController' }); return; } } if (!cipher.organizationId && !cryptoService.getEncKey()) { toastr.error('You cannot use this feature until you update your encryption key.', 'Feature Unavailable'); return; } var attachmentModel = $uibModal.open({ animation: true, templateUrl: 'app/vault/views/vaultAttachments.html', controller: 'vaultAttachmentsController', resolve: { cipherId: function () { return cipher.id; } } }); attachmentModel.result.then(function (hasAttachments) { cipher.hasAttachments = hasAttachments; }); }); }; $scope.editFolder = function (folder) { if (!folder.id) { return; } var editModel = $uibModal.open({ animation: true, templateUrl: 'app/vault/views/vaultEditFolder.html', controller: 'vaultEditFolderController', size: 'sm', resolve: { folderId: function () { return folder.id; } } }); editModel.result.then(function (editedFolder) { folder.name = editedFolder.name; }); }; $scope.$on('vaultAddFolder', function (event, args) { $scope.addFolder(); }); $scope.addFolder = function () { var addModel = $uibModal.open({ animation: true, templateUrl: 'app/vault/views/vaultAddFolder.html', controller: 'vaultAddFolderController', size: 'sm' }); addModel.result.then(function (addedFolder) { $rootScope.vaultFolders.push(addedFolder); }); }; $scope.deleteFolder = function (folder) { if (!folder.id) { return; } if (!confirm('Are you sure you want to delete this folder (' + folder.name + ')? ' + 'Any items will be moved to "No Folder".')) { return; } apiService.folders.del({ id: folder.id }, function () { $analytics.eventTrack('Deleted Folder'); var index = $rootScope.vaultFolders.indexOf(folder); if (index > -1) { $rootScope.vaultFolders.splice(index, 1); $scope.filterAll(); } }); }; $scope.share = function (cipher) { var modal = $uibModal.open({ animation: true, templateUrl: 'app/vault/views/vaultShareCipher.html', controller: 'vaultShareCipherController', resolve: { cipherId: function () { return cipher.id; } } }); modal.result.then(function (returned) { cipher.organizationId = returned.orgId; cipher.collectionIds = returned.collectionIds || []; }); }; $scope.editCollections = function (cipher) { var modal = $uibModal.open({ animation: true, templateUrl: 'app/vault/views/vaultCipherCollections.html', controller: 'vaultCipherCollectionsController', resolve: { cipherId: function () { return cipher.id; } } }); modal.result.then(function (response) { if (response.collectionIds && !response.collectionIds.length) { removeCipherFromScopes(cipher); } else if (response.collectionIds) { cipher.collectionIds = response.collectionIds; } }); }; $scope.filterCollection = function (col) { resetSelected(); $scope.selectedCollection = col; $scope.selectedIcon = 'fa-cube'; $scope.filter = function (c) { return c.collectionIds && c.collectionIds.indexOf(col.id) > -1; }; fixLayout(); }; $scope.filterFolder = function (f) { resetSelected(); $scope.selectedFolder = f; $scope.selectedIcon = 'fa-folder-open' + (!f.id ? '-o' : ''); $scope.filter = function (c) { return c.folderId === f.id; }; fixLayout(); }; $scope.filterType = function (t) { resetSelected(); $scope.selectedType = t; switch (t) { case constants.cipherType.login: $scope.selectedTitle = 'Login'; $scope.selectedIcon = 'fa-globe'; break; case constants.cipherType.card: $scope.selectedTitle = 'Card'; $scope.selectedIcon = 'fa-credit-card'; break; case constants.cipherType.identity: $scope.selectedTitle = 'Identity'; $scope.selectedIcon = 'fa-id-card-o'; break; case constants.cipherType.secureNote: $scope.selectedTitle = 'Secure Note'; $scope.selectedIcon = 'fa-sticky-note-o'; break; default: break; } $scope.filter = function (c) { return c.type === t; }; fixLayout(); }; $scope.filterFavorites = function () { resetSelected(); $scope.selectedFavorites = true; $scope.selectedTitle = 'Favorites'; $scope.selectedIcon = 'fa-star'; $scope.filter = function (c) { return !!c.favorite; }; fixLayout(); }; $scope.filterAll = function () { resetSelected(); $scope.selectedAll = true; $scope.selectedTitle = 'All'; $scope.selectedIcon = 'fa-th'; $scope.filter = null; fixLayout(); }; function resetSelected() { $scope.selectedFolder = undefined; $scope.selectedCollection = undefined; $scope.selectedType = undefined; $scope.selectedFavorites = false; $scope.selectedAll = false; } function fixLayout() { if ($.AdminLTE && $.AdminLTE.layout) { $timeout(function () { $.AdminLTE.layout.fix(); }, 0); } } $scope.cipherFilter = function () { return function (cipher) { return !$scope.filter || $scope.filter(cipher); }; }; $scope.unselectAll = function () { selectAll(false); }; $scope.selectAll = function () { selectAll(true); }; $scope.select = function ($event) { var checkbox = $($event.currentTarget).closest('tr').find('input[name="cipherSelection"]'); checkbox.prop('checked', !checkbox.prop('checked')); }; function distinct(value, index, self) { return self.indexOf(value) === index; } function getSelectedCiphers() { return $('input[name="cipherSelection"]:checked').map(function () { return $(this).val(); }).get().filter(distinct); } function selectAll(select) { $('input[name="cipherSelection"]').prop('checked', select); } $scope.bulkMove = function () { var ids = getSelectedCiphers(); if (ids.length === 0) { alert('You have not selected anything.'); return; } var modal = $uibModal.open({ animation: true, templateUrl: 'app/vault/views/vaultMoveCiphers.html', controller: 'vaultMoveCiphersController', size: 'sm', resolve: { ids: function () { return ids; } } }); modal.result.then(function (folderId) { for (var i = 0; i < ids.length; i++) { var cipher = $filter('filter')($rootScope.vaultCiphers, { id: ids[i] }); if (cipher.length) { cipher[0].folderId = folderId; } } selectAll(false); sortScopedCipherData(); toastr.success('Items have been moved!'); }); }; $scope.bulkDelete = function () { var ids = getSelectedCiphers(); if (ids.length === 0) { alert('You have not selected anything.'); return; } if (!confirm('Are you sure you want to delete the selected items (total: ' + ids.length + ')?')) { return; } $scope.actionLoading = true; apiService.ciphers.delMany({ ids: ids }, function () { $analytics.eventTrack('Bulk Deleted Items'); for (var i = 0; i < ids.length; i++) { var cipher = $filter('filter')($rootScope.vaultCiphers, { id: ids[i] }); if (cipher.length && cipher[0].edit) { removeCipherFromScopes(cipher[0]); } } selectAll(false); $scope.actionLoading = false; toastr.success('Items have been deleted!'); }, function (e) { var errors = validationService.parseErrors(e); toastr.error(errors.length ? errors[0] : 'An error occurred.'); $scope.actionLoading = false; }); }; function removeCipherFromScopes(cipher) { var index = $rootScope.vaultCiphers.indexOf(cipher); if (index > -1) { $rootScope.vaultCiphers.splice(index, 1); } index = $scope.ciphers.indexOf(cipher); if (index > -1) { $scope.ciphers.splice(index, 1); } } }]); angular .module('bit.vault') .controller('vaultEditCipherController', ["$scope", "apiService", "$uibModalInstance", "cryptoService", "cipherService", "passwordService", "cipherId", "$analytics", "$rootScope", "authService", "$uibModal", "constants", "$filter", function ($scope, apiService, $uibModalInstance, cryptoService, cipherService, passwordService, cipherId, $analytics, $rootScope, authService, $uibModal, constants, $filter) { $analytics.eventTrack('vaultEditCipherController', { category: 'Modal' }); $scope.folders = $rootScope.vaultFolders; $scope.cipher = {}; $scope.readOnly = false; $scope.constants = constants; authService.getUserProfile().then(function (profile) { $scope.useTotp = profile.premium; return apiService.ciphers.get({ id: cipherId }).$promise; }).then(function (cipher) { $scope.cipher = cipherService.decryptCipher(cipher); $scope.readOnly = !$scope.cipher.edit; $scope.useTotp = $scope.useTotp || $scope.cipher.organizationUseTotp; setUriMatchValues(); }); $scope.save = function (model) { if ($scope.readOnly) { $scope.savePromise = apiService.ciphers.putPartial({ id: cipherId }, { folderId: model.folderId, favorite: model.favorite }, function (response) { $analytics.eventTrack('Partially Edited Cipher'); $uibModalInstance.close({ action: 'partialEdit', data: { id: cipherId, favorite: model.favorite, folderId: model.folderId && model.folderId !== '' ? model.folderId : null } }); }).$promise; } else { var cipher = cipherService.encryptCipher(model, $scope.cipher.type); $scope.savePromise = apiService.ciphers.put({ id: cipherId }, cipher, function (cipherResponse) { $analytics.eventTrack('Edited Cipher'); var decCipher = cipherService.decryptCipherPreview(cipherResponse); $uibModalInstance.close({ action: 'edit', data: decCipher }); }).$promise; } }; $scope.generatePassword = function () { if (!$scope.cipher.login.password || confirm('Are you sure you want to overwrite the current password?')) { $analytics.eventTrack('Generated Password From Edit'); $scope.cipher.login.password = passwordService.generatePassword({ length: 14, special: true }); } }; $scope.addUri = function () { if (!$scope.cipher.login) { return; } if (!$scope.cipher.login.uris) { $scope.cipher.login.uris = []; } $scope.cipher.login.uris.push({ uri: null, match: null, matchValue: null }); }; $scope.removeUri = function (uri) { if (!$scope.cipher.login || !$scope.cipher.login.uris) { return; } var index = $scope.cipher.login.uris.indexOf(uri); if (index > -1) { $scope.cipher.login.uris.splice(index, 1); } }; $scope.uriMatchChanged = function (uri) { if ((!uri.matchValue && uri.matchValue !== 0) || uri.matchValue === '') { uri.match = null; } else { uri.match = parseInt(uri.matchValue); } }; $scope.addField = function () { if (!$scope.cipher.fields) { $scope.cipher.fields = []; } $scope.cipher.fields.push({ type: constants.fieldType.text.toString(), name: null, value: null }); }; $scope.removeField = function (field) { var index = $scope.cipher.fields.indexOf(field); if (index > -1) { $scope.cipher.fields.splice(index, 1); } }; $scope.toggleFavorite = function () { $scope.cipher.favorite = !$scope.cipher.favorite; }; $scope.clipboardSuccess = function (e) { e.clearSelection(); selectPassword(e); }; $scope.clipboardError = function (e, password) { if (password) { selectPassword(e); } alert('Your web browser does not support easy clipboard copying. Copy it manually instead.'); }; $scope.folderSort = function (item) { if (!item.id) { return ''; } return item.name.toLowerCase(); }; function selectPassword(e) { var target = $(e.trigger).parent().prev(); if (target.attr('type') === 'text') { target.select(); } } $scope.delete = function () { if (!confirm('Are you sure you want to delete this item (' + $scope.cipher.name + ')?')) { return; } apiService.ciphers.del({ id: $scope.cipher.id }, function () { $analytics.eventTrack('Deleted Cipher From Edit'); $uibModalInstance.close({ action: 'delete', data: $scope.cipher.id }); }); }; $scope.close = function () { $uibModalInstance.dismiss('cancel'); }; $scope.showUpgrade = function () { $uibModal.open({ animation: true, templateUrl: 'app/views/premiumRequired.html', controller: 'premiumRequiredController' }); }; function setUriMatchValues() { if ($scope.cipher.login && $scope.cipher.login.uris) { for (var i = 0; i < $scope.cipher.login.uris.length; i++) { $scope.cipher.login.uris[i].matchValue = $scope.cipher.login.uris[i].match || $scope.cipher.login.uris[i].match === 0 ? $scope.cipher.login.uris[i].match.toString() : ''; } } } }]); angular .module('bit.vault') .controller('vaultEditFolderController', ["$scope", "apiService", "$uibModalInstance", "cryptoService", "cipherService", "folderId", "$analytics", function ($scope, apiService, $uibModalInstance, cryptoService, cipherService, folderId, $analytics) { $analytics.eventTrack('vaultEditFolderController', { category: 'Modal' }); $scope.folder = {}; apiService.folders.get({ id: folderId }, function (folder) { $scope.folder = cipherService.decryptFolder(folder); }); $scope.savePromise = null; $scope.save = function (model) { var folder = cipherService.encryptFolder(model); $scope.savePromise = apiService.folders.put({ id: folderId }, folder, function (response) { $analytics.eventTrack('Edited Folder'); var decFolder = cipherService.decryptFolder(response); $uibModalInstance.close(decFolder); }).$promise; }; $scope.close = function () { $uibModalInstance.dismiss('cancel'); }; }]); angular .module('bit.vault') .controller('vaultMoveCiphersController', ["$scope", "apiService", "$uibModalInstance", "ids", "$analytics", "$rootScope", "$filter", function ($scope, apiService, $uibModalInstance, ids, $analytics, $rootScope, $filter) { $analytics.eventTrack('vaultMoveCiphersController', { category: 'Modal' }); $scope.folders = $rootScope.vaultFolders; $scope.count = ids.length; $scope.save = function () { $scope.savePromise = apiService.ciphers.moveMany({ ids: ids, folderId: $scope.folderId }, function () { $analytics.eventTrack('Bulk Moved Ciphers'); $uibModalInstance.close($scope.folderId || null); }).$promise; }; $scope.folderSort = function (item) { if (!item.id) { return '!'; } return item.name.toLowerCase(); }; $scope.close = function () { $uibModalInstance.dismiss('cancel'); }; }]); angular .module('bit.vault') .controller('vaultShareCipherController', ["$scope", "apiService", "$uibModalInstance", "authService", "cipherService", "cipherId", "$analytics", "$state", "cryptoService", "$q", "toastr", function ($scope, apiService, $uibModalInstance, authService, cipherService, cipherId, $analytics, $state, cryptoService, $q, toastr) { $analytics.eventTrack('vaultShareCipherController', { category: 'Modal' }); $scope.model = {}; $scope.cipher = {}; $scope.collections = []; $scope.selectedCollections = {}; $scope.organizations = []; var organizationCollectionCounts = {}; $scope.loadingCollections = true; $scope.loading = true; $scope.readOnly = false; apiService.ciphers.get({ id: cipherId }).$promise.then(function (cipher) { $scope.readOnly = !cipher.Edit; if (cipher.Edit) { $scope.cipher = cipherService.decryptCipher(cipher); } return cipher.Edit; }).then(function (canEdit) { $scope.loading = false; if (!canEdit) { return; } return authService.getUserProfile(); }).then(function (profile) { if (profile && profile.organizations) { var orgs = [], setFirstOrg = false; for (var i in profile.organizations) { if (profile.organizations.hasOwnProperty(i) && profile.organizations[i].enabled) { orgs.push({ id: profile.organizations[i].id, name: profile.organizations[i].name }); organizationCollectionCounts[profile.organizations[i].id] = 0; if (!setFirstOrg) { setFirstOrg = true; $scope.model.organizationId = profile.organizations[i].id; } } } $scope.organizations = orgs; apiService.collections.listMe({ writeOnly: true }, function (response) { var collections = []; for (var i = 0; i < response.Data.length; i++) { var decCollection = cipherService.decryptCollection(response.Data[i]); decCollection.organizationId = response.Data[i].OrganizationId; collections.push(decCollection); organizationCollectionCounts[decCollection.organizationId]++; } $scope.collections = collections; $scope.loadingCollections = false; }); } }); $scope.toggleCollectionSelectionAll = function ($event) { var collections = {}; if ($event.target.checked) { for (var i = 0; i < $scope.collections.length; i++) { if ($scope.model.organizationId && $scope.collections[i].organizationId === $scope.model.organizationId) { collections[$scope.collections[i].id] = true; } } } $scope.selectedCollections = collections; }; $scope.toggleCollectionSelection = function (id) { if (id in $scope.selectedCollections) { delete $scope.selectedCollections[id]; } else { $scope.selectedCollections[id] = true; } }; $scope.collectionSelected = function (collection) { return collection.id in $scope.selectedCollections; }; $scope.allSelected = function () { if (!$scope.model.organizationId) { return false; } return Object.keys($scope.selectedCollections).length === organizationCollectionCounts[$scope.model.organizationId]; }; $scope.orgChanged = function () { $scope.selectedCollections = {}; }; $scope.submitPromise = null; $scope.submit = function (model) { var orgKey = cryptoService.getOrgKey(model.organizationId); var errorOnUpload = false; var attachmentSharePromises = []; if ($scope.cipher.attachments) { for (var i = 0; i < $scope.cipher.attachments.length; i++) { /* jshint ignore:start */ (function (attachment) { var promise = cipherService.downloadAndDecryptAttachment(null, attachment, false) .then(function (decData) { return cryptoService.encryptToBytes(decData.buffer, orgKey); }).then(function (encData) { if (errorOnUpload) { return; } var fd = new FormData(); var blob = new Blob([encData], { type: 'application/octet-stream' }); var encFilename = cryptoService.encrypt(attachment.fileName, orgKey); fd.append('data', blob, encFilename); return apiService.ciphers.postShareAttachment({ id: cipherId, attachmentId: attachment.id, orgId: model.organizationId }, fd).$promise; }, function (err) { errorOnUpload = true; }); attachmentSharePromises.push(promise); })($scope.cipher.attachments[i]); /* jshint ignore:end */ } } var returnedCollectionIds = null; $scope.submitPromise = $q.all(attachmentSharePromises).then(function () { if (errorOnUpload) { return; } $scope.cipher.organizationId = model.organizationId; var request = { collectionIds: [], cipher: cipherService.encryptCipher($scope.cipher, $scope.cipher.type, null, true) }; for (var id in $scope.selectedCollections) { if ($scope.selectedCollections.hasOwnProperty(id)) { request.collectionIds.push(id); } } returnedCollectionIds = request.collectionIds; return apiService.ciphers.putShare({ id: cipherId }, request).$promise; }).then(function (response) { $analytics.eventTrack('Shared Cipher'); toastr.success('Item has been shared.'); $uibModalInstance.close({ orgId: model.organizationId, collectionIds: returnedCollectionIds }); }); }; $scope.close = function () { $uibModalInstance.dismiss('cancel'); }; $scope.createOrg = function () { $state.go('backend.user.settingsCreateOrg').then(function () { $uibModalInstance.dismiss('cancel'); }); }; }]); angular .module('bit.tools') .controller('toolsController', ["$scope", "$uibModal", "apiService", "toastr", "authService", function ($scope, $uibModal, apiService, toastr, authService) { $scope.import = function () { $uibModal.open({ animation: true, templateUrl: 'app/tools/views/toolsImport.html', controller: 'toolsImportController' }); }; $scope.export = function () { $uibModal.open({ animation: true, templateUrl: 'app/tools/views/toolsExport.html', controller: 'toolsExportController' }); }; }]); angular .module('bit.tools') .controller('toolsExportController', ["$scope", "apiService", "$uibModalInstance", "cipherService", "$q", "toastr", "$analytics", "constants", function ($scope, apiService, $uibModalInstance, cipherService, $q, toastr, $analytics, constants) { $analytics.eventTrack('toolsExportController', { category: 'Modal' }); $scope.export = function (model) { $scope.startedExport = true; var decCiphers = [], decFolders = []; var folderPromise = apiService.folders.list({}, function (folders) { decFolders = cipherService.decryptFolders(folders.Data); }).$promise; var ciphersPromise = apiService.ciphers.list({}, function (ciphers) { decCiphers = cipherService.decryptCiphers(ciphers.Data); }).$promise; $q.all([folderPromise, ciphersPromise]).then(function () { if (!decCiphers.length) { toastr.error('Nothing to export.', 'Error!'); $scope.close(); return; } var foldersDict = {}; for (var i = 0; i < decFolders.length; i++) { foldersDict[decFolders[i].id] = decFolders[i]; } try { var exportCiphers = []; for (i = 0; i < decCiphers.length; i++) { // only export logins and secure notes if (decCiphers[i].type !== constants.cipherType.login && decCiphers[i].type !== constants.cipherType.secureNote) { continue; } var cipher = { folder: decCiphers[i].folderId && (decCiphers[i].folderId in foldersDict) ? foldersDict[decCiphers[i].folderId].name : null, favorite: decCiphers[i].favorite ? 1 : null, type: null, name: decCiphers[i].name, notes: decCiphers[i].notes, fields: null, // Login props login_uri: null, login_username: null, login_password: null, login_totp: null }; var j; if (decCiphers[i].fields) { for (j = 0; j < decCiphers[i].fields.length; j++) { if (!cipher.fields) { cipher.fields = ''; } else { cipher.fields += '\n'; } cipher.fields += ((decCiphers[i].fields[j].name || '') + ': ' + decCiphers[i].fields[j].value); } } switch (decCiphers[i].type) { case constants.cipherType.login: cipher.type = 'login'; cipher.login_username = decCiphers[i].login.username; cipher.login_password = decCiphers[i].login.password; cipher.login_totp = decCiphers[i].login.totp; if (decCiphers[i].login.uris && decCiphers[i].login.uris.length) { cipher.login_uri = []; for (j = 0; j < decCiphers[i].login.uris.length; j++) { cipher.login_uri.push(decCiphers[i].login.uris[j].uri); } } break; case constants.cipherType.secureNote: cipher.type = 'note'; break; default: continue; } exportCiphers.push(cipher); } var csvString = Papa.unparse(exportCiphers); var csvBlob = new Blob([csvString]); // IE hack. ref http://msdn.microsoft.com/en-us/library/ie/hh779016.aspx if (window.navigator.msSaveOrOpenBlob) { window.navigator.msSaveBlob(csvBlob, makeFileName()); } else { var a = window.document.createElement('a'); a.href = window.URL.createObjectURL(csvBlob, { type: 'text/plain' }); a.download = makeFileName(); document.body.appendChild(a); // IE: "Access is denied". // ref: https://connect.microsoft.com/IE/feedback/details/797361/ie-10-treats-blob-url-as-cross-origin-and-denies-access a.click(); document.body.removeChild(a); } $analytics.eventTrack('Exported Data'); toastr.success('Your data has been exported. Check your browser\'s downloads folder.', 'Success!'); $scope.close(); } catch (err) { toastr.error('Something went wrong. Please try again.', 'Error!'); $scope.close(); } }, function () { toastr.error('Something went wrong. Please try again.', 'Error!'); $scope.close(); }); }; $scope.close = function () { $uibModalInstance.dismiss('cancel'); }; function makeFileName() { var now = new Date(); var dateString = now.getFullYear() + '' + padNumber(now.getMonth() + 1, 2) + '' + padNumber(now.getDate(), 2) + padNumber(now.getHours(), 2) + '' + padNumber(now.getMinutes(), 2) + padNumber(now.getSeconds(), 2); return 'bitwarden_export_' + dateString + '.csv'; } function padNumber(number, width, paddingCharacter) { paddingCharacter = paddingCharacter || '0'; number = number + ''; return number.length >= width ? number : new Array(width - number.length + 1).join(paddingCharacter) + number; } }]); angular .module('bit.tools') .controller('toolsImportController', ["$scope", "$state", "apiService", "$uibModalInstance", "cryptoService", "cipherService", "toastr", "importService", "$analytics", "$sce", "validationService", function ($scope, $state, apiService, $uibModalInstance, cryptoService, cipherService, toastr, importService, $analytics, $sce, validationService) { $analytics.eventTrack('toolsImportController', { category: 'Modal' }); $scope.model = { source: '' }; $scope.source = {}; $scope.splitFeatured = true; $scope.options = [ { id: 'bitwardencsv', name: 'Bitwarden (csv)', featured: true, sort: 1, instructions: $sce.trustAsHtml('Export using the web vault (vault.bitwarden.com). ' + 'Log into the web vault and navigate to "Tools" > "Export".') }, { id: 'lastpass', name: 'LastPass (csv)', featured: true, sort: 2, instructions: $sce.trustAsHtml('See detailed instructions on our help site at ' + '' + 'https://help.bitwarden.com/article/import-from-lastpass/') }, { id: 'chromecsv', name: 'Chrome (csv)', featured: true, sort: 3, instructions: $sce.trustAsHtml('See detailed instructions on our help site at ' + '' + 'https://help.bitwarden.com/article/import-from-chrome/') }, { id: 'firefoxpasswordexportercsv', name: 'Firefox Password Exporter (csv)', featured: true, sort: 4, instructions: $sce.trustAsHtml('Use the ' + '' + 'FF Password Exporter application to export your passwords to a CSV file.') }, { id: 'keepass2xml', name: 'KeePass 2 (xml)', featured: true, sort: 5, instructions: $sce.trustAsHtml('Using the KeePass 2 desktop application, navigate to "File" > "Export" and ' + 'select the KeePass XML (2.x) option.') }, { id: 'keepassxcsv', name: 'KeePassX (csv)', instructions: $sce.trustAsHtml('Using the KeePassX desktop application, navigate to "Database" > ' + '"Export to CSV file" and save the CSV file.') }, { id: 'dashlanecsv', name: 'Dashlane (csv)', featured: true, sort: 7, instructions: $sce.trustAsHtml('Using the Dashlane desktop application, navigate to "File" > "Export" > ' + '"Unsecured archive (readable) in CSV format" and save the CSV file.') }, { id: '1password1pif', name: '1Password (1pif)', featured: true, sort: 6, instructions: $sce.trustAsHtml('See detailed instructions on our help site at ' + '' + 'https://help.bitwarden.com/article/import-from-1password/') }, { id: '1password6wincsv', name: '1Password 6 Windows (csv)', instructions: $sce.trustAsHtml('See detailed instructions on our help site at ' + '' + 'https://help.bitwarden.com/article/import-from-1password/') }, { id: 'roboformhtml', name: 'RoboForm (html)', instructions: $sce.trustAsHtml('Using the RoboForm Editor desktop application, navigate to "RoboForm" ' + '(top left) > "Print List" > "Logins". When the following print dialog pops up click on the "Save" button ' + 'and save the HTML file.') }, { id: 'keepercsv', name: 'Keeper (csv)', instructions: $sce.trustAsHtml('Log into the Keeper web vault (keepersecurity.com/vault). Navigate to "Backup" ' + '(top right) and find the "Export to Text File" option. Click "Export Now" to save the TXT/CSV file.') }, { id: 'enpasscsv', name: 'Enpass (csv)', instructions: $sce.trustAsHtml('Using the Enpass desktop application, navigate to "File" > "Export" > ' + '"As CSV". Select "Yes" to the warning alert and save the CSV file. Note that the importer only fully ' + 'supports files exported while Enpass is set to the English language, so adjust your settings accordingly.') }, { id: 'safeincloudxml', name: 'SafeInCloud (xml)', instructions: $sce.trustAsHtml('Using the SaveInCloud desktop application, navigate to "File" > "Export" > ' + '"As XML" and save the XML file.') }, { id: 'pwsafexml', name: 'Password Safe (xml)', instructions: $sce.trustAsHtml('Using the Password Safe desktop application, navigate to "File" > ' + '"Export To" > "XML format..." and save the XML file.') }, { id: 'stickypasswordxml', name: 'Sticky Password (xml)', instructions: $sce.trustAsHtml('Using the Sticky Password desktop application, navigate to "Menu" ' + '(top right) > "Export" > "Export all". Select the unencrypted format XML option and then the ' + '"Save to file" button. Save the XML file.') }, { id: 'msecurecsv', name: 'mSecure (csv)', instructions: $sce.trustAsHtml('Using the mSecure desktop application, navigate to "File" > ' + '"Export" > "CSV File..." and save the CSV file.') }, { id: 'truekeycsv', name: 'True Key (csv)', instructions: $sce.trustAsHtml('Using the True Key desktop application, click the gear icon (top right) and ' + 'then navigate to "App Settings". Click the "Export" button, enter your password and save the CSV file.') }, { id: 'passwordbossjson', name: 'Password Boss (json)', instructions: $sce.trustAsHtml('Using the Password Boss desktop application, navigate to "File" > ' + '"Export data" > "Password Boss JSON - not encrypted" and save the JSON file.') }, { id: 'zohovaultcsv', name: 'Zoho Vault (csv)', instructions: $sce.trustAsHtml('Log into the Zoho web vault (vault.zoho.com). Navigate to "Tools" > ' + '"Export Secrets". Select "All Secrets" and click the "Zoho Vault Format CSV" button. Highlight ' + 'and copy the data from the textarea. Open a text editor like Notepad and paste the data. Save the ' + 'data from the text editor aszoho_export.csv.')
},
{
id: 'splashidcsv',
name: 'SplashID (csv)',
instructions: $sce.trustAsHtml('Using the SplashID Safe desktop application, click on the SplashID ' +
'blue lock logo in the top right corner. Navigate to "Export" > "Export as CSV" and save the CSV file.')
},
{
id: 'passworddragonxml',
name: 'Password Dragon (xml)',
instructions: $sce.trustAsHtml('Using the Password Dragon desktop application, navigate to "File" > ' +
'"Export" > "To XML". In the dialog that pops up select "All Rows" and check all fields. Click ' +
'the "Export" button and save the XML file.')
},
{
id: 'padlockcsv',
name: 'Padlock (csv)',
instructions: $sce.trustAsHtml('Using the Padlock desktop application, click the hamburger icon ' +
'in the top left corner and navigate to "Settings". Click the "Export Data" option. Ensure that ' +
'the "CSV" option is selected from the dropdown. Highlight and copy the data from the textarea. ' +
'Open a text editor like Notepad and paste the data. Save the data from the text editor as ' +
'padlock_export.csv.')
},
{
id: 'clipperzhtml',
name: 'Clipperz (html)',
instructions: $sce.trustAsHtml('Log into the Clipperz web application (clipperz.is/app). Click the ' +
'hamburger menu icon in the top right to expand the navigation bar. Navigate to "Data" > ' +
'"Export". Click the "download HTML+JSON" button to save the HTML file.')
},
{
id: 'avirajson',
name: 'Avira (json)',
instructions: $sce.trustAsHtml('Using the Avira browser extension, click your username in the top ' +
'right corner and navigate to "Settings". Locate the "Export Data" section and click "Export". ' +
'In the dialog that pops up, click the "Export Password Manager Data" button to save the ' +
'TXT/JSON file.')
},
{
id: 'saferpasscsv',
name: 'SaferPass (csv)',
instructions: $sce.trustAsHtml('Using the SaferPass browser extension, click the hamburger icon ' +
'in the top left corner and navigate to "Settings". Click the "Export accounts" button to ' +
'save the CSV file.')
},
{
id: 'upmcsv',
name: 'Universal Password Manager (csv)',
instructions: $sce.trustAsHtml('Using the Universal Password Manager desktop application, navigate ' +
'to "Database" > "Export" and save the CSV file.')
},
{
id: 'ascendocsv',
name: 'Ascendo DataVault (csv)',
instructions: $sce.trustAsHtml('Using the Ascendo DataVault desktop application, navigate ' +
'to "Tools" > "Export". In the dialog that pops up, select the "All Items (DVX, CSV)" ' +
'option. Click the "Ok" button to save the CSV file.')
},
{
id: 'meldiumcsv',
name: 'Meldium (csv)',
instructions: $sce.trustAsHtml('Using the Meldium web vault, navigate to "Settings". ' +
'Locate the "Export data" function and click "Show me my data" to save the CSV file.')
},
{
id: 'passkeepcsv',
name: 'PassKeep (csv)',
instructions: $sce.trustAsHtml('Using the PassKeep mobile app, navigate to "Backup/Restore". ' +
'Locate the "CSV Backup/Restore" section and click "Backup to CSV" to save the CSV file.')
},
{
id: 'operacsv',
name: 'Opera (csv)',
instructions: $sce.trustAsHtml('The process for importing from Opera is exactly the same as ' +
'importing from Google Chrome. See detailed instructions on our help site at ' +
'' +
'https://help.bitwarden.com/article/import-from-chrome/')
},
{
id: 'vivaldicsv',
name: 'Vivaldi (csv)',
instructions: $sce.trustAsHtml('The process for importing from Vivaldi is exactly the same as ' +
'importing from Google Chrome. See detailed instructions on our help site at ' +
'' +
'https://help.bitwarden.com/article/import-from-chrome/')
},
{
id: 'gnomejson',
name: 'GNOME Passwords and Keys/Seahorse (json)',
instructions: $sce.trustAsHtml('Make sure you have python-keyring and python-gnomekeyring installed. ' +
'Save the GNOME Keyring Import/Export ' +
'python script by Luke Plant to your desktop as pw_helper.py. Open terminal and run ' +
'chmod +rx Desktop/pw_helper.py and then ' +
'python Desktop/pw_helper.py export Desktop/my_passwords.json. Then upload ' +
'the resulting my_passwords.json file here to Bitwarden.')
}
];
$scope.setSource = function () {
for (var i = 0; i < $scope.options.length; i++) {
if ($scope.options[i].id === $scope.model.source) {
$scope.source = $scope.options[i];
break;
}
}
};
$scope.setSource();
$scope.import = function (model, form) {
if (!model.source || model.source === '') {
validationService.addError(form, 'source', 'Select the format of the import file.', true);
return;
}
var file = document.getElementById('file').files[0];
if (!file && (!model.fileContents || model.fileContents === '')) {
validationService.addError(form, 'file', 'Select the import file or copy/paste the import file contents.', true);
return;
}
$scope.processing = true;
importService.import(model.source, file || model.fileContents, importSuccess, importError);
};
function importSuccess(folders, ciphers, folderRelationships) {
if (!folders.length && !ciphers.length) {
importError('Nothing was imported.');
return;
}
else if (ciphers.length) {
var halfway = Math.floor(ciphers.length / 2);
var last = ciphers.length - 1;
if (cipherIsBadData(ciphers[0]) && cipherIsBadData(ciphers[halfway]) && cipherIsBadData(ciphers[last])) {
importError('Data is not formatted correctly. Please check your import file and try again.');
return;
}
}
apiService.ciphers.import({
folders: cipherService.encryptFolders(folders),
ciphers: cipherService.encryptCiphers(ciphers),
folderRelationships: folderRelationships
}, function () {
$uibModalInstance.dismiss('cancel');
$state.go('backend.user.vault', { refreshFromServer: true }).then(function () {
$analytics.eventTrack('Imported Data', { label: $scope.model.source });
toastr.success('Data has been successfully imported into your vault.', 'Import Success');
});
}, importError);
}
function cipherIsBadData(cipher) {
return (cipher.name === null || cipher.name === '--') &&
(cipher.login && (cipher.login.password === null || cipher.login.password === ''));
}
function importError(error) {
$analytics.eventTrack('Import Data Failed', { label: $scope.model.source });
$uibModalInstance.dismiss('cancel');
if (error) {
var data = error.data;
if (data && data.ValidationErrors) {
var message = '';
for (var key in data.ValidationErrors) {
if (!data.ValidationErrors.hasOwnProperty(key)) {
continue;
}
for (var i = 0; i < data.ValidationErrors[key].length; i++) {
message += (key + ': ' + data.ValidationErrors[key][i] + ' ');
}
}
if (message !== '') {
toastr.error(message);
return;
}
}
else if (data && data.Message) {
toastr.error(data.Message);
return;
}
else {
toastr.error(error);
return;
}
}
toastr.error('Something went wrong. Try again.', 'Oh No!');
}
$scope.close = function () {
$uibModalInstance.dismiss('cancel');
};
}]);