check_config function
This commit is contained in:
parent
dc76c9e6f8
commit
2423a6d942
13
Database.pm
13
Database.pm
@ -1,15 +1,16 @@
|
|||||||
package Database;
|
package Database;
|
||||||
|
|
||||||
use DBI;
|
use DBI;
|
||||||
|
use GPG;
|
||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
my $class = shift;
|
my $class = shift;
|
||||||
|
|
||||||
# Get home dir
|
# Get home dir
|
||||||
my $home = $ENV{HOME};
|
my $home = $ENV->{HOME};
|
||||||
|
|
||||||
my $self = {
|
my $self = {
|
||||||
_home => $home;
|
_home => $home,
|
||||||
};
|
};
|
||||||
|
|
||||||
bless $self, $class;
|
bless $self, $class;
|
||||||
@ -27,7 +28,7 @@ sub connect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub mdo {
|
sub mdo {
|
||||||
my ($self) = @_;
|
my ($self, $query, $type) = @_;
|
||||||
my $dbh = $self->{_dbh};
|
my $dbh = $self->{_dbh};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,7 +38,7 @@ sub create_base {
|
|||||||
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");
|
@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";
|
||||||
@ -50,6 +51,10 @@ sub create_base {
|
|||||||
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);
|
||||||
|
|
||||||
|
# Encrypt db
|
||||||
|
# TODO: write this
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
25
Password.pm
25
Password.pm
@ -6,15 +6,38 @@ use utf8;
|
|||||||
|
|
||||||
use Database;
|
use Database;
|
||||||
|
|
||||||
|
use PasswordSave;
|
||||||
|
use PasswordShow;
|
||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
my $class = shift;
|
my $class = shift;
|
||||||
|
|
||||||
|
my $db = Database->new();
|
||||||
|
|
||||||
|
my $p_save = PasswordSave->new();
|
||||||
|
my $p_show = PasswordShow->new();
|
||||||
|
|
||||||
my $self = {
|
my $self = {
|
||||||
_home => $home,
|
_db => $db,
|
||||||
|
_p_save => $p_save,
|
||||||
|
_p_show => $p_show,
|
||||||
};
|
};
|
||||||
|
|
||||||
bless $self, $class;
|
bless $self, $class;
|
||||||
return $self;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
6
pm.pl
6
pm.pl
@ -3,7 +3,7 @@
|
|||||||
use Password;
|
use Password;
|
||||||
use Getopt::Std;
|
use Getopt::Std;
|
||||||
|
|
||||||
our $VERSION = '0.0.0a';
|
our $VERSION = '0.0.0b';
|
||||||
|
|
||||||
# Debug
|
# Debug
|
||||||
use Data::Dumper;
|
use Data::Dumper;
|
||||||
@ -54,3 +54,7 @@ sub init() {
|
|||||||
|
|
||||||
# Parse cmd line
|
# Parse cmd line
|
||||||
init();
|
init();
|
||||||
|
|
||||||
|
my $pass = Password->new();
|
||||||
|
# Don't use it's before GPG and Database
|
||||||
|
# $pass->check_config() == 0 or die "$!\n";
|
Loading…
Reference in New Issue
Block a user