Merge branch 'master' of github.com:Difrex/PM

This commit is contained in:
Difrex(Denis Zheleztsov) 2014-05-12 10:12:06 +04:00
commit 28e0231ab3
3 changed files with 46 additions and 13 deletions

22
GPG.pm
View File

@ -10,7 +10,10 @@ sub new {
my $home = $ENV{HOME};
my $db = $home . "/.PM/db.sqlite";
my $self = { _db => $db, };
my $self = {
_db => $db,
_home => $home,
};
bless $self, $class;
return $self;
@ -26,12 +29,29 @@ sub encrypt_db {
@rm_db = ( "rm", "-f", "$db" );
system(@rm_db) == 0 or die "Cannot remove old database: $!\n";
# Keys selection.
my @enc_cmd;
my $recipient;
if ( -e $self->{_home} . "/.PM/.key" ) {
open my $key_f, "<" , $self->{_home} . "/.PM/.key"
or die "Cannot open file: $!\n";
while ( <$key_f> ) {
$recipient = $_;
}
@enc_cmd = (
"gpg", "--output", "$db",
"-a", "--recipient", "$recipient",
"--encrypt", "$file",
);
}
else {
# gpg --output test.gpg --encrypt test -a --default-recipient-self
@enc_cmd = (
"gpg", "--output", "$db",
"-a", "--default-recipient-self",
"--encrypt", "$file",
);
}
system(@enc_cmd) == 0
or die "Cannot encrypt!\nDecrypted file: $file\nTraceback: $!\n";

View File

@ -32,9 +32,16 @@ Set this key(or another of cource) for default:
vim ~/.gnupg/gpg.conf
# find string and uncomment or add it
default-key your@mail-address-key.org
default-key key_email@example.com
:wq
You can use not default key:
# Create file with key email
cat > ~/.PM/.key << EOF
key_email@example.com
EOF
First run:
$ ./pm.pl
@ -62,6 +69,6 @@ Show help screen:
# TODO
* Import/Export with simple(only password) encryption
* Password lenght
* Store decrypted DB into RAM not in /tmp/
* Different keys selection

12
pm.pl
View File

@ -80,9 +80,15 @@ if ( defined($opt_s) and defined($opt_n) and !defined($opt_o) ) {
my $get_pass = $get_h->{password};
$copy->copy($get_pass);
print "Password copied to xclipboard.\nURI is "
. $get_h->{resource} . "\n";
# TEST
use Term::ANSIColor;
print color 'green';
print "Password copied to xclipboard.";
print color 'reset';
print "\nURI is ";
print color 'bold blue';
print $get_h->{resource} . "\n";
print color 'reset';
}
elsif ( defined($opt_s) and defined($opt_n) and defined($opt_o) ) {