Start working on GPG module

This commit is contained in:
Difrex(Denis Zheleztsov) 2014-04-28 12:17:17 +04:00
parent 2423a6d942
commit dcb70474e3
3 changed files with 75 additions and 67 deletions

View File

@ -9,8 +9,11 @@ sub new {
# Get home dir
my $home = $ENV->{HOME};
my $gpg = GPG->new();
my $self = {
_home => $home,
_gpg => $gpg,
};
bless $self, $class;
@ -22,35 +25,38 @@ sub connect {
my $home = $self->{_home};
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;
}
sub mdo {
my ($self, $query, $type) = @_;
my ( $self, $query, $type ) = @_;
my $dbh = $self->{_dbh};
}
sub create_base {
my ($self) = @_;
my $home = $self->{_home};
my $pm_dir = $home."/.PM/";
my $pm_dir = $home . "/.PM/";
# Check dir
if (!(-d $pm_dir)) {
if ( !( -d $pm_dir ) ) {
# 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";
# 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";
# 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";
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);
# Encrypt db

View File

@ -30,7 +30,7 @@ sub new {
# 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 {

10
pm.pl
View File

@ -44,11 +44,12 @@ EOF
sub init() {
my $opt_string = 'swn:l:p:rhv';
getopts("$opt_string") or usage();
our ($opt_s, $opt_w, $opt_n, $opt_r,
$opt_l, $opt_p, $opt_h, $opt_v);
our ( $opt_s, $opt_w, $opt_n, $opt_r, $opt_l, $opt_p, $opt_h, $opt_v );
print "Simple password manager writed in Perl.\nVersion: ".
$VERSION."\n" and exit 0 if $opt_v;
print "Simple password manager writed in Perl.\nVersion: "
. $VERSION
. "\n" and exit 0
if $opt_v;
usage if $opt_h;
}
@ -56,5 +57,6 @@ sub init() {
init();
my $pass = Password->new();
# Don't use it's before GPG and Database
# $pass->check_config() == 0 or die "$!\n";