diff options
author | brantje <brantje@gmail.com> | 2016-10-15 18:05:25 +0300 |
---|---|---|
committer | brantje <brantje@gmail.com> | 2016-10-14 16:49:08 +0300 |
commit | d5a123abf45c54bd2e8b02cbd312322c4602181d (patch) | |
tree | a8e054fd25a34850ad0bf15e68048ecac488b371 /js | |
parent | 8b31278429e84ae2ebd053faad73d95fe98cbe55 (diff) |
Use global namespace for importers
Diffstat (limited to 'js')
-rw-r--r-- | js/importers/import-main.js | 183 | ||||
-rw-r--r-- | js/importers/importer-clipperz.js | 104 | ||||
-rw-r--r-- | js/importers/importer-dashlanecsv.js | 87 | ||||
-rw-r--r-- | js/importers/importer-keepasscsv.js | 91 | ||||
-rw-r--r-- | js/importers/importer-lastpasscsv.js | 73 | ||||
-rw-r--r-- | js/importers/importer-passmanjson.js | 126 | ||||
-rw-r--r-- | js/importers/importer-passpackcsv.js | 95 | ||||
-rw-r--r-- | js/importers/importer-randomdata.js | 165 | ||||
-rw-r--r-- | js/importers/importer-zohocsv.js | 75 |
9 files changed, 505 insertions, 494 deletions
diff --git a/js/importers/import-main.js b/js/importers/import-main.js index 5f5944bb..6443be49 100644 --- a/js/importers/import-main.js +++ b/js/importers/import-main.js @@ -1,98 +1,99 @@ -// Importers should always start with this -if(!window['PassmanImporter']){ - var PassmanImporter = {} -} +var PassmanImporter = PassmanImporter || {}; +(function(window, $, PassmanImporter) { + 'use strict'; -PassmanImporter.parseRow_ = function(row) { - // Strip leading quote. - row = row.trim(); - var isQuoted = false; - if (row.charAt(0) == '"') { - row = row.substring(1); - isQuoted = true; - } - if (row.charAt(row.length - 2) == '"') { - row = row.substring(0, row.length - 2); - isQuoted = true; - } - // Strip trailing quote. There seems to be a character between the last quote - // and the line ending, hence 2 instead of 1. - if(isQuoted == true) { - row = row.split('","'); - } else { - row = row.split(','); - } - return row; -}; -PassmanImporter.htmlDecode = function(input){ - var e = document.createElement('div'); - e.innerHTML = input; - return e.childNodes[0].nodeValue; -}; -PassmanImporter.toObject_ = function(headings, row) { - var result = {}; - for (var i = 0, ii = row.length; i < ii; i++) { - headings[i] = headings[i].replace(',','_') - .toLowerCase().replace(' ','_') - .replace('(','').replace(')','') - .replace('"',''); - result[headings[i]] = row[i]; - } - return result; -}; -PassmanImporter.join_ = function(arr, sep) { - var parts = []; - for (var i = 0, ii = arr.length; i < ii; i++) { - arr[i] && parts.push(arr[i]); - } - return parts.join(sep); -}; - -PassmanImporter.newCredential = function () { - var credential = { - 'credential_id': null, - 'guid': null, - 'vault_id': null, - 'label': null, - 'description': null, - 'created': null, - 'changed': null, - 'tags': [], - 'email': null, - 'username': null, - 'password': null, - 'url': null, - 'favicon': null, - 'renew_interval': null, - 'expire_time': 0, - 'delete_time': 0, - 'files': [], - 'custom_fields': [], - 'otp': {}, - 'hidden': false + PassmanImporter.parseRow_ = function(row) { + // Strip leading quote. + row = row.trim(); + var isQuoted = false; + if (row.charAt(0) == '"') { + row = row.substring(1); + isQuoted = true; + } + if (row.charAt(row.length - 2) == '"') { + row = row.substring(0, row.length - 2); + isQuoted = true; + } + // Strip trailing quote. There seems to be a character between the last quote + // and the line ending, hence 2 instead of 1. + if(isQuoted == true) { + row = row.split('","'); + } else { + row = row.split(','); + } + return row; + }; + PassmanImporter.htmlDecode = function(input){ + var e = document.createElement('div'); + e.innerHTML = input; + return e.childNodes[0].nodeValue; + }; + PassmanImporter.toObject_ = function(headings, row) { + var result = {}; + for (var i = 0, ii = row.length; i < ii; i++) { + headings[i] = headings[i].replace(',','_') + .toLowerCase().replace(' ','_') + .replace('(','').replace(')','') + .replace('"',''); + result[headings[i]] = row[i]; + } + return result; }; - return credential; -}; -PassmanImporter.readCsv = function( csv, hasHeadings ){ - hasHeadings = (hasHeadings === undefined) ? true : hasHeadings; - var lines = []; - var rows = csv.split('\n'); - if(hasHeadings) { - var headings = this.parseRow_(rows[0]); - for (var i = 1, row; row = rows[i]; i++) { - row = this.toObject_(headings, this.parseRow_(row)); - lines.push(row); + PassmanImporter.join_ = function(arr, sep) { + var parts = []; + for (var i = 0, ii = arr.length; i < ii; i++) { + arr[i] && parts.push(arr[i]); } - } else { - for (var i = 1, row; row = rows[i]; i++) { - lines.push(this.parseRow_(row)); + return parts.join(sep); + }; + + PassmanImporter.newCredential = function () { + var credential = { + 'credential_id': null, + 'guid': null, + 'vault_id': null, + 'label': null, + 'description': null, + 'created': null, + 'changed': null, + 'tags': [], + 'email': null, + 'username': null, + 'password': null, + 'url': null, + 'favicon': null, + 'renew_interval': null, + 'expire_time': 0, + 'delete_time': 0, + 'files': [], + 'custom_fields': [], + 'otp': {}, + 'hidden': false + }; + return credential; + }; + + PassmanImporter.readCsv = function( csv, hasHeadings ){ + hasHeadings = (hasHeadings === undefined) ? true : hasHeadings; + var lines = []; + var rows = csv.split('\n'); + if(hasHeadings) { + var headings = this.parseRow_(rows[0]); + for (var i = 1, row; row = rows[i]; i++) { + row = this.toObject_(headings, this.parseRow_(row)); + lines.push(row); + } + } else { + for (var i = 1, row; row = rows[i]; i++) { + lines.push(this.parseRow_(row)); + } } - } - return lines; -}; + return lines; + }; -PassmanImporter.readJson = function (string){ - return JSON.parse(string); -};
\ No newline at end of file + PassmanImporter.readJson = function (string){ + return JSON.parse(string); + }; +})(window, $, PassmanImporter); diff --git a/js/importers/importer-clipperz.js b/js/importers/importer-clipperz.js index e9194bcc..213f969c 100644 --- a/js/importers/importer-clipperz.js +++ b/js/importers/importer-clipperz.js @@ -1,58 +1,58 @@ // Importers should always start with this -if (!window['PassmanImporter']) { - var PassmanImporter = {} -} -// Define the importer -PassmanImporter.clippers = { - info: { - name: 'Clipperz.is', - id: 'clippers', - description: 'Go to menu -> Export -> Download HTML + JSON. Fields will be imported as custom fields.' - } -}; +var PassmanImporter = PassmanImporter || {}; +(function(window, $, PassmanImporter) { + 'use strict'; + PassmanImporter.clippers = { + info: { + name: 'Clipperz.is', + id: 'clippers', + description: 'Go to menu -> Export -> Download HTML + JSON. Fields will be imported as custom fields.' + } + }; -PassmanImporter.clippers.readFile = function (file_data) { - return new C_Promise(function() { - var credential_list = []; - var re = /<textarea>(.*?)<\/textarea>/gi; - var matches = re.exec(file_data); - if(matches){ - var raw_json = matches[0].substring(10); - raw_json = PassmanImporter.htmlDecode(raw_json.slice(0, -11)); - var json_objects = PassmanImporter.readJson(raw_json); - for(var i = 0; i < json_objects.length; i++){ - var card = json_objects[i]; - re = /(\w+)/gi; - var tags = card.label.match(re); - card.label = card.label.replace(tags.join(' '), '').trim(); - tags = tags.map(function(item){ return {text: item.replace('', '') }}); + PassmanImporter.clippers.readFile = function (file_data) { + return new C_Promise(function() { + var credential_list = []; + var re = /<textarea>(.*?)<\/textarea>/gi; + var matches = re.exec(file_data); + if(matches){ + var raw_json = matches[0].substring(10); + raw_json = PassmanImporter.htmlDecode(raw_json.slice(0, -11)); + var json_objects = PassmanImporter.readJson(raw_json); + for(var i = 0; i < json_objects.length; i++){ + var card = json_objects[i]; + re = /(\w+)/gi; + var tags = card.label.match(re); + card.label = card.label.replace(tags.join(' '), '').trim(); + tags = tags.map(function(item){ return {text: item.replace('', '') }}); - var _credential = PassmanImporter.newCredential(); - _credential.label = card.label; - _credential.description = card.data.notes; - _credential.tags = tags; - for(var field in card.currentVersion.fields){ - var field_data = card.currentVersion.fields[field]; - _credential.custom_fields.push( - { - 'label': field_data.label, - 'value': field_data.value, - 'secret': (field_data.hidden == true) - } - ) - } - if(_credential.label){ - credential_list.push(_credential); + var _credential = PassmanImporter.newCredential(); + _credential.label = card.label; + _credential.description = card.data.notes; + _credential.tags = tags; + for(var field in card.currentVersion.fields){ + var field_data = card.currentVersion.fields[field]; + _credential.custom_fields.push( + { + 'label': field_data.label, + 'value': field_data.value, + 'secret': (field_data.hidden == true) + } + ) + } + if(_credential.label){ + credential_list.push(_credential); + } + var progress = { + percent: i/json_objects.length*100, + loaded: i, + total: json_objects.length + }; + this.call_progress(progress); } - var progress = { - percent: i/json_objects.length*100, - loaded: i, - total: json_objects.length - }; - this.call_progress(progress); } - } - this.call_then(credential_list); - }); -};
\ No newline at end of file + this.call_then(credential_list); + }); + }; +})(window, $, PassmanImporter); diff --git a/js/importers/importer-dashlanecsv.js b/js/importers/importer-dashlanecsv.js index 40652bac..2efe7d2e 100644 --- a/js/importers/importer-dashlanecsv.js +++ b/js/importers/importer-dashlanecsv.js @@ -1,48 +1,49 @@ // Importers should always start with this -if (!window['PassmanImporter']) { - var PassmanImporter = {} -} -// Define the importer -PassmanImporter.dashLaneCsv = { - info: { - name: 'Dashlane 4 csv', - id: 'dashLaneCsv', - description: 'Create an csv export. Go to File -> export -> Unsecured archive (readable) in CSV format' - } -}; +var PassmanImporter = PassmanImporter || {}; +(function(window, $, PassmanImporter) { + 'use strict'; + // Define the importer + PassmanImporter.dashLaneCsv = { + info: { + name: 'Dashlane 4 csv', + id: 'dashLaneCsv', + description: 'Create an csv export. Go to File -> export -> Unsecured archive (readable) in CSV format' + } + }; -PassmanImporter.dashLaneCsv.readFile = function (file_data) { - return new C_Promise(function(){ - var rows = file_data.split('\n'); - var credential_list = []; - for (var i = 0; i < rows.length; i++) { - var row = rows[i]; - var row_data = row.split('","'); - if (row_data[0].charAt(0) == '"') { - row_data[0] = row_data[0].substring(1); - } + PassmanImporter.dashLaneCsv.readFile = function (file_data) { + return new C_Promise(function(){ + var rows = file_data.split('\n'); + var credential_list = []; + for (var i = 0; i < rows.length; i++) { + var row = rows[i]; + var row_data = row.split('","'); + if (row_data[0].charAt(0) == '"') { + row_data[0] = row_data[0].substring(1); + } - if (row_data[row_data.length-1].toString().charAt(row_data[row_data.length - 1].length - 1) == '"') { - row_data[row_data.length - 1] = row_data[row_data.length -1].substring(0, row_data[row_data.length - 1].length - 1); - } + if (row_data[row_data.length-1].toString().charAt(row_data[row_data.length - 1].length - 1) == '"') { + row_data[row_data.length - 1] = row_data[row_data.length -1].substring(0, row_data[row_data.length - 1].length - 1); + } - var _credential = PassmanImporter.newCredential(); - _credential.label = row_data[0]; - _credential.username = row_data[2]; - _credential.password = row_data[row_data.length - 2]; - _credential.url = row_data[0]; - _credential.description = row_data[row_data.length - 1]; - if(_credential.label){ - credential_list.push(_credential); - } + var _credential = PassmanImporter.newCredential(); + _credential.label = row_data[0]; + _credential.username = row_data[2]; + _credential.password = row_data[row_data.length - 2]; + _credential.url = row_data[0]; + _credential.description = row_data[row_data.length - 1]; + if(_credential.label){ + credential_list.push(_credential); + } - var progress = { - percent: i/rows.length*100, - loaded: i, - total: rows.length - }; - this.call_progress(progress); - } - this.call_then(credential_list); - }); -};
\ No newline at end of file + var progress = { + percent: i/rows.length*100, + loaded: i, + total: rows.length + }; + this.call_progress(progress); + } + this.call_then(credential_list); + }); + }; +})(window, $, PassmanImporter); diff --git a/js/importers/importer-keepasscsv.js b/js/importers/importer-keepasscsv.js index f328d306..cdaec06e 100644 --- a/js/importers/importer-keepasscsv.js +++ b/js/importers/importer-keepasscsv.js @@ -1,50 +1,51 @@ // Importers should always start with this -if (!window['PassmanImporter']) { - var PassmanImporter = {} -} -// Define the importer -PassmanImporter.keepassCsv = { - info: { - name: 'KeePass csv', - id: 'keepassCsv', - description: 'Create an csv export with the following options enabled: http://i.imgur.com/CaeTA4d.png' - } -}; +var PassmanImporter = PassmanImporter || {}; +(function(window, $, PassmanImporter) { + 'use strict'; + // Define the importer + PassmanImporter.keepassCsv = { + info: { + name: 'KeePass csv', + id: 'keepassCsv', + description: 'Create an csv export with the following options enabled: http://i.imgur.com/CaeTA4d.png' + } + }; -PassmanImporter.keepassCsv.readFile = function (file_data) { - var p = new C_Promise(function(){ - var parsed_csv = PassmanImporter.readCsv(file_data); - var credential_list = []; - for (var i = 0; i < parsed_csv.length; i++) { - var row = parsed_csv[i]; - var _credential = PassmanImporter.newCredential(); - _credential.label = row.account; - _credential.username = row.login_name; - _credential.password = row.password; - _credential.url = row.web_site; - if (row.hasOwnProperty('expires')) { - row.expires = row.expires.replace('"',''); - _credential.expire_time = new Date(row.expires).getTime() / 1000; - } - var tags = [{text: row.group}]; - if (row.hasOwnProperty('group_tree')) { - var exploded_tree = row.group_tree.split('\\\\'); - for (var t = 0; t < exploded_tree.length; t++) { - tags.push({text: exploded_tree[t]}); + PassmanImporter.keepassCsv.readFile = function (file_data) { + var p = new C_Promise(function(){ + var parsed_csv = PassmanImporter.readCsv(file_data); + var credential_list = []; + for (var i = 0; i < parsed_csv.length; i++) { + var row = parsed_csv[i]; + var _credential = PassmanImporter.newCredential(); + _credential.label = row.account; + _credential.username = row.login_name; + _credential.password = row.password; + _credential.url = row.web_site; + if (row.hasOwnProperty('expires')) { + row.expires = row.expires.replace('"',''); + _credential.expire_time = new Date(row.expires).getTime() / 1000; } - } - _credential.tags = tags; - credential_list.push(_credential); + var tags = [{text: row.group}]; + if (row.hasOwnProperty('group_tree')) { + var exploded_tree = row.group_tree.split('\\\\'); + for (var t = 0; t < exploded_tree.length; t++) { + tags.push({text: exploded_tree[t]}); + } + } + _credential.tags = tags; + credential_list.push(_credential); - var progress = { - percent: i/parsed_csv.length*100, - loaded: i, - total: parsed_csv.length - }; + var progress = { + percent: i/parsed_csv.length*100, + loaded: i, + total: parsed_csv.length + }; - this.call_progress(progress); - } - this.call_then(credential_list); - }); - return p; -};
\ No newline at end of file + this.call_progress(progress); + } + this.call_then(credential_list); + }); + return p; + }; +})(window, $, PassmanImporter); diff --git a/js/importers/importer-lastpasscsv.js b/js/importers/importer-lastpasscsv.js index c370a3d2..02b57546 100644 --- a/js/importers/importer-lastpasscsv.js +++ b/js/importers/importer-lastpasscsv.js @@ -1,39 +1,40 @@ // Importers should always start with this -if (!window['PassmanImporter']) { - var PassmanImporter = {} -} -// Define the importer -PassmanImporter.lastpassCsv = { - info: { - name: 'LastPass csv', - id: 'lastpassCsv', - description: 'Create an csv export. Go to More options -> Advanced -> Export -> Last Pass CSV File' - } -}; +var PassmanImporter = PassmanImporter || {}; +(function(window, $, PassmanImporter) { + 'use strict'; + // Define the importer + PassmanImporter.lastpassCsv = { + info: { + name: 'LastPass csv', + id: 'lastpassCsv', + description: 'Create an csv export. Go to More options -> Advanced -> Export -> Last Pass CSV File' + } + }; -PassmanImporter.lastpassCsv.readFile = function (file_data) { - return new C_Promise(function(){ - var parsed_csv = PassmanImporter.readCsv(file_data); - var credential_list = []; - for (var i = 0; i < parsed_csv.length; i++) { - var row = parsed_csv[i]; - var _credential = PassmanImporter.newCredential(); - _credential.label = PassmanImporter.htmlDecode(row.name); - _credential.username = row.username; - _credential.password = row.password; - _credential.url = row.url; - _credential.tags = [{text: row.grouping}]; - _credential.description = row.extra; - if(_credential.label){ - credential_list.push(_credential); + PassmanImporter.lastpassCsv.readFile = function (file_data) { + return new C_Promise(function(){ + var parsed_csv = PassmanImporter.readCsv(file_data); + var credential_list = []; + for (var i = 0; i < parsed_csv.length; i++) { + var row = parsed_csv[i]; + var _credential = PassmanImporter.newCredential(); + _credential.label = PassmanImporter.htmlDecode(row.name); + _credential.username = row.username; + _credential.password = row.password; + _credential.url = row.url; + _credential.tags = [{text: row.grouping}]; + _credential.description = row.extra; + if(_credential.label){ + credential_list.push(_credential); + } + var progress = { + percent: i/parsed_csv.length*100, + loaded: i, + total: parsed_csv.length + }; + this.call_progress(progress); } - var progress = { - percent: i/parsed_csv.length*100, - loaded: i, - total: parsed_csv.length - }; - this.call_progress(progress); - } - this.call_then(credential_list) - }); -};
\ No newline at end of file + this.call_then(credential_list) + }); + }; +})(window, $, PassmanImporter);
\ No newline at end of file diff --git a/js/importers/importer-passmanjson.js b/js/importers/importer-passmanjson.js index 44b0a7cd..cb72b3ac 100644 --- a/js/importers/importer-passmanjson.js +++ b/js/importers/importer-passmanjson.js @@ -1,70 +1,70 @@ // Importers should always start with this -if (!window['PassmanImporter']) { - var PassmanImporter = {} -} -// Define the importer -PassmanImporter.passmanJson = { - info: { - name: 'Passman JSON', - id: 'passmanJson', - description: 'Export the item in passman as passman json, with all fields enabled' - } -}; +var PassmanImporter = PassmanImporter || {}; +(function(window, $, PassmanImporter) { + 'use strict'; + PassmanImporter.passmanJson = { + info: { + name: 'Passman JSON', + id: 'passmanJson', + description: 'Export the item in passman as passman json, with all fields enabled' + } + }; -PassmanImporter.passmanJson.readFile = function (file_data) { - return new C_Promise(function(){ - var parsed_json = PassmanImporter.readJson(file_data); - var credential_list = []; - for (var i = 0; i < parsed_json.length; i++) { - var item = parsed_json[i]; - var _credential = PassmanImporter.newCredential(); - _credential.label = item.label; - _credential.username = item.account; - _credential.password = item.password; - _credential.email = item.email; - _credential.url = item.url; - _credential.tags = item.tags; - _credential.description = item.description; - //Check for custom fields - if (item.hasOwnProperty('customFields')) { - //Check for otp - if (item.customFields.length > 0) { - for (var cf = 0; cf < item.customFields.length; cf++) { - _credential.custom_fields.push( - { - 'label': item.customFields[cf].label, - 'value': item.customFields[cf].value, - 'secret': (item.customFields[cf].clicktoshow == '1') - } - ) + PassmanImporter.passmanJson.readFile = function (file_data) { + return new C_Promise(function(){ + var parsed_json = PassmanImporter.readJson(file_data); + var credential_list = []; + for (var i = 0; i < parsed_json.length; i++) { + var item = parsed_json[i]; + var _credential = PassmanImporter.newCredential(); + _credential.label = item.label; + _credential.username = item.account; + _credential.password = item.password; + _credential.email = item.email; + _credential.url = item.url; + _credential.tags = item.tags; + _credential.description = item.description; + //Check for custom fields + if (item.hasOwnProperty('customFields')) { + //Check for otp + if (item.customFields.length > 0) { + for (var cf = 0; cf < item.customFields.length; cf++) { + _credential.custom_fields.push( + { + 'label': item.customFields[cf].label, + 'value': item.customFields[cf].value, + 'secret': (item.customFields[cf].clicktoshow == '1') + } + ) + } } } - } - if (item.hasOwnProperty('otpsecret')) { - if (item.otpsecret) { - _credential.otp = { - 'issuer': item.otpsecret.issuer, - 'label': item.otpsecret.label, - 'qr_uri': { - 'image': item.otpsecret.qrCode, - 'qrData': '' - }, - 'secret': item.otpsecret.secret, - 'type': item.otpsecret.type + if (item.hasOwnProperty('otpsecret')) { + if (item.otpsecret) { + _credential.otp = { + 'issuer': item.otpsecret.issuer, + 'label': item.otpsecret.label, + 'qr_uri': { + 'image': item.otpsecret.qrCode, + 'qrData': '' + }, + 'secret': item.otpsecret.secret, + 'type': item.otpsecret.type + } } } - } - if(_credential.label){ - credential_list.push(_credential); - } - var progress = { - percent: i/parsed_json.length*100, - loaded: i, - total: parsed_json.length - }; + if(_credential.label){ + credential_list.push(_credential); + } + var progress = { + percent: i/parsed_json.length*100, + loaded: i, + total: parsed_json.length + }; - this.call_progress(progress); - } - this.call_then(credential_list); - }); -};
\ No newline at end of file + this.call_progress(progress); + } + this.call_then(credential_list); + }); + }; +})(window, $, PassmanImporter); diff --git a/js/importers/importer-passpackcsv.js b/js/importers/importer-passpackcsv.js index ab852024..bf4026c2 100644 --- a/js/importers/importer-passpackcsv.js +++ b/js/importers/importer-passpackcsv.js @@ -1,52 +1,53 @@ // Importers should always start with this -if (!window['PassmanImporter']) { - var PassmanImporter = {} -} -// Define the importer -PassmanImporter.passpackCsv = { - info: { - name: 'Passpack csv', - id: 'passpackCsv', - description: 'Go to Tools -> Export. Select Comma Separated Values, All entries then continue.' - } -}; +var PassmanImporter = PassmanImporter || {}; +(function(window, $, PassmanImporter) { + 'use strict'; + // Define the importer + PassmanImporter.passpackCsv = { + info: { + name: 'Passpack csv', + id: 'passpackCsv', + description: 'Go to Tools -> Export. Select Comma Separated Values, All entries then continue.' + } + }; -PassmanImporter.passpackCsv.readFile = function (file_data) { - return new C_Promise(function(){ - var parsed_csv = PassmanImporter.readCsv(file_data, false); - var credential_list = []; - for (var i = 0; i < parsed_csv.length; i++) { - var row = parsed_csv[i]; - var _credential = PassmanImporter.newCredential(); - _credential.label = row[0]; - _credential.username = row[1]; - _credential.password = row[2]; - _credential.url = row[3]; - var tags = row[4].split(' '); - if (tags.length > 0) { - _credential.tags = tags.map(function (item) { - if (item) { - return {text: item} - } + PassmanImporter.passpackCsv.readFile = function (file_data) { + return new C_Promise(function(){ + var parsed_csv = PassmanImporter.readCsv(file_data, false); + var credential_list = []; + for (var i = 0; i < parsed_csv.length; i++) { + var row = parsed_csv[i]; + var _credential = PassmanImporter.newCredential(); + _credential.label = row[0]; + _credential.username = row[1]; + _credential.password = row[2]; + _credential.url = row[3]; + var tags = row[4].split(' '); + if (tags.length > 0) { + _credential.tags = tags.map(function (item) { + if (item) { + return {text: item} + } - }).filter(function (item) { - return (item); - }); - } - _credential.description = row[5]; - _credential.email = row[6]; - if (_credential.label) { - credential_list.push(_credential); - } + }).filter(function (item) { + return (item); + }); + } + _credential.description = row[5]; + _credential.email = row[6]; + if (_credential.label) { + credential_list.push(_credential); + } - var progress = { - percent: i/parsed_csv.length*100, - loaded: i, - total: parsed_csv.length - }; + var progress = { + percent: i/parsed_csv.length*100, + loaded: i, + total: parsed_csv.length + }; - this.call_progress(progress); - } - this.call_then(credential_list); - }) -};
\ No newline at end of file + this.call_progress(progress); + } + this.call_then(credential_list); + }) + }; +})(window, $, PassmanImporter);
\ No newline at end of file diff --git a/js/importers/importer-randomdata.js b/js/importers/importer-randomdata.js index b12a666a..6d241c8d 100644 --- a/js/importers/importer-randomdata.js +++ b/js/importers/importer-randomdata.js @@ -1,94 +1,97 @@ // Importers should always start with this -if (!window['PassmanImporter']) { - var PassmanImporter = {} -} +var PassmanImporter = PassmanImporter || {}; +(function(window, $, PassmanImporter) { + 'use strict'; + // Define the importer + // Define the importer -PassmanImporter.randomData = { - info: { - name: 'Random data', - id: 'randomData', - description: 'Create\'s 50 random credentials for testing purposes.' - } -}; + PassmanImporter.randomData = { + info: { + name: 'Random data', + id: 'randomData', + description: 'Create\'s 50 random credentials for testing purposes.' + } + }; -PassmanImporter.randomData.readFile = function () { - return new C_Promise(function () { - var tags = - ['Social media', - 'Hosting', - 'Forums', - 'Webshops', - 'FTP', - 'SSH', - 'Banking', - 'Applications', - 'Server stuff', - 'mysql', - 'Wifi', - 'Games', - 'Certificate', - 'Serials' - ]; - var label; - var credential_list = []; - var _this = this; - var generateCredential = function (max, i, callback) { - if (jQuery) { - var url = OC.generateUrl('apps/passman/api/internal/generate_person'); - $.ajax({ - url: url, - dataType: 'json', - success: function (data) { - if(data) { - var _credential = PassmanImporter.newCredential(); - label = (Math.random() >= 0.5) ? data.domain : data.email_d + ' - ' + data.email_u; - _credential.label = label; - _credential.username = data.username; - _credential.password = data.password; - _credential.url = data.url; + PassmanImporter.randomData.readFile = function () { + return new C_Promise(function () { + var tags = + ['Social media', + 'Hosting', + 'Forums', + 'Webshops', + 'FTP', + 'SSH', + 'Banking', + 'Applications', + 'Server stuff', + 'mysql', + 'Wifi', + 'Games', + 'Certificate', + 'Serials' + ]; + var label; + var credential_list = []; + var _this = this; + var generateCredential = function (max, i, callback) { + if (jQuery) { + var url = OC.generateUrl('apps/passman/api/internal/generate_person'); + $.ajax({ + url: url, + dataType: 'json', + success: function (data) { + if(data) { + var _credential = PassmanImporter.newCredential(); + label = (Math.random() >= 0.5) ? data.domain : data.email_d + ' - ' + data.email_u; + _credential.label = label; + _credential.username = data.username; + _credential.password = data.password; + _credential.url = data.url; - var tag_amount = Math.floor(Math.random() * 5); - var ta = 0; - var _tags = []; - while (ta < tag_amount) { - var item = tags[Math.floor(Math.random() * tags.length)]; - if (_tags.indexOf(item) === -1) { - _tags.push(item); - ta++ - } - } - _credential.tags = _tags.map(function (item) { - if (item) { - return {text: item} + var tag_amount = Math.floor(Math.random() * 5); + var ta = 0; + var _tags = []; + while (ta < tag_amount) { + var item = tags[Math.floor(Math.random() * tags.length)]; + if (_tags.indexOf(item) === -1) { + _tags.push(item); + ta++ + } } + _credential.tags = _tags.map(function (item) { + if (item) { + return {text: item} + } - }).filter(function (item) { - return (item); - }); - credential_list.push(_credential); + }).filter(function (item) { + return (item); + }); + credential_list.push(_credential); - if (i < max) { - var progress = { - percent: i / max * 100, - loaded: i, - total: max - }; - _this.call_progress(progress); - generateCredential(max, i + 1, callback) + if (i < max) { + var progress = { + percent: i / max * 100, + loaded: i, + total: max + }; + _this.call_progress(progress); + generateCredential(max, i + 1, callback) + } else { + callback(credential_list) + } } else { - callback(credential_list) + generateCredential(max, i , callback) } - } else { - generateCredential(max, i , callback) } - } - }); - } - }; + }); + } + }; - generateCredential(50, 1, function (credential_list) { - _this.call_then(credential_list); + generateCredential(50, 1, function (credential_list) { + _this.call_then(credential_list); + }); }); - }); -}; + }; +})(window, $, PassmanImporter);
\ No newline at end of file diff --git a/js/importers/importer-zohocsv.js b/js/importers/importer-zohocsv.js index d677572a..9f0a53c2 100644 --- a/js/importers/importer-zohocsv.js +++ b/js/importers/importer-zohocsv.js @@ -1,40 +1,43 @@ // Importers should always start with this -if (!window['PassmanImporter']) { - var PassmanImporter = {} -} -// Define the importer -PassmanImporter.zohoCsv = { - info: { - name: 'ZOHO csv', - id: 'zohoCsv', - description: 'Create an csv export. Go to Tools -> Export secrets -> Select "General CSV" and click "Export Secrets"' - } -}; +var PassmanImporter = PassmanImporter || {}; -PassmanImporter.zohoCsv.readFile = function (file_data) { - return new C_Promise(function(){ - var parsed_csv = PassmanImporter.readCsv(file_data, false); - var credential_list = []; - for (var i = 0; i < parsed_csv.length; i++) { - var row = parsed_csv[i]; - var _credential = PassmanImporter.newCredential(); - _credential.label = row[0]; - _credential.username = row[3]; - _credential.password = row[4]; - _credential.url = row[1]; - _credential.description = row[2]; - if(_credential.label){ - credential_list.push(_credential); - } - - var progress = { - percent: i/parsed_csv.length*100, - loaded: i, - total: parsed_csv.length - }; +(function(window, $, PassmanImporter) { + 'use strict'; - this.call_progress(progress); + // Define the importer + PassmanImporter.zohoCsv = { + info: { + name: 'ZOHO csv', + id: 'zohoCsv', + description: 'Create an csv export. Go to Tools -> Export secrets -> Select "General CSV" and click "Export Secrets"' } - this.call_then(credential_list); - }) -};
\ No newline at end of file + }; + + PassmanImporter.zohoCsv.readFile = function (file_data) { + return new C_Promise(function(){ + var parsed_csv = PassmanImporter.readCsv(file_data, false); + var credential_list = []; + for (var i = 0; i < parsed_csv.length; i++) { + var row = parsed_csv[i]; + var _credential = PassmanImporter.newCredential(); + _credential.label = row[0]; + _credential.username = row[3]; + _credential.password = row[4]; + _credential.url = row[1]; + _credential.description = row[2]; + if(_credential.label){ + credential_list.push(_credential); + } + + var progress = { + percent: i/parsed_csv.length*100, + loaded: i, + total: parsed_csv.length + }; + + this.call_progress(progress); + } + this.call_then(credential_list); + }) + }; +})(window, $, PassmanImporter); |