Comments support

This commit is contained in:
Difrex(Denis Zheleztsov) 2014-05-12 17:16:10 +04:00
parent f75822471b
commit 844b817b14
4 changed files with 31 additions and 15 deletions

View File

@ -44,26 +44,32 @@ sub mdo {
# Bad hack # Bad hack
if ( $name eq 'all' ) { if ( $name eq 'all' ) {
my $q = 'select id, name, resource, username from passwords'; my $q
= 'select id, name, resource, username, comment from passwords';
my $sth = $dbh->prepare($q); my $sth = $dbh->prepare($q);
my $rv = $sth->execute(); my $rv = $sth->execute();
use Term::ANSIColor; use Term::ANSIColor;
printf "%-11s %-11s %-11s %-11s\n", printf "%-11s %-11s %-11s %-11s %-11s\n",
colored( "ID", 'white' ), colored( "ID", 'white' ),
colored( "NAME", 'magenta' ), colored( "NAME", 'magenta' ),
colored( "RESOURCE", 'blue' ), colored( "RESOURCE", 'blue' ),
colored( "USERNAME", 'green' ); colored( "USERNAME", 'green' ),
print "=========================\n"; colored( "COMMENT", 'yellow' );
while ( my ( $id, $name, $resource, $username ) print "=================================\n";
while ( my ( $id, $name, $resource, $username, $comment )
= $sth->fetchrow_array() ) = $sth->fetchrow_array() )
{ {
printf "%-11s %-11s %-11s %-11s\n", if ( !defined($comment) ) {
$comment = '';
}
printf "%-11s %-11s %-11s %-11s %-11s\n",
colored( $id, 'white' ), colored( $id, 'white' ),
colored( $name, 'magenta' ), colored( $name, 'magenta' ),
colored( $resource, 'blue' ), colored( $resource, 'blue' ),
colored( $username, 'green' ); colored( $username, 'green' ),
colored( $comment, 'yellow' );
} }
# Remove unencrypted file # Remove unencrypted file

View File

@ -91,6 +91,12 @@ sub save {
my $resource = $store->{resource}; my $resource = $store->{resource};
my $password = $store->{password}; my $password = $store->{password};
# Comment check
my $comment = '';
if ( defined( $store->{comment} ) ) {
$comment = $store->{comment};
}
# Username check # Username check
my $username = ''; my $username = '';
if ( defined( $store->{username} ) ) { if ( defined( $store->{username} ) ) {
@ -99,8 +105,8 @@ sub save {
# Decrypt database # Decrypt database
my $dec_db_file = $gpg->decrypt_db(); my $dec_db_file = $gpg->decrypt_db();
my $q = "insert into passwords(name, resource, password, username) my $q = "insert into passwords(name, resource, password, username, comment)
values('$name', '$resource', '$password', '$username')"; values('$name', '$resource', '$password', '$username', '$comment')";
my $mdo_q = { my $mdo_q = {
file => $dec_db_file, file => $dec_db_file,
name => $name, name => $name,

View File

@ -17,6 +17,7 @@ Simple password manager writed in Perl.
-w store new password -w store new password
-l [Link] link to resource -l [Link] link to resource
-u username -u username
-c comment
-p [Password] password -p [Password] password
if key not selected PM generate secure password if key not selected PM generate secure password
and copy it to xclipboard and copy it to xclipboard
@ -40,7 +41,7 @@ Examples:
\tPassword copied to clipboard. Trying to open uri. \tPassword copied to clipboard. Trying to open uri.
Store new password: Store new password:
\tpm.pl -w -n PRON -l http://superpronsite.com/ -p my_secret_password \tpm.pl -w -n PRON -l http://superpronsite.com/ -p my_secret_password -c 'Most viewed site'
\tPassword for resource PRON is stored into DB! \tPassword for resource PRON is stored into DB!
Remove password: Remove password:

9
pm.pl
View File

@ -15,11 +15,11 @@ our $VERSION = '0.0.1-beta1';
my $usage = Usage->new(); my $usage = Usage->new();
sub init() { sub init() {
my $opt_string = 'swn:l:p:rhvou:i:'; my $opt_string = 'swn:l:p:rhvou:i:c:';
getopts("$opt_string") or $usage->show(); getopts("$opt_string") or $usage->show();
our ( our (
$opt_s, $opt_w, $opt_n, $opt_r, $opt_l, $opt_p, $opt_s, $opt_w, $opt_n, $opt_r, $opt_l, $opt_p,
$opt_h, $opt_v, $opt_o, $opt_u, $opt_i, $opt_h, $opt_v, $opt_o, $opt_u, $opt_i, $opt_c,
); );
print "Simple password manager writed in Perl.\nVersion: " print "Simple password manager writed in Perl.\nVersion: "
@ -73,6 +73,7 @@ elsif ( defined($opt_s) and defined($opt_n) and defined($opt_o) ) {
print $get_h->{resource} . "\n"; print $get_h->{resource} . "\n";
print color 'reset'; print color 'reset';
} }
# Remove string from db # Remove string from db
elsif ( defined($opt_r) and defined($opt_i) ) { elsif ( defined($opt_r) and defined($opt_i) ) {
@ -98,10 +99,11 @@ elsif ( defined($opt_w)
resource => $opt_l, resource => $opt_l,
password => $opt_p, password => $opt_p,
username => $opt_u, username => $opt_u,
comment => $opt_c,
}; };
$pass->save($store_h) == 0 or die "Oops! 105: pm.pl. $!\n"; $pass->save($store_h) == 0 or die "Oops! 105: pm.pl. $!\n";
$copy->copy( $opt_p ); $copy->copy($opt_p);
print color 'green'; print color 'green';
print "Password was stored into DB!\n"; print "Password was stored into DB!\n";
print color 'reset'; print color 'reset';
@ -120,6 +122,7 @@ elsif ( defined($opt_w)
password => $opt_p, password => $opt_p,
gen => 0, gen => 0,
username => $opt_u, username => $opt_u,
comment => $opt_c,
}; };
$pass->save($store_h) == 0 or die "Oops! 122: pm.pl. $!\n"; $pass->save($store_h) == 0 or die "Oops! 122: pm.pl. $!\n";