#!/usr/bin/perl -w #### # Author: Daniel E. Markle # Date: Sun Jan 28 19:44:29 EST 2007 @72 /Internet Time/ # # Description: # This script converts ZSafe plain text save files to Password Safe 2.0 files # using the Linux/Unix pwsafe utility (http://pwsafe.sf.net/). # # Usage: zsafe_txt_to_pwsafe #### use strict; my $ORIGINAL_ENTRIES = 0; my $SUCCESSFUL_ENTRIES = 0; my $SITE_MOD_ENTRIES = 0; my $FAILED_ENTRIES = 0; sub rmquote { my $data = shift(@_); $data =~ s/"//g; return $data; } # generates and runs pwsafe command for addition sub pwsafe_add { my ($group, $site, $username, $password, $notes, $pwsafepassword, $pwfile) = @_; my $data = "$pwsafepassword\n$site\n$group\n$username\n$password\n$password\n$notes\n\n"; open(ZSAFECMD,"| pwsafe -a -f $pwfile --dbversion=2 &> /dev/null"); print ZSAFECMD $data; if ( close(ZSAFECMD) == 0 ) { print "*** pwsafe does not allow duplicate sites within a group, trying with site-username\n"; $data = "$pwsafepassword\n$site-$username\n$group\n$username\n$password\n$password\n$notes\n\n"; open(ZSAFECMD,"| pwsafe -a -f $pwfile --dbversion=2 &> /dev/null"); print ZSAFECMD $data; if ( close(ZSAFECMD) == 0 ) { print "*** Failed entry: $group $site $username\n"; $FAILED_ENTRIES++; } else { print "*** site-username suceeded\n"; $SITE_MOD_ENTRIES++; } } else { $SUCCESSFUL_ENTRIES++; } } scalar @ARGV == 3 or die "Usage: zsafe_txt_to_pwsafe "; open(ZSAFETEXT,'<',$ARGV[0]) || die "Can't open " . $ARGV[0]; my $pwfile = $ARGV[1]; my $password = $ARGV[2]; if ( -e $pwfile ) { die "$pwfile already exists! Cowardly failing to nuke it"; } `echo -e \"$password\n$password\" | pwsafe -f $pwfile --dbversion=2 --createdb &> /dev/null`; while () { chop; my @line = split /";"/; pwsafe_add( rmquote($line[0]), rmquote($line[1]), rmquote($line[2]), rmquote($line[3]), rmquote($line[4]), rmquote($password), rmquote($pwfile) ); $ORIGINAL_ENTRIES++; } close(ZSAFETEXT); print "---- Summary ----------------------------------\n"; print 'Original Entries from Zsafe: ' . $ORIGINAL_ENTRIES . "\n"; print 'Imported from Zsafe without problems: ' . $SUCCESSFUL_ENTRIES . "\n"; print 'Imported from Zsafe with modified site: ' . $SITE_MOD_ENTRIES . "\n"; print 'Failed to import from Zsafe: ' . $FAILED_ENTRIES . "\n";