2016-10-19 23:44:19 +08:00
/ * *
* Nextcloud - passman
*
* @ copyright Copyright ( c ) 2016 , Sander Brand ( brantje @ gmail . com )
* @ copyright Copyright ( c ) 2016 , Marcos Zuriaga Miguel ( wolfi @ wolfi . es )
* @ license GNU AGPL version 3 or any later version
*
* This program is free software : you can redistribute it and / or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation , either version 3 of the
* License , or ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU Affero General Public License for more details .
*
* You should have received a copy of the GNU Affero General Public License
* along with this program . If not , see < http : //www.gnu.org/licenses/>.
*
* /
2016-09-25 06:01:23 +08:00
// Importers should always start with this
2016-12-31 20:29:37 +08:00
/** global: PassmanImporter */
2016-10-15 23:05:25 +08:00
var PassmanImporter = PassmanImporter || { } ;
2017-01-07 01:40:03 +08:00
( function ( window , $ , PassmanImporter ) {
2016-10-15 23:05:25 +08:00
'use strict' ;
// Define the importer
PassmanImporter . keepassCsv = {
info : {
name : 'KeePass csv' ,
id : 'keepassCsv' ,
2019-06-15 02:31:44 +08:00
exportSteps : [ 'If using Keepass V1: Create an csv export with the following options enabled: http://i.imgur.com/CaeTA4d.png' , 'With Keepass V2 or Keepass XC no configuration is needed' ]
2016-10-15 23:05:25 +08:00
}
} ;
2016-09-25 06:01:23 +08:00
2016-10-15 23:05:25 +08:00
PassmanImporter . keepassCsv . readFile = function ( file _data ) {
2016-12-31 20:29:37 +08:00
/** global: C_Promise */
2017-01-07 01:40:03 +08:00
var p = new C _Promise ( function ( ) {
2016-10-15 23:05:25 +08:00
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 ;
2020-11-20 06:14:59 +08:00
_credential . description = row . comments ;
2016-10-15 23:05:25 +08:00
if ( row . hasOwnProperty ( 'expires' ) ) {
2017-01-07 01:40:03 +08:00
row . expires = row . expires . replace ( '"' , '' ) ;
2016-10-15 23:05:25 +08:00
_credential . expire _time = new Date ( row . expires ) . getTime ( ) / 1000 ;
2016-09-26 23:05:47 +08:00
}
2017-01-07 01:40:03 +08:00
var tags = ( row . group ) ? [ { text : row . group } ] : [ ] ;
2016-10-15 23:05:25 +08:00
if ( row . hasOwnProperty ( 'group_tree' ) ) {
var exploded _tree = row . group _tree . split ( '\\\\' ) ;
for ( var t = 0 ; t < exploded _tree . length ; t ++ ) {
2017-01-07 01:40:03 +08:00
if ( exploded _tree [ t ] . trim ( ) . length > 0 ) {
tags . push ( { text : exploded _tree [ t ] . trim ( ) } ) ;
}
2016-10-15 23:05:25 +08:00
}
}
_credential . tags = tags ;
credential _list . push ( _credential ) ;
2016-09-27 00:23:35 +08:00
2016-10-15 23:05:25 +08:00
var progress = {
2017-01-07 01:40:03 +08:00
percent : i / parsed _csv . length * 100 ,
2016-10-15 23:05:25 +08:00
loaded : i ,
total : parsed _csv . length
} ;
2016-09-27 00:23:35 +08:00
2016-10-15 23:05:25 +08:00
this . call _progress ( progress ) ;
}
this . call _then ( credential _list ) ;
} ) ;
return p ;
} ;
} ) ( window , $ , PassmanImporter ) ;