Merge pull request #1 from vit1-irk/master

Небольшие изменения
This commit is contained in:
Denis 2016-05-04 16:14:37 +04:00
commit 1f2fdfa3ec
6 changed files with 47 additions and 9 deletions

View File

@ -1,3 +1,7 @@
Denis a.k.a Difrex Zheleztsov
mailto://difrex.punk@gmail.com/
copyleft 2014
Viktor (vit01, vit1-irk) Fedenyov
mailto://me@ii-net.tk
copyleft 2016

16
GPG.pm
View File

@ -77,7 +77,7 @@ sub decrypt_db {
my @chars = ( "A" .. "Z", "a" .. "z" );
my $string;
$string .= $chars[ rand @chars ] for 1 .. 10;
my $file = '/tmp/' . 'pm.' . $string;
my $file = '/dev/shm/' . 'pm.' . $string;
# gpg --output /tmp/decryptfile --decrypt $db
@dec_cmd = ( "$gpg", "--output", "$file", "--decrypt", "$db" );
@ -109,4 +109,18 @@ sub export {
return $export_file;
}
sub import_db {
my ($self, $file) = @_;
my @chars = ( "A" .. "Z", "a" .. "z" );
my $string;
$string .= $chars[ rand @chars ] for 1 .. 10;
my $tmpfile = '/dev/shm/' . 'pm.' . $string;
system("gpg --output $tmpfile --decrypt $file") == 0 or die "Cannot decrypt $file: $!\n";
my $encrypted = $self->encrypt_db($tmpfile);
return $encrypted;
}
1;

View File

@ -110,6 +110,13 @@ sub export {
return 0;
}
sub import_db {
my ( $self, $filename ) = @_;
my $gpg = $self->{_gpg};
return $gpg->import_db($filename);
}
# Decrypt base and store new password
sub save {
my ( $self, $store ) = @_;
@ -153,10 +160,14 @@ sub save {
# Generate password
sub generate {
my ($self, $length) = @_;
my $value;
# Defaults
my $length = 16;
if (!$length) {
$length = 16;
}
my $digest;
for (1..32) {

View File

@ -84,6 +84,4 @@ Show help screen:
# TODO
* Import/Export with simple(only password) encryption
* Password lenght
* Store decrypted DB into RAM not in /tmp/

View File

@ -21,11 +21,13 @@ Simple password manager writed in Perl.
-c comment
-p [Password] password
if key not selected PM generate secure password
-e [number] (with length [number] if mentioned)
and copy it to xclipboard
-r remove password
-i password ID
-o open link
-x [filename] export
-b [filename] import database
-h show this help screen and exit
-v show version info and exit

13
pm.pl
View File

@ -15,11 +15,12 @@ our $VERSION = '0.0.1';
my $usage = Usage->new();
sub init() {
my $opt_string = 'swn:l:p:rhvou:i:c:x:g:';
my $opt_string = 'swn:l:p:rhvou:i:c:x:g:b:e:';
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_x, $opt_g,
$opt_b, $opt_e
);
print "Simple password manager writed in Perl.\nVersion: "
@ -107,7 +108,11 @@ elsif ( defined($opt_w)
# Generate password and store it into DB
$opt_g = '' if !($opt_g);
$opt_p = $pass->generate();
if ( defined($opt_e) ) {
$pass_length=$opt_e;
}
$opt_p = $pass->generate($pass_length);
my $store_h = {
name => $opt_n,
@ -149,6 +154,10 @@ elsif ( defined($opt_x) ) {
$pass->export($opt_x);
print colored( "Dabase stored in $opt_x\n", 'green' );
}
elsif ( defined($opt_b) ) {
$pass->import_db($opt_b);
print colored( "Database imported from $opt_b\n", 'green' );
}
else {
$usage->show();
}