Jump to content
Sign in to follow this  
0rAX0

CVS export is an unholy mess :(

Recommended Posts

Hi,

I tried to export my password to CVS and it produced the most messy file it can, notes mixed in with usernames, usernames mixed in with urls ... etc. It's practically unusable unless I sit and fix everything manually! 

  • Thanks 1

Share this post


Link to post
Share on other sites

I have been using Enpass on Android and Linux without issue. Because my old phone is having issues with Google Play Services I have installed an AOSP ROM which means Enpass just crashes on start. I thought I would use Keepassx on the phone but holy crap the CSV coming out of Enpass is unusable. It seems the extra fields trip up the export and would need so much editing it is not worth it. 

So I sit with Enpass and Keepassx on the desktop copying and pasting fields like the old days. 

Any idea when this could get looked at?

This Perl script can translate the export into something that another manager (KeepassX) can import.

 

#!/usr/bin/perl
use strict;

# Usage enpass_csv_clean.pl Documents/Exports/Enpass_2018-11-16_12-54-46.csv 
# File will be generated in the same directory but with CLEAN added into the name
# Please then import into another application and delete the unprotected files!
# This file must be in your $PATH

my $infile = @ARGV[0];

unless ($infile) {
	print "Cannot find file, exiting\n";
	exit;
}

unless (lc $infile =~ "\.csv") {
	print "Not a CSV file, exiting\n";
	exit;
}

my $outfile = $infile;
$outfile =~ s/.csv/CLEAN.csv/;    
our @csvfile = ();
open( FILE, "<$infile" ) || die("Unable to open $infile $!");
flock( $infile, "1" );
chomp( @csvfile = <FILE> );
close(FILE);
    
my @title = ();
my @username = ();
my @password = ();
my @email = ();
my @url = ();
our $count = 0;

foreach my $line (@csvfile) {
	$line =~ s/^.(.*).$/$1/;
	$line =~ s/","/|/g;
	
	
	my @values = split /\|/, $line;
	
	$title[$count] = $values[0];
	
	if    (lc $values[1] eq "username") { $username[$count] = $values[2]; }
	elsif (lc $values[3] eq "username") { $username[$count] = $values[4]; }
	elsif (lc $values[5] eq "username") { $username[$count] = $values[6]; }
	elsif (lc $values[7] eq "username") { $username[$count] = $values[8]; }
	
	if    (lc $values[1] eq "email") { $email[$count] = $values[2]; }
	elsif (lc $values[3] eq "email") { $email[$count] = $values[4]; }
	elsif (lc $values[5] eq "email") { $email[$count] = $values[5]; }
	elsif (lc $values[7] eq "email") { $email[$count] = $values[7]; }
	
	if    (lc $values[1] eq "password") { $password[$count] = $values[2]; }
	elsif (lc $values[3] eq "password") { $password[$count] = $values[4]; }
	elsif (lc $values[5] eq "password") { $password[$count] = $values[6]; }
	elsif (lc $values[7] eq "password") { $password[$count] = $values[8]; }
	
	if    (lc $values[1] eq "url") { $url[$count] = $values[2]; }
	elsif (lc $values[3] eq "url") { $url[$count] = $values[4]; }
	elsif (lc $values[5] eq "url") { $url[$count] = $values[6]; }
	elsif (lc $values[7] eq "url") { $url[$count] = $values[8]; }
	
	$count++;
	}

my $total = $count;

$count = 0;
my $success = 0;

open( FILE, ">$outfile" )
      || die "Cannot write to $outfile";
    
    print FILE "\"Title\",\"Username\",\"Password\",\"Email\",\"URL\"\n";

while ($count <= $total) {
	my $id = 0;
	if ($username[$count] ne "" || $email[$count] ne "") { $id = 1; }
	if ($title[$count] ne "" && $id == 1 && $password[$count] ne "") {
	print FILE "\"$title[$count]\",\"$username[$count]\",\"$password[$count]\",\"$email[$count]\",\"$url[$count]\"\n";
	$success++;
}
	$count++;
	}
close(FILE);

print "$success entries copied to $outfile\n";

 

Edited by SimonJ
Script added

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×