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

@ -6,11 +6,14 @@ use GPG;
sub new {
my $class = shift;
# Get home dir
my $home = $ENV->{HOME};
# Get home dir
my $home = $ENV->{HOME};
my $self = {
_home => $home,
my $gpg = GPG->new();
my $self = {
_home => $home,
_gpg => $gpg,
};
bless $self, $class;
@ -18,50 +21,53 @@ sub new {
}
sub connect {
my ($self) = @_;
my $home = $self->{_home};
my $db_file = $home . "/.PM/db.sqlite";
my $dbh = DBI->connect("dbi:SQLite:dbname=$db_file","","");
my ($self) = @_;
my $home = $self->{_home};
my $db_file = $home . "/.PM/db.sqlite";
my $dbh = DBI->connect( "dbi:SQLite:dbname=$db_file", "", "" );
return $dbh;
}
sub mdo {
my ($self, $query, $type) = @_;
my $dbh = $self->{_dbh};
my ( $self, $query, $type ) = @_;
my $dbh = $self->{_dbh};
}
sub create_base {
my ($self) = @_;
my $home = $self->{_home};
my $pm_dir = $home."/.PM/";
# Check dir
if (!(-d $pm_dir)) {
# Create dirrectory
@mkdir_cmd = ("mkdir", "$pm_dir");
system(@mkdir_cmd) == 0 or die "Cannot create dir $pm_dir: $!\n";
my ($self) = @_;
my $home = $self->{_home};
my $pm_dir = $home . "/.PM/";
# Create DB file
@createdb_cmd = ("touch", "$pm_dir/db.sqlite");
system(@createdb_cmd) == 0 or die "Cannot create database file: $!\n";
# Check dir
if ( !( -d $pm_dir ) ) {
# Create table. TODO: write this
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)";
$dbh->do($q_table);
# Create dirrectory
my @mkdir_cmd = ( "mkdir", "$pm_dir" );
system(@mkdir_cmd) == 0 or die "Cannot create dir $pm_dir: $!\n";
# Encrypt db
# TODO: write this
# Create DB file
my @createdb_cmd = ( "touch", "$pm_dir/db.sqlite" );
system(@createdb_cmd) == 0 or die "Cannot create database file: $!\n";
return 0;
}
else {
print "Dirrectory is exist!\n";
return 0;
}
# Create table. TODO: write this
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)";
$dbh->do($q_table);
# Encrypt db
# TODO: write this
return 0;
}
else {
print "Dirrectory is exist!\n";
return 0;
}
}
1;
1;

View File

@ -10,34 +10,34 @@ use PasswordSave;
use PasswordShow;
sub new {
my $class = shift;
my $class = shift;
my $db = Database->new();
my $db = Database->new();
my $p_save = PasswordSave->new();
my $p_show = PasswordShow->new();
my $p_save = PasswordSave->new();
my $p_show = PasswordShow->new();
my $self = {
_db => $db,
_p_save => $p_save,
_p_show => $p_show,
my $self = {
_db => $db,
_p_save => $p_save,
_p_show => $p_show,
};
bless $self, $class;
return $self;
}
# Check configuration. If it doesn't exist create it.
sub check_config {
my ($self) = @_;
if (-e $ENV->{HOME}."/.PM/db.sqlite") {
return 0;
}
else {
my $db = $self->{_db};
$db->create_base();
}
return 0;
my ($self) = @_;
if ( -e $ENV->{HOME} . "/.PM/db.sqlite" ) {
return 0;
}
else {
my $db = $self->{_db};
$db->create_base();
}
return 0;
}
1;
1;

24
pm.pl
View File

@ -9,7 +9,7 @@ our $VERSION = '0.0.0b';
use Data::Dumper;
sub usage() {
print STDERR << "EOF";
print STDERR << "EOF";
Simple password manager writed in Perl.
Usage:
@ -38,23 +38,25 @@ Examples:
\tPassword copied to clipboard. Trying to open uri.
EOF
exit 1;
exit 1;
}
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);
print "Simple password manager writed in Perl.\nVersion: ".
$VERSION."\n" and exit 0 if $opt_v;
usage if $opt_h;
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 );
print "Simple password manager writed in Perl.\nVersion: "
. $VERSION
. "\n" and exit 0
if $opt_v;
usage if $opt_h;
}
# Parse cmd line
init();
my $pass = Password->new();
# Don't use it's before GPG and Database
# $pass->check_config() == 0 or die "$!\n";
# $pass->check_config() == 0 or die "$!\n";