Start working on GPG module
This commit is contained in:
parent
2423a6d942
commit
dcb70474e3
22
Database.pm
22
Database.pm
@ -9,8 +9,11 @@ sub new {
|
|||||||
# Get home dir
|
# Get home dir
|
||||||
my $home = $ENV->{HOME};
|
my $home = $ENV->{HOME};
|
||||||
|
|
||||||
|
my $gpg = GPG->new();
|
||||||
|
|
||||||
my $self = {
|
my $self = {
|
||||||
_home => $home,
|
_home => $home,
|
||||||
|
_gpg => $gpg,
|
||||||
};
|
};
|
||||||
|
|
||||||
bless $self, $class;
|
bless $self, $class;
|
||||||
@ -22,35 +25,38 @@ sub connect {
|
|||||||
my $home = $self->{_home};
|
my $home = $self->{_home};
|
||||||
my $db_file = $home . "/.PM/db.sqlite";
|
my $db_file = $home . "/.PM/db.sqlite";
|
||||||
|
|
||||||
my $dbh = DBI->connect("dbi:SQLite:dbname=$db_file","","");
|
my $dbh = DBI->connect( "dbi:SQLite:dbname=$db_file", "", "" );
|
||||||
|
|
||||||
return $dbh;
|
return $dbh;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub mdo {
|
sub mdo {
|
||||||
my ($self, $query, $type) = @_;
|
my ( $self, $query, $type ) = @_;
|
||||||
my $dbh = $self->{_dbh};
|
my $dbh = $self->{_dbh};
|
||||||
}
|
}
|
||||||
|
|
||||||
sub create_base {
|
sub create_base {
|
||||||
my ($self) = @_;
|
my ($self) = @_;
|
||||||
my $home = $self->{_home};
|
my $home = $self->{_home};
|
||||||
my $pm_dir = $home."/.PM/";
|
my $pm_dir = $home . "/.PM/";
|
||||||
|
|
||||||
# Check dir
|
# Check dir
|
||||||
if (!(-d $pm_dir)) {
|
if ( !( -d $pm_dir ) ) {
|
||||||
|
|
||||||
# Create dirrectory
|
# Create dirrectory
|
||||||
@mkdir_cmd = ("mkdir", "$pm_dir");
|
my @mkdir_cmd = ( "mkdir", "$pm_dir" );
|
||||||
system(@mkdir_cmd) == 0 or die "Cannot create dir $pm_dir: $!\n";
|
system(@mkdir_cmd) == 0 or die "Cannot create dir $pm_dir: $!\n";
|
||||||
|
|
||||||
# Create DB file
|
# Create DB file
|
||||||
@createdb_cmd = ("touch", "$pm_dir/db.sqlite");
|
my @createdb_cmd = ( "touch", "$pm_dir/db.sqlite" );
|
||||||
system(@createdb_cmd) == 0 or die "Cannot create database file: $!\n";
|
system(@createdb_cmd) == 0 or die "Cannot create database file: $!\n";
|
||||||
|
|
||||||
# Create table. TODO: write this
|
# Create table. TODO: write this
|
||||||
my $dbh = DBI->connect("dbi:SQLite:dbname=$pm_dir/db.sqlite","","");
|
my $dbh
|
||||||
|
= DBI->connect( "dbi:SQLite:dbname=$pm_dir/db.sqlite", "", "" );
|
||||||
print "Create database schema\n";
|
print "Create database schema\n";
|
||||||
my $q_table = "create table passwords(name VARCHAR(32), resource TEXT, password TEXT)";
|
my $q_table
|
||||||
|
= "create table passwords(name VARCHAR(32), resource TEXT, password TEXT)";
|
||||||
$dbh->do($q_table);
|
$dbh->do($q_table);
|
||||||
|
|
||||||
# Encrypt db
|
# Encrypt db
|
||||||
|
@ -30,7 +30,7 @@ sub new {
|
|||||||
# Check configuration. If it doesn't exist create it.
|
# Check configuration. If it doesn't exist create it.
|
||||||
sub check_config {
|
sub check_config {
|
||||||
my ($self) = @_;
|
my ($self) = @_;
|
||||||
if (-e $ENV->{HOME}."/.PM/db.sqlite") {
|
if ( -e $ENV->{HOME} . "/.PM/db.sqlite" ) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
10
pm.pl
10
pm.pl
@ -44,11 +44,12 @@ EOF
|
|||||||
sub init() {
|
sub init() {
|
||||||
my $opt_string = 'swn:l:p:rhv';
|
my $opt_string = 'swn:l:p:rhv';
|
||||||
getopts("$opt_string") or usage();
|
getopts("$opt_string") or usage();
|
||||||
our ($opt_s, $opt_w, $opt_n, $opt_r,
|
our ( $opt_s, $opt_w, $opt_n, $opt_r, $opt_l, $opt_p, $opt_h, $opt_v );
|
||||||
$opt_l, $opt_p, $opt_h, $opt_v);
|
|
||||||
|
|
||||||
print "Simple password manager writed in Perl.\nVersion: ".
|
print "Simple password manager writed in Perl.\nVersion: "
|
||||||
$VERSION."\n" and exit 0 if $opt_v;
|
. $VERSION
|
||||||
|
. "\n" and exit 0
|
||||||
|
if $opt_v;
|
||||||
usage if $opt_h;
|
usage if $opt_h;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,5 +57,6 @@ sub init() {
|
|||||||
init();
|
init();
|
||||||
|
|
||||||
my $pass = Password->new();
|
my $pass = Password->new();
|
||||||
|
|
||||||
# Don't use it's before GPG and Database
|
# Don't use it's before GPG and Database
|
||||||
# $pass->check_config() == 0 or die "$!\n";
|
# $pass->check_config() == 0 or die "$!\n";
|
Loading…
Reference in New Issue
Block a user