initial support for export
This commit is contained in:
parent
c8b9949bdf
commit
52c4bd5e0a
19
GPG.pm
19
GPG.pm
@ -90,4 +90,23 @@ sub decrypt_db {
|
||||
return $file;
|
||||
}
|
||||
|
||||
sub export {
|
||||
my ($self, $file) = @_;
|
||||
|
||||
use Term::ANSIColor;
|
||||
print "Password for " . colored("export\n", 'yellow');
|
||||
|
||||
# gpg --symmetric filename
|
||||
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");
|
||||
system(@rm_cmd) == 0 or die "Cannot remove file $file: $!\n";
|
||||
|
||||
my $export_file = $file . '.gpg';
|
||||
|
||||
return $export_file;
|
||||
}
|
||||
|
||||
1;
|
||||
|
16
Password.pm
16
Password.pm
@ -81,6 +81,19 @@ 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 ) = @_;
|
||||
@ -105,7 +118,8 @@ sub save {
|
||||
|
||||
# Decrypt database
|
||||
my $dec_db_file = $gpg->decrypt_db();
|
||||
my $q = "insert into passwords(name, resource, password, username, comment)
|
||||
my $q
|
||||
= "insert into passwords(name, resource, password, username, comment)
|
||||
values('$name', '$resource', '$password', '$username', '$comment')";
|
||||
my $mdo_q = {
|
||||
file => $dec_db_file,
|
||||
|
1
Usage.pm
1
Usage.pm
@ -24,6 +24,7 @@ Simple password manager writed in Perl.
|
||||
-r remove password
|
||||
-i password ID
|
||||
-o open link
|
||||
-x [filename] export
|
||||
-h show this help screen and exit
|
||||
-v show version info and exit
|
||||
|
||||
|
11
pm.pl
11
pm.pl
@ -15,11 +15,11 @@ our $VERSION = '0.0.1-beta1';
|
||||
my $usage = Usage->new();
|
||||
|
||||
sub init() {
|
||||
my $opt_string = 'swn:l:p:rhvou:i:c:';
|
||||
my $opt_string = 'swn:l:p:rhvou:i:c:x:';
|
||||
getopts("$opt_string") or $usage->show();
|
||||
our (
|
||||
$opt_s, $opt_w, $opt_n, $opt_r, $opt_l, $opt_p,
|
||||
$opt_h, $opt_v, $opt_o, $opt_u, $opt_i, $opt_c,
|
||||
$opt_s, $opt_w, $opt_n, $opt_r, $opt_l, $opt_p, $opt_h,
|
||||
$opt_v, $opt_o, $opt_u, $opt_i, $opt_c, $opt_x,
|
||||
);
|
||||
|
||||
print "Simple password manager writed in Perl.\nVersion: "
|
||||
@ -130,6 +130,11 @@ elsif ( defined($opt_w)
|
||||
print "Password was stored into DB!\n";
|
||||
print color 'reset';
|
||||
}
|
||||
# Export
|
||||
elsif ( defined($opt_x) ) {
|
||||
$pass->export($opt_x);
|
||||
print colored("Dabase stored in $opt_x\n", 'green');
|
||||
}
|
||||
else {
|
||||
$usage->show();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user