From dcb70474e398a0950933a4698244f92d33523708 Mon Sep 17 00:00:00 2001 From: "Difrex(Denis Zheleztsov)" Date: Mon, 28 Apr 2014 12:17:17 +0400 Subject: [PATCH] Start working on GPG module --- Database.pm | 80 ++++++++++++++++++++++++++++------------------------- Password.pm | 38 ++++++++++++------------- pm.pl | 24 ++++++++-------- 3 files changed, 75 insertions(+), 67 deletions(-) diff --git a/Database.pm b/Database.pm index 8af5380..88c3123 100644 --- a/Database.pm +++ b/Database.pm @@ -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; \ No newline at end of file +1; diff --git a/Password.pm b/Password.pm index 01f561f..3a550d1 100644 --- a/Password.pm +++ b/Password.pm @@ -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; \ No newline at end of file +1; diff --git a/pm.pl b/pm.pl index 38a634c..b2f564c 100755 --- a/pm.pl +++ b/pm.pl @@ -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"; \ No newline at end of file +# $pass->check_config() == 0 or die "$!\n";