From 5892f440e84d69223b0dc3455e8ef462c6464720 Mon Sep 17 00:00:00 2001 From: "Difrex(Denis Zheleztsov)" Date: Fri, 16 May 2014 18:47:38 +0400 Subject: [PATCH] Not working import --- GPG.pm | 25 +++++++++++++++++++++---- Password.pm | 34 +++++++++++++++++++++------------- Usage.pm | 1 + 3 files changed, 43 insertions(+), 17 deletions(-) diff --git a/GPG.pm b/GPG.pm index 88ecc5f..ce3286d 100644 --- a/GPG.pm +++ b/GPG.pm @@ -91,17 +91,17 @@ sub decrypt_db { } sub export { - my ($self, $file) = @_; + my ( $self, $file ) = @_; use Term::ANSIColor; - print "Password for " . colored("export\n", 'yellow'); + print "Password for " . colored( "export\n", 'yellow' ); # gpg --symmetric filename - my @enc_cmd = ('gpg', '--symmetric', "$file"); + my @enc_cmd = ( 'gpg', '--symmetric', "$file" ); system(@enc_cmd) == 0 or die "Cannot encrypt $file: $!\n"; # Remove unencrypted file - my @rm_cmd = ('rm', '-f', "$file"); + my @rm_cmd = ( 'rm', '-f', "$file" ); system(@rm_cmd) == 0 or die "Cannot remove file $file: $!\n"; my $export_file = $file . '.gpg'; @@ -109,4 +109,21 @@ sub export { return $export_file; } +sub import { + my ( $self, $file ) = @_; + + # Generate random file name + my @chars = ( "A" .. "Z", "a" .. "z" ); + my $string; + $string .= $chars[ rand @chars ] for 1 .. 10; + my $dec_file = "/tmp/pm." . $string; + + # Decrypt database + # gpg --output filepath --decrypt encfile + my @dec_cmd = ( 'gpg', '--output', $dec_file, '--decrypt', $file ); + system(@dec_cmd) == 0 or die "Cannot decrypt file $file: $!\n"; + + return $dec_file; +} + 1; diff --git a/Password.pm b/Password.pm index 102df30..e946e99 100644 --- a/Password.pm +++ b/Password.pm @@ -81,19 +81,6 @@ sub remove { return 0; } -sub export { - my ( $self, $filename ) = @_; - my $gpg = $self->{_gpg}; - - my $dec_db_file = $gpg->decrypt_db(); - my $export_enc = $gpg->export($dec_db_file); - - my @mv_cmd = ( 'mv', "$export_enc", "$filename" ); - system(@mv_cmd) == 0 or die "Cannot move $export_enc to $filename: $!\n"; - - return 0; -} - # Decrypt base and store new password sub save { my ( $self, $store ) = @_; @@ -134,6 +121,27 @@ sub save { return 0; } +sub export { + my ( $self, $filename ) = @_; + my $gpg = $self->{_gpg}; + + my $dec_db_file = $gpg->decrypt_db(); + my $export_enc = $gpg->export($dec_db_file); + + my @mv_cmd = ( 'mv', "$export_enc", "$filename" ); + system(@mv_cmd) == 0 or die "Cannot move $export_enc to $filename: $!\n"; + + return 0; +} + +sub import { + my ( $self, $file ) = @_; + my $gpg = $self->{_gpg}; + my $db_class = $self->{_db}; + + my $dec_file = $gpg->import($file); +} + # Generate password sub generate { my @chars = ( "A" .. "Z", "a" .. "z", 0 .. 9 ); diff --git a/Usage.pm b/Usage.pm index 130b968..48f7123 100644 --- a/Usage.pm +++ b/Usage.pm @@ -25,6 +25,7 @@ Simple password manager writed in Perl. -i password ID -o open link -x [filename] export + -I [filename] import -h show this help screen and exit -v show version info and exit