Query proccessing mechanism writed
This commit is contained in:
parent
e4de44a9b4
commit
89920df709
35
Database.pm
35
Database.pm
@ -7,7 +7,7 @@ sub new {
|
||||
my $class = shift;
|
||||
|
||||
# Get home dir
|
||||
my $home = $ENV->{HOME};
|
||||
my $home = $ENV{HOME};
|
||||
|
||||
my $gpg = GPG->new($home);
|
||||
|
||||
@ -27,9 +27,38 @@ sub connect {
|
||||
return $dbh;
|
||||
}
|
||||
|
||||
# Query proccessing mechanism
|
||||
sub mdo {
|
||||
my ( $self, $query, $type, $file ) = @_;
|
||||
my $dbh = Database->connect();
|
||||
my ( $self, $query ) = @_;
|
||||
my $db_file = $query->{file};
|
||||
my $q = $query->{query};
|
||||
my $name = $query->{name};
|
||||
my $type = $query->{type};
|
||||
|
||||
my $dbh = Database->connect($db_file);
|
||||
|
||||
# Select
|
||||
if ( $type eq 'select' ) {
|
||||
my $sth = $dbh->prepare($q);
|
||||
$sth->execute();
|
||||
my ( $name, $resource, $password ) = $sth->fetchrow_array();
|
||||
|
||||
my $q_hash = {
|
||||
name => $name,
|
||||
resource => $resource,
|
||||
password => $password,
|
||||
};
|
||||
return $q_hash;
|
||||
}
|
||||
elsif ( $type eq 'do' ) {
|
||||
$dbh->do($q);
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
print STDERR "Something went wrong! $!\n";
|
||||
return 1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
# Create config dirrectory and DB if not exist
|
||||
|
32
Password.pm
32
Password.pm
@ -5,6 +5,7 @@ use warnings;
|
||||
use utf8;
|
||||
|
||||
use Database;
|
||||
use GPG;
|
||||
|
||||
use PasswordSave;
|
||||
use PasswordShow;
|
||||
@ -13,12 +14,14 @@ sub new {
|
||||
my $class = shift;
|
||||
|
||||
my $db = Database->new();
|
||||
my $gpg = GPG->new( $ENV{HOME} );
|
||||
|
||||
my $p_save = PasswordSave->new();
|
||||
my $p_show = PasswordShow->new();
|
||||
|
||||
my $self = {
|
||||
_db => $db,
|
||||
_gpg => $gpg,
|
||||
_p_save => $p_save,
|
||||
_p_show => $p_show,
|
||||
};
|
||||
@ -27,10 +30,37 @@ sub new {
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub show {
|
||||
my ( $self, $name ) = @_;
|
||||
my $db_class = $self->{_db};
|
||||
my $gpg = $self->{_gpg};
|
||||
|
||||
# Decrypt db
|
||||
my $dec_db_file = $gpg->decrypt_db();
|
||||
|
||||
# Query
|
||||
my $query_string
|
||||
= "select name, resource, password from passwords where name='$name'";
|
||||
|
||||
my $mdo_q = {
|
||||
file => $dec_db_file,
|
||||
query => $query_string,
|
||||
name => $name,
|
||||
type => 'select',
|
||||
};
|
||||
my $q_hash = $db_class->mdo($mdo_q);
|
||||
|
||||
# Remove unencrypted file
|
||||
@rm_cmd = ( "rm", "$dec_db_file" );
|
||||
system(@rm_cmd) == 0 or die "Cannot remove unencrypted database! $!\n";
|
||||
|
||||
return $q_hash;
|
||||
}
|
||||
|
||||
# Check configuration. If it doesn't exist create it.
|
||||
sub check_config {
|
||||
my ($self) = @_;
|
||||
if ( -e $ENV->{HOME} . "/.PM/db.sqlite" ) {
|
||||
if ( -e $ENV{HOME} . "/.PM/db.sqlite" ) {
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
|
@ -2,3 +2,9 @@ PM
|
||||
==
|
||||
|
||||
Simple password manager writed in perl.
|
||||
|
||||
TODO
|
||||
====
|
||||
|
||||
* Store decrypted DB into RAM not in /tmp/
|
||||
* Different keys selection
|
Loading…
Reference in New Issue
Block a user