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
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 $rv = $sth->execute();
use Term::ANSIColor;
printf "%-11s %-11s %-11s %-11s\n",
printf "%-11s %-11s %-11s %-11s %-11s\n",
colored( "ID", 'white' ),
colored( "NAME", 'magenta' ),
colored( "RESOURCE", 'blue' ),
colored( "USERNAME", 'green' );
print "=========================\n";
while ( my ( $id, $name, $resource, $username )
colored( "USERNAME", 'green' ),
colored( "COMMENT", 'yellow' );
print "=================================\n";
while ( my ( $id, $name, $resource, $username, $comment )
= $sth->fetchrow_array() )
{
printf "%-11s %-11s %-11s %-11s\n",
if ( !defined($comment) ) {
$comment = '';
}
printf "%-11s %-11s %-11s %-11s %-11s\n",
colored( $id, 'white' ),
colored( $name, 'magenta' ),
colored( $resource, 'blue' ),
colored( $username, 'green' );
colored( $username, 'green' ),
colored( $comment, 'yellow' );
}
# Remove unencrypted file

View File

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

View File

@ -17,6 +17,7 @@ Simple password manager writed in Perl.
-w store new password
-l [Link] link to resource
-u username
-c comment
-p [Password] password
if key not selected PM generate secure password
and copy it to xclipboard
@ -40,7 +41,7 @@ Examples:
\tPassword copied to clipboard. Trying to open uri.
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!
Remove password:

9
pm.pl
View File

@ -15,11 +15,11 @@ our $VERSION = '0.0.1-beta1';
my $usage = Usage->new();
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();
our (
$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: "
@ -73,6 +73,7 @@ elsif ( defined($opt_s) and defined($opt_n) and defined($opt_o) ) {
print $get_h->{resource} . "\n";
print color 'reset';
}
# Remove string from db
elsif ( defined($opt_r) and defined($opt_i) ) {
@ -98,10 +99,11 @@ elsif ( defined($opt_w)
resource => $opt_l,
password => $opt_p,
username => $opt_u,
comment => $opt_c,
};
$pass->save($store_h) == 0 or die "Oops! 105: pm.pl. $!\n";
$copy->copy( $opt_p );
$copy->copy($opt_p);
print color 'green';
print "Password was stored into DB!\n";
print color 'reset';
@ -120,6 +122,7 @@ elsif ( defined($opt_w)
password => $opt_p,
gen => 0,
username => $opt_u,
comment => $opt_c,
};
$pass->save($store_h) == 0 or die "Oops! 122: pm.pl. $!\n";