2014-01-20 01:08:03 +01:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
|
|
|
|
use v5.14;
|
|
|
|
use DBI;
|
|
|
|
|
|
|
|
use lib '../';
|
|
|
|
use app::zone::interface;
|
|
|
|
use app::zone::edit;
|
|
|
|
use app::zone::rndc_interface;
|
|
|
|
use app::bdd::management;
|
|
|
|
use app::bdd::admin;
|
|
|
|
use app::bdd::lambda;
|
|
|
|
|
|
|
|
package app;
|
|
|
|
use Moose;
|
|
|
|
|
|
|
|
has dbh => ( is => 'rw', builder => '_void');
|
|
|
|
has dnsi => ( is => 'rw', builder => '_void');
|
|
|
|
has um => ( is => 'rw', builder => '_void');
|
|
|
|
has [ qw/zdir dbname dbhost dbport dbuser dbpass sgbd dnsapp/ ] => qw/is ro required 1/;
|
|
|
|
sub _void { my $x = ''; \$x; }
|
|
|
|
|
|
|
|
### users
|
|
|
|
|
|
|
|
sub init {
|
|
|
|
my ($self) = @_;
|
|
|
|
|
|
|
|
my $success;
|
|
|
|
|
|
|
|
my $dsn = 'DBI:' . $self->sgbd
|
|
|
|
. ':database=' . $self->dbname
|
|
|
|
. ';host=' . $self->dbhost
|
|
|
|
. ';port=' . $self->dbport;
|
|
|
|
|
|
|
|
${$self->dbh} = DBI->connect($dsn
|
|
|
|
, $self->dbuser
|
|
|
|
, $self->dbpass)
|
|
|
|
|| die "Could not connect to database: $DBI::errstr";
|
|
|
|
|
|
|
|
($success, ${$self->dnsi}) = app::zone::interface ->new()
|
|
|
|
->get_interface($self->dnsapp, $self->zdir);
|
|
|
|
|
|
|
|
die("zone interface") unless $success;
|
|
|
|
|
|
|
|
${$self->um} = app::bdd::management->new(dbh => ${$self->dbh});
|
|
|
|
}
|
|
|
|
|
|
|
|
sub auth {
|
|
|
|
my ($self, $login, $passwd) = @_;
|
2014-01-22 17:01:34 +01:00
|
|
|
${$self->um}->auth($login, $passwd);
|
2014-01-20 01:08:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
sub register_user {
|
|
|
|
my ($self, $login, $passwd) = @_;
|
2014-01-22 17:01:34 +01:00
|
|
|
${$self->um}->register_user($login, $passwd);
|
2014-01-20 01:08:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
sub set_admin {
|
2014-01-23 21:30:52 +01:00
|
|
|
my ($self, $login, $val) = @_;
|
|
|
|
${$self->um}->set_admin($login, $val);
|
2014-01-20 01:08:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
sub update_passwd {
|
|
|
|
my ($self, $login, $new) = @_;
|
2014-01-22 17:01:34 +01:00
|
|
|
my ($success, $user, $isadmin) = ${$self->um}->get_user($login);
|
|
|
|
$user->passwd($new);
|
2014-01-20 01:08:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
sub delete_user {
|
|
|
|
my ($self, $login) = @_;
|
2014-01-22 17:01:34 +01:00
|
|
|
my ($success, @domains) = $self->get_domains($login);
|
|
|
|
|
|
|
|
if($success) {
|
|
|
|
$self->delete_domain($login, $_) foreach(@domains);
|
|
|
|
${$self->um}->delete_user($login);
|
|
|
|
}
|
2014-01-20 01:08:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
### domains
|
|
|
|
|
|
|
|
# return yes or no
|
|
|
|
sub add_domain {
|
|
|
|
my ($self, $login, $domain) = @_;
|
2014-01-22 17:01:34 +01:00
|
|
|
my ($success, $user, $isadmin) = ${$self->um}->get_user($login);
|
|
|
|
|
|
|
|
unless($success) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-01-24 22:37:02 +01:00
|
|
|
unless ($user->add_domain($domain)) {
|
|
|
|
return 0;
|
|
|
|
}
|
2014-01-20 01:08:03 +01:00
|
|
|
|
|
|
|
my $ze = app::zone::edit->new(zname => $domain, zdir => $self->zdir);
|
|
|
|
$ze->addzone();
|
|
|
|
}
|
|
|
|
|
|
|
|
sub delete_domain {
|
|
|
|
my ($self, $login, $domain) = @_;
|
2014-01-22 17:01:34 +01:00
|
|
|
my ($success, $user, $isadmin) = ${$self->um}->get_user($login);
|
2014-01-20 01:08:03 +01:00
|
|
|
$user->delete_domain($domain);
|
|
|
|
my $ze = app::zone::edit->new(zname => $domain, zdir => $self->zdir);
|
|
|
|
$ze->del();
|
|
|
|
}
|
|
|
|
|
2014-01-21 01:33:17 +01:00
|
|
|
sub update_domain_raw {
|
|
|
|
my ($self, $login, $zone, $domain) = @_;
|
|
|
|
my $ze = app::zone::edit->new(zname => $domain, zdir => $self->zdir);
|
|
|
|
$ze->update_raw($zone);
|
|
|
|
}
|
|
|
|
|
2014-01-20 01:08:03 +01:00
|
|
|
sub update_domain {
|
|
|
|
my ($self, $login, $zone, $domain) = @_;
|
|
|
|
my $ze = app::zone::edit->new(zname => $domain, zdir => $self->zdir);
|
|
|
|
$ze->update($zone);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub get_domain {
|
|
|
|
my ($self, $login, $domain) = @_;
|
|
|
|
my $ze = app::zone::edit->new(zname => $domain, zdir => $self->zdir);
|
|
|
|
$ze->get();
|
|
|
|
}
|
|
|
|
|
|
|
|
sub get_domains {
|
|
|
|
my ($self, $login) = @_;
|
2014-01-22 17:01:34 +01:00
|
|
|
${$self->um}->get_domains($login);
|
2014-01-20 01:08:03 +01:00
|
|
|
}
|
|
|
|
|
2014-01-22 17:01:34 +01:00
|
|
|
sub get_all_domains {
|
|
|
|
my ($self) = @_;
|
|
|
|
# % domain login
|
|
|
|
${$self->um}->get_all_domains;
|
2014-01-20 01:08:03 +01:00
|
|
|
}
|
|
|
|
|
2014-01-23 21:30:52 +01:00
|
|
|
sub get_all_users {
|
|
|
|
my ($self) = @_;
|
|
|
|
# % login admin
|
|
|
|
${$self->um}->get_all_users;
|
|
|
|
}
|
|
|
|
|
2014-01-20 01:08:03 +01:00
|
|
|
sub new_tmp {
|
|
|
|
my ($self, $login, $domain) = @_;
|
|
|
|
my $ze = app::zone::edit->new(zname => $domain, zdir => $self->zdir);
|
|
|
|
$ze->new_tmp();
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|