diff --git a/GPG.pm b/GPG.pm index 88ecc5f..fd59043 100644 --- a/GPG.pm +++ b/GPG.pm @@ -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; } -1; +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; \ No newline at end of file diff --git a/Password.pm b/Password.pm index 1e8e36d..7fe42e1 100644 --- a/Password.pm +++ b/Password.pm @@ -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) { diff --git a/README.md b/README.md index 7db6a5a..c59c22c 100644 --- a/README.md +++ b/README.md @@ -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/ +* Store decrypted DB into RAM not in /tmp/ \ No newline at end of file diff --git a/Usage.pm b/Usage.pm index 616336b..1203192 100644 --- a/Usage.pm +++ b/Usage.pm @@ -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 diff --git a/pm.pl b/pm.pl index 3753b44..df763ed 100755 --- a/pm.pl +++ b/pm.pl @@ -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(); -} +} \ No newline at end of file