Merge branch 'remove' into testing
This commit is contained in:
commit
eb611a0f64
17
Database.pm
17
Database.pm
@ -44,19 +44,19 @@ sub mdo {
|
||||
|
||||
# Bad hack
|
||||
if ( $name eq 'all' ) {
|
||||
my $q = 'select name, resource, username from passwords';
|
||||
my $q = 'select id, name, resource, username from passwords';
|
||||
|
||||
my $sth = $dbh->prepare($q);
|
||||
my $rv = $sth->execute();
|
||||
|
||||
|
||||
|
||||
printf "%-11s %-11s %-11s\n", "NAME", "RESOURCE", "USERNAME";
|
||||
while ( my ( $name, $resource, $username )
|
||||
printf "%-11s %-11s %-11s %-11s\n", "ID", "NAME", "RESOURCE", "USERNAME";
|
||||
while ( my ( $id, $name, $resource, $username )
|
||||
= $sth->fetchrow_array() )
|
||||
{
|
||||
printf "%-11s %-11s %-11s\n",
|
||||
$name, $resource, "\t$username";
|
||||
printf "%-11s %-11s %-11s %-11s\n",
|
||||
$id, $name, $resource, $username;
|
||||
}
|
||||
# Remove unencrypted file
|
||||
my @rm_cmd = ( "rm", "-f", "$db_file" );
|
||||
@ -67,9 +67,10 @@ sub mdo {
|
||||
my $sth = $dbh->prepare($q);
|
||||
$sth->execute();
|
||||
|
||||
my ( $name, $resource, $password ) = $sth->fetchrow_array();
|
||||
my ( $id, $name, $resource, $password ) = $sth->fetchrow_array();
|
||||
|
||||
my $q_hash = {
|
||||
id => $id,
|
||||
name => $name,
|
||||
resource => $resource,
|
||||
password => $password,
|
||||
@ -121,8 +122,8 @@ sub create_base {
|
||||
my $dbh = DBI->connect( "dbi:SQLite:dbname=$first_sqlite", "", "" );
|
||||
print "Create database schema\n";
|
||||
my $q_table
|
||||
= "create table passwords(name VARCHAR(32), username VARCHAR(32),
|
||||
resource TEXT, password TEXT)";
|
||||
= "create table passwords(id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, name VARCHAR(32), username VARCHAR(32),
|
||||
resource TEXT, password TEXT, comment TEXT)";
|
||||
$dbh->do($q_table);
|
||||
|
||||
print "Encrypt database...\n";
|
||||
|
26
Password.pm
26
Password.pm
@ -59,6 +59,28 @@ sub show {
|
||||
return $q_hash;
|
||||
}
|
||||
|
||||
# Remove password
|
||||
sub remove {
|
||||
my ( $self, $store ) = @_;
|
||||
my $db_class = $self->{_db};
|
||||
my $gpg = $self->{_gpg};
|
||||
my $id = $store->{id};
|
||||
|
||||
# Decrypt database
|
||||
my $dec_db_file = $gpg->decrypt_db();
|
||||
my $q = "delete from passwords where id=$id";
|
||||
my $mdo_q = {
|
||||
file => $dec_db_file,
|
||||
query => $q,
|
||||
type => 'do',
|
||||
};
|
||||
|
||||
$db_class->mdo($mdo_q);
|
||||
$gpg->encrypt_db($dec_db_file);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
# Decrypt base and store new password
|
||||
sub save {
|
||||
my ( $self, $store ) = @_;
|
||||
@ -72,8 +94,8 @@ sub save {
|
||||
|
||||
# Username check
|
||||
my $username = '';
|
||||
if (defined($store->{username})) {
|
||||
$username = $store->{username}
|
||||
if ( defined( $store->{username} ) ) {
|
||||
$username = $store->{username};
|
||||
}
|
||||
|
||||
if ( $generate == 1 ) {
|
||||
|
19
pm.pl
19
pm.pl
@ -22,6 +22,7 @@ Simple password manager writed in Perl.
|
||||
if key not selected PM generate secure password
|
||||
and copy it to xclipboard
|
||||
-r remove password
|
||||
-i password ID
|
||||
-o open link
|
||||
-h show this help screen and exit
|
||||
-v show version info and exit
|
||||
@ -48,11 +49,11 @@ EOF
|
||||
}
|
||||
|
||||
sub init() {
|
||||
my $opt_string = 'swn:l:p:rhvou:';
|
||||
my $opt_string = 'swn:l:p:rhvou:i:';
|
||||
getopts("$opt_string") or usage();
|
||||
our (
|
||||
$opt_s, $opt_w, $opt_n, $opt_r, $opt_l,
|
||||
$opt_p, $opt_h, $opt_v, $opt_o, $opt_u
|
||||
$opt_s, $opt_w, $opt_n, $opt_r, $opt_l, $opt_p,
|
||||
$opt_h, $opt_v, $opt_o, $opt_u, $opt_i,
|
||||
);
|
||||
|
||||
print "Simple password manager writed in Perl.\nVersion: "
|
||||
@ -76,10 +77,11 @@ my $copy = ClipPass->new();
|
||||
# It's really ugly code. Sorry :(
|
||||
if ( defined($opt_s) and defined($opt_n) and !defined($opt_o) ) {
|
||||
|
||||
my $get_h = $pass->show($opt_n, $opt_u);
|
||||
my $get_h = $pass->show( $opt_n, $opt_u );
|
||||
my $get_pass = $get_h->{password};
|
||||
|
||||
$copy->copy($get_pass);
|
||||
|
||||
# TEST
|
||||
use Term::ANSIColor;
|
||||
print color 'green';
|
||||
@ -92,7 +94,7 @@ if ( defined($opt_s) and defined($opt_n) and !defined($opt_o) ) {
|
||||
}
|
||||
elsif ( defined($opt_s) and defined($opt_n) and defined($opt_o) ) {
|
||||
|
||||
my $get_h = $pass->show($opt_n, $opt_u);
|
||||
my $get_h = $pass->show( $opt_n, $opt_u );
|
||||
$copy->copy( $get_h->{password} );
|
||||
|
||||
# Open resource.
|
||||
@ -101,6 +103,13 @@ elsif ( defined($opt_s) and defined($opt_n) and defined($opt_o) ) {
|
||||
|
||||
print "Password copied to clipboard. Trying to open uri.\n";
|
||||
}
|
||||
# Remove string from db
|
||||
elsif ( defined($opt_r) and defined($opt_i) ) {
|
||||
|
||||
my $store_h = { id => $opt_i, };
|
||||
|
||||
$pass->remove($store_h) == 0 or die "Oops! 105: pm.pl. $!\n";
|
||||
}
|
||||
elsif ( defined($opt_w)
|
||||
and defined($opt_n)
|
||||
and defined($opt_l)
|
||||
|
Loading…
Reference in New Issue
Block a user